diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-06 05:10:17 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-06 05:10:17 +0000 |
commit | 2434e1f7ee25ee759b46037e2768e930c1c37313 (patch) | |
tree | c4399ae49ff3b1b6988f9a6048e4b84a65a5c118 /libs | |
parent | 7d2ab812671a10f754c6cf6f7feb86aa15cc6477 (diff) | |
parent | 297dc4e32df726542e895abb3869a8c47b62c143 (diff) |
Merge "[WifiTrackerLib] Fix WifiPickerTrackerTest to mock correct config API" into rvc-dev am: a86c9944ed am: 297dc4e32d
Change-Id: I32393e00c667fc0cfe5f70eeba74b260dc7bbabf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java index bb69003c7..f59e34499 100644 --- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java @@ -49,11 +49,13 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.time.Clock; import java.util.ArrayList; import java.util.Arrays; +import java.util.BitSet; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -392,7 +394,7 @@ public class WifiPickerTrackerTest { final WifiPickerTracker wifiPickerTracker = createTestWifiPickerTracker(); final WifiConfiguration config = new WifiConfiguration(); config.SSID = "\"ssid\""; - when(mMockWifiManager.getConfiguredNetworks()) + when(mMockWifiManager.getPrivilegedConfiguredNetworks()) .thenReturn(Collections.singletonList(config)); wifiPickerTracker.onStart(); verify(mMockContext).registerReceiver(mBroadcastReceiverCaptor.capture(), @@ -426,7 +428,7 @@ public class WifiPickerTrackerTest { final WifiConfiguration config = new WifiConfiguration(); config.SSID = "\"ssid\""; config.networkId = 1; - when(mMockWifiManager.getConfiguredNetworks()) + when(mMockWifiManager.getPrivilegedConfiguredNetworks()) .thenReturn(Collections.singletonList(config)); when(mMockWifiInfo.getNetworkId()).thenReturn(1); when(mMockWifiInfo.getRssi()).thenReturn(-50); @@ -448,7 +450,7 @@ public class WifiPickerTrackerTest { final WifiConfiguration config = new WifiConfiguration(); config.SSID = "\"ssid\""; config.networkId = 1; - when(mMockWifiManager.getConfiguredNetworks()) + when(mMockWifiManager.getPrivilegedConfiguredNetworks()) .thenReturn(Collections.singletonList(config)); when(mMockWifiManager.getScanResults()).thenReturn(Arrays.asList( buildScanResult("ssid", "bssid", START_MILLIS))); @@ -479,7 +481,7 @@ public class WifiPickerTrackerTest { final WifiConfiguration config = new WifiConfiguration(); config.SSID = "\"ssid\""; config.networkId = 1; - when(mMockWifiManager.getConfiguredNetworks()) + when(mMockWifiManager.getPrivilegedConfiguredNetworks()) .thenReturn(Collections.singletonList(config)); when(mMockWifiManager.getScanResults()).thenReturn(Arrays.asList( buildScanResult("ssid", "bssid", START_MILLIS))); @@ -578,7 +580,8 @@ public class WifiPickerTrackerTest { public void testGetConnectedEntry_alreadyConnectedToPasspoint_returnsPasspointEntry() { final String fqdn = "fqdn"; final String friendlyName = "friendlyName"; - final WifiPickerTracker wifiPickerTracker = createTestWifiPickerTracker(); + final int networkId = 1; + // Create a passpoint configuration to match with the current network final PasspointConfiguration passpointConfig = new PasspointConfiguration(); final HomeSp homeSp = new HomeSp(); homeSp.setFqdn(fqdn); @@ -587,10 +590,23 @@ public class WifiPickerTrackerTest { passpointConfig.setCredential(new Credential()); when(mMockWifiManager.getPasspointConfigurations()) .thenReturn(Collections.singletonList(passpointConfig)); + // Create a wifi config to match the WifiInfo netId and unique id of the passpoint config + final WifiConfiguration config = Mockito.mock(WifiConfiguration.class); + config.SSID = "\"ssid\""; + config.networkId = networkId; + config.allowedKeyManagement = new BitSet(); + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192); + + when(config.isPasspoint()).thenReturn(true); + when(config.getKey()).thenReturn(passpointConfig.getUniqueId()); + when(mMockWifiManager.getPrivilegedConfiguredNetworks()) + .thenReturn(Collections.singletonList(config)); when(mMockWifiInfo.isPasspointAp()).thenReturn(true); + when(mMockWifiInfo.getNetworkId()).thenReturn(networkId); when(mMockWifiInfo.getPasspointFqdn()).thenReturn(fqdn); when(mMockWifiInfo.getRssi()).thenReturn(-50); when(mMockNetworkInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.CONNECTED); + final WifiPickerTracker wifiPickerTracker = createTestWifiPickerTracker(); wifiPickerTracker.onStart(); verify(mMockContext).registerReceiver(mBroadcastReceiverCaptor.capture(), |