From 279516b46c950d9fbc3967bda2952e52d6748137 Mon Sep 17 00:00:00 2001 From: Quang Luong Date: Tue, 5 May 2020 15:54:07 -0700 Subject: [WifiTrackerLib] Fix WifiPickerTrackerTest to mock correct config API The API call to get configured networks was changed from getConfiguredNetworks() to getPrivilegedConfiguredNetworks(), so the unit tests must be changed to match the new behavior of WifiPickerTracker. Bug: 155812281 Test: atest WifiTrackerLibTests Change-Id: Ida1f01aea07490b8d133194181dc44fe7d70ade2 --- .../wifitrackerlib/WifiPickerTrackerTest.java | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'libs') 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(), -- cgit v1.2.3