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.spy; 22 import static org.mockito.Mockito.verify; 23 24 import android.app.settings.SettingsEnums; 25 import android.os.Bundle; 26 27 import com.android.wifitrackerlib.NetworkDetailsTracker; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 import org.robolectric.RobolectricTestRunner; 35 import org.robolectric.shadows.androidx.fragment.FragmentController; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class ConfigureWifiEntryFragmentTest { 39 40 private static final String KEY_SSID = "key_ssid"; 41 private static final String KEY_SECURITY = "key_security"; 42 43 private ConfigureWifiEntryFragment mConfigureWifiEntryFragment; 44 45 @Mock 46 private NetworkDetailsTracker mNetworkDetailsTracker; 47 48 @Before setUp()49 public void setUp() { 50 MockitoAnnotations.initMocks(this); 51 Bundle bundle = new Bundle(); 52 53 bundle.putString(KEY_SSID, "Test AP"); 54 bundle.putInt(KEY_SECURITY, 1 /* WEP */); 55 mConfigureWifiEntryFragment = spy(new ConfigureWifiEntryFragment()); 56 mConfigureWifiEntryFragment.setArguments(bundle); 57 mConfigureWifiEntryFragment.mNetworkDetailsTracker = mNetworkDetailsTracker; 58 59 FragmentController.setupFragment(mConfigureWifiEntryFragment); 60 } 61 62 @Test getMetricsCategory_shouldReturnConfigureNetwork()63 public void getMetricsCategory_shouldReturnConfigureNetwork() { 64 assertThat(mConfigureWifiEntryFragment.getMetricsCategory()).isEqualTo( 65 SettingsEnums.SETTINGS_WIFI_CONFIGURE_NETWORK); 66 } 67 68 @Test getMode_shouldBeModeConnected()69 public void getMode_shouldBeModeConnected() { 70 assertThat(mConfigureWifiEntryFragment.getMode()).isEqualTo( 71 WifiConfigUiBase2.MODE_CONNECT); 72 } 73 74 @Test launchFragment_shouldShowSubmitButton()75 public void launchFragment_shouldShowSubmitButton() { 76 assertThat(mConfigureWifiEntryFragment.getSubmitButton()).isNotNull(); 77 } 78 79 @Test launchFragment_shouldShowCancelButton()80 public void launchFragment_shouldShowCancelButton() { 81 assertThat(mConfigureWifiEntryFragment.getCancelButton()).isNotNull(); 82 } 83 84 @Test onClickSubmitButton_shouldHandleSubmitAction()85 public void onClickSubmitButton_shouldHandleSubmitAction() { 86 mConfigureWifiEntryFragment.getSubmitButton().performClick(); 87 88 verify(mConfigureWifiEntryFragment).handleSubmitAction(); 89 } 90 91 @Test dispatchSubmit_shouldHandleSubmitAction()92 public void dispatchSubmit_shouldHandleSubmitAction() { 93 mConfigureWifiEntryFragment.dispatchSubmit(); 94 95 verify(mConfigureWifiEntryFragment).handleSubmitAction(); 96 } 97 98 @Test onClickCancelButton_shouldHandleCancelAction()99 public void onClickCancelButton_shouldHandleCancelAction() { 100 mConfigureWifiEntryFragment.getCancelButton().performClick(); 101 102 verify(mConfigureWifiEntryFragment).handleCancelAction(); 103 } 104 } 105