diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-06 04:42:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-06 04:42:02 +0000 |
commit | a86c9944ed5ee4a4c3637cf7aab229d6230aac77 (patch) | |
tree | 21ffa104c699f834cf86b9683209459d0e314448 /libs | |
parent | f0932e0e8d5c81dff2baabd1fe09de154f44689c (diff) | |
parent | 279516b46c950d9fbc3967bda2952e52d6748137 (diff) |
Merge "[WifiTrackerLib] Fix WifiPickerTrackerTest to mock correct config API" into rvc-dev
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(), |