Migrate robolectric tests to junit tests
This change do the 2 things: 1. Add new junit tests files which replace robolectric RobolectricTestRunner & RuntimeEnvironment with AndroidX objects without problem. 2. Remove the robolectric test files which have it's new junit files. This change migrate 103 files, there are still 1209 files to go. Bug: 174728471 Test: atest make RunSettingsRoboTests Change-Id: I15ed3f4745b85862f720aabbf710ce1475aced93
This commit is contained in:
74
tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
Normal file
74
tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testSSID() {
|
||||
assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
|
||||
assertThat(WifiUtils.isSSIDTooLong("☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎")).isTrue();
|
||||
|
||||
assertThat(WifiUtils.isSSIDTooShort("123")).isFalse();
|
||||
assertThat(WifiUtils.isSSIDTooShort("")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPassword() {
|
||||
final String longPassword = "123456789012345678901234567890"
|
||||
+ "1234567890123456789012345678901234567890";
|
||||
assertThat(WifiUtils.isHotspotWpa2PasswordValid("123")).isFalse();
|
||||
assertThat(WifiUtils.isHotspotWpa2PasswordValid("12345678")).isTrue();
|
||||
assertThat(WifiUtils.isHotspotWpa2PasswordValid("1234567890")).isTrue();
|
||||
assertThat(WifiUtils.isHotspotWpa2PasswordValid(longPassword)).isFalse();
|
||||
assertThat(WifiUtils.isHotspotWpa2PasswordValid("")).isFalse();
|
||||
assertThat(WifiUtils.isHotspotWpa2PasswordValid("€¥£")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiConfigByWifiEntry_shouldReturnCorrectConfig() {
|
||||
final String testSSID = "WifiUtilsTest";
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(wifiEntry.getSsid()).thenReturn(testSSID);
|
||||
|
||||
final WifiConfiguration config = WifiUtils.getWifiConfig(wifiEntry, null /* scanResult */);
|
||||
|
||||
assertThat(config).isNotNull();
|
||||
assertThat(config.SSID).isEqualTo("\"" + testSSID + "\"");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getWifiConfigWithNullInput_ThrowIllegalArgumentException() {
|
||||
WifiConfiguration config = WifiUtils.getWifiConfig(null /* wifiEntry */,
|
||||
null /* scanResult */);
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiSubscriptionDetailPreferenceController2Test {
|
||||
|
||||
@Mock
|
||||
private WifiEntry mMockWifiEntry;
|
||||
|
||||
private WifiSubscriptionDetailPreferenceController2 mPreferenceController;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
mMockWifiEntry = mock(WifiEntry.class);
|
||||
WifiSubscriptionDetailPreferenceController2 preferenceController =
|
||||
new WifiSubscriptionDetailPreferenceController2(mContext);
|
||||
preferenceController.setWifiEntry(mMockWifiEntry);
|
||||
mPreferenceController = spy(preferenceController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_canSetPrivacy_shouldBeSelectable() {
|
||||
when(mMockWifiEntry.canManageSubscription()).thenReturn(true);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_canNotSetPrivacy_shouldNotSelectable() {
|
||||
when(mMockWifiEntry.canManageSubscription()).thenReturn(false);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiNetworkConfigTest {
|
||||
private WifiNetworkConfig mWifiConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "Pixel:_ABCD;");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WPA");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "\\012345678,");
|
||||
mWifiConfig = WifiNetworkConfig.getValidConfigOrNull(intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitConfig_IntentReceived_QRCodeValue() {
|
||||
String qrcode = mWifiConfig.getQrCode();
|
||||
assertThat(qrcode).isEqualTo("WIFI:S:Pixel\\:_ABCD\\;;T:WPA;P:\\\\012345678\\,;H:false;;");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user