• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.settings.wifi;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.spy;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
25 
26 import android.app.settings.SettingsEnums;
27 import android.content.Context;
28 import android.net.wifi.WifiManager;
29 import android.os.Bundle;
30 
31 import androidx.test.core.app.ApplicationProvider;
32 
33 import com.android.wifitrackerlib.NetworkDetailsTracker;
34 
35 import org.junit.Before;
36 import org.junit.Ignore;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 import org.robolectric.RobolectricTestRunner;
42 import org.robolectric.shadows.androidx.fragment.FragmentController;
43 
44 @RunWith(RobolectricTestRunner.class)
45 public class ConfigureWifiEntryFragmentTest {
46 
47     private static final String KEY_SSID = "key_ssid";
48     private static final String KEY_SECURITY = "key_security";
49 
50     private ConfigureWifiEntryFragment mConfigureWifiEntryFragment;
51 
52     @Mock
53     private NetworkDetailsTracker mNetworkDetailsTracker;
54 
55     @Before
setUp()56     public void setUp() {
57         MockitoAnnotations.initMocks(this);
58         Context context = spy(ApplicationProvider.getApplicationContext());
59         when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mock(WifiManager.class));
60 
61         Bundle bundle = new Bundle();
62         bundle.putString(KEY_SSID, "Test AP");
63         bundle.putInt(KEY_SECURITY, 1 /* WEP */);
64         mConfigureWifiEntryFragment = spy(new ConfigureWifiEntryFragment());
65         mConfigureWifiEntryFragment.setArguments(bundle);
66         mConfigureWifiEntryFragment.mNetworkDetailsTracker = mNetworkDetailsTracker;
67         when(mConfigureWifiEntryFragment.getContext()).thenReturn(context);
68 
69         FragmentController.setupFragment(mConfigureWifiEntryFragment);
70     }
71 
72     @Ignore
73     @Test
getMetricsCategory_shouldReturnConfigureNetwork()74     public void getMetricsCategory_shouldReturnConfigureNetwork() {
75         assertThat(mConfigureWifiEntryFragment.getMetricsCategory()).isEqualTo(
76                 SettingsEnums.SETTINGS_WIFI_CONFIGURE_NETWORK);
77     }
78 
79     @Ignore
80     @Test
getMode_shouldBeModeConnected()81     public void getMode_shouldBeModeConnected() {
82         assertThat(mConfigureWifiEntryFragment.getMode()).isEqualTo(
83                 WifiConfigUiBase2.MODE_CONNECT);
84     }
85 
86     @Ignore
87     @Test
launchFragment_shouldShowSubmitButton()88     public void launchFragment_shouldShowSubmitButton() {
89         assertThat(mConfigureWifiEntryFragment.getSubmitButton()).isNotNull();
90     }
91 
92     @Ignore
93     @Test
launchFragment_shouldShowCancelButton()94     public void launchFragment_shouldShowCancelButton() {
95         assertThat(mConfigureWifiEntryFragment.getCancelButton()).isNotNull();
96     }
97 
98     @Ignore
99     @Test
onClickSubmitButton_shouldHandleSubmitAction()100     public void onClickSubmitButton_shouldHandleSubmitAction() {
101         mConfigureWifiEntryFragment.getSubmitButton().performClick();
102 
103         verify(mConfigureWifiEntryFragment).handleSubmitAction();
104     }
105 
106     @Ignore
107     @Test
dispatchSubmit_shouldHandleSubmitAction()108     public void dispatchSubmit_shouldHandleSubmitAction() {
109         mConfigureWifiEntryFragment.dispatchSubmit();
110 
111         verify(mConfigureWifiEntryFragment).handleSubmitAction();
112     }
113 
114     @Ignore
115     @Test
onClickCancelButton_shouldHandleCancelAction()116     public void onClickCancelButton_shouldHandleCancelAction() {
117         mConfigureWifiEntryFragment.getCancelButton().performClick();
118 
119         verify(mConfigureWifiEntryFragment).handleCancelAction();
120     }
121 }
122