Home | History | Annotate | Download | only in setup
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.tv.settings.connectivity.setup;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 import static org.junit.Assert.assertTrue;
     21 
     22 import android.arch.lifecycle.ViewModelProviders;
     23 import android.net.wifi.WifiConfiguration;
     24 
     25 import com.android.tv.settings.TvSettingsRobolectricTestRunner;
     26 import com.android.tv.settings.testutils.TvShadowWifiManager;
     27 
     28 import org.junit.Before;
     29 import org.junit.Test;
     30 import org.junit.runner.RunWith;
     31 import org.mockito.MockitoAnnotations;
     32 import org.robolectric.Robolectric;
     33 import org.robolectric.annotation.Config;
     34 
     35 @RunWith(TvSettingsRobolectricTestRunner.class)
     36 @Config(shadows = TvShadowWifiManager.class)
     37 public class ConnectTimeoutStateTest {
     38     private WifiSetupActivity mActivity;
     39     private ConnectTimeOutState mState;
     40 
     41     @Before
     42     public void setUp() {
     43         MockitoAnnotations.initMocks(this);
     44         mActivity = Robolectric.buildActivity(WifiSetupActivity.class).create().get();
     45         mState = new ConnectTimeOutState(mActivity);
     46     }
     47 
     48     @Test
     49     public void testProcessForward() {
     50         String ssid = "aewrf";
     51         AdvancedOptionsFlowInfo advInfo =
     52                 ViewModelProviders.of(mActivity).get(AdvancedOptionsFlowInfo.class);
     53         UserChoiceInfo userInfo = ViewModelProviders.of(mActivity).get(UserChoiceInfo.class);
     54         WifiConfiguration wifiConfiguration = new WifiConfiguration();
     55         wifiConfiguration.SSID = ssid;
     56         userInfo.setWifiConfiguration(wifiConfiguration);
     57         advInfo.setCanStart(false);
     58         advInfo.setPrintableSsid(null);
     59         mState.processForward();
     60         assertTrue(advInfo.canStart());
     61         assertEquals(ssid, advInfo.getPrintableSsid());
     62     }
     63 }
     64