diff options
author | Peter Qiu <zqiu@google.com> | 2017-03-16 23:54:26 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-03-16 23:54:26 +0000 |
commit | c4ffd679940aa0177a0fba2c8693619f8b3cc6e9 (patch) | |
tree | bb2313f5c23e1c7285db1890d3c3fea994f11fe5 /tests | |
parent | ff5296a14a7b1336bdfd78d9dbd43de0adefe013 (diff) | |
parent | 874395d470ba902ff5cba880e7fbfb07a8d24c06 (diff) |
hotspot2: update semantics for PasspointManager#matchProvider am: b54f07e01c am: f80d78535b
am: 874395d470
Change-Id: I545a1bdc18d3a92730d8da73e333f6f872fb9b81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java | 38 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java | 42 |
2 files changed, 29 insertions, 51 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index a86d961ba..887e6354f 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -28,6 +28,7 @@ import static android.net.wifi.WifiManager.EXTRA_URL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; @@ -552,19 +553,17 @@ public class PasspointManagerTest { } /** - * Verify that an empty list will be returned when no providers are installed. + * Verify that a {code null} will be returned when no providers are installed. * * @throws Exception */ @Test public void matchProviderWithNoProvidersInstalled() throws Exception { - List<Pair<PasspointProvider, PasspointMatch>> result = - mManager.matchProvider(createTestScanResult()); - assertTrue(result.isEmpty()); + assertNull(mManager.matchProvider(createTestScanResult())); } /** - * Verify that an empty list will be returned when ANQP entry doesn't exist in the cache. + * Verify that a {code null} be returned when ANQP entry doesn't exist in the cache. * * @throws Exception */ @@ -573,17 +572,14 @@ public class PasspointManagerTest { addTestProvider(); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); - List<Pair<PasspointProvider, PasspointMatch>> result = - mManager.matchProvider(createTestScanResult()); + assertNull(mManager.matchProvider(createTestScanResult())); // Verify that a request for ANQP elements is initiated. verify(mAnqpRequestManager).requestANQPElements(eq(TEST_BSSID), any(ANQPNetworkKey.class), anyBoolean(), anyBoolean()); - assertTrue(result.isEmpty()); } /** - * Verify that the returned list will contained an expected provider when a HomeProvider - * is matched. + * Verify that the expected provider will be returned when a HomeProvider is matched. * * @throws Exception */ @@ -594,15 +590,14 @@ public class PasspointManagerTest { when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(provider.match(anyMap())).thenReturn(PasspointMatch.HomeProvider); - List<Pair<PasspointProvider, PasspointMatch>> result = + Pair<PasspointProvider, PasspointMatch> result = mManager.matchProvider(createTestScanResult()); - assertEquals(1, result.size()); - assertEquals(PasspointMatch.HomeProvider, result.get(0).second); + assertEquals(PasspointMatch.HomeProvider, result.second); + assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn()); } /** - * Verify that the returned list will contained an expected provider when a RoamingProvider - * is matched. + * Verify that the expected provider will be returned when a RoamingProvider is matched. * * @throws Exception */ @@ -613,15 +608,14 @@ public class PasspointManagerTest { when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(provider.match(anyMap())).thenReturn(PasspointMatch.RoamingProvider); - List<Pair<PasspointProvider, PasspointMatch>> result = + Pair<PasspointProvider, PasspointMatch> result = mManager.matchProvider(createTestScanResult()); - assertEquals(1, result.size()); - assertEquals(PasspointMatch.RoamingProvider, result.get(0).second); - assertEquals(TEST_FQDN, provider.getConfig().getHomeSp().getFqdn()); + assertEquals(PasspointMatch.RoamingProvider, result.second); + assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn()); } /** - * Verify that an empty list will be returned when there is no matching provider. + * Verify that a {code null} will be returned when there is no matching provider. * * @throws Exception */ @@ -632,9 +626,7 @@ public class PasspointManagerTest { when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); when(provider.match(anyMap())).thenReturn(PasspointMatch.None); - List<Pair<PasspointProvider, PasspointMatch>> result = - mManager.matchProvider(createTestScanResult()); - assertEquals(0, result.size()); + assertNull(mManager.matchProvider(createTestScanResult())); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java index 05d9ea225..c4527adc4 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java @@ -128,8 +128,7 @@ public class PasspointNetworkEvaluatorTest { List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] { generateScanDetail(TEST_SSID1), generateScanDetail(TEST_SSID2)}); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); - List<Pair<PasspointProvider, PasspointMatch>> matchedProviders = new ArrayList<>(); - when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders); + when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(null); assertEquals(null, mEvaluator.evaluateNetworks( scanDetails, null, null, false, false, connectableNetworks)); assertTrue(connectableNetworks.isEmpty()); @@ -158,31 +157,26 @@ public class PasspointNetworkEvaluatorTest { } /** - * Verify that when both home provider and roaming provider is found for the same network, - * home provider is preferred. + * Verify that when a network matches a home provider is found, the correct network + * information (WifiConfiguration) is setup and returned. * * @throws Exception */ @Test - public void evaluateScansWithNetworkMatchingHomeAndRoamingProvider() throws Exception { + public void evaluateScansWithNetworkMatchingHomeProvider() throws Exception { List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] { generateScanDetail(TEST_SSID1), generateScanDetail(TEST_SSID2)}); // Setup matching providers for ScanDetail with TEST_SSID1. Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create( TEST_PROVIDER1, PasspointMatch.HomeProvider); - Pair<PasspointProvider, PasspointMatch> roamingProvider = Pair.create( - TEST_PROVIDER2, PasspointMatch.RoamingProvider); - List<Pair<PasspointProvider, PasspointMatch>> matchedProviders = new ArrayList<>(); - matchedProviders.add(homeProvider); - matchedProviders.add(roamingProvider); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); - // Return matchedProviders for the first ScanDetail (TEST_SSID1) and an empty list for + // Return homeProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for // for the second (TEST_SSID2); - when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders) - .thenReturn(new ArrayList<Pair<PasspointProvider, PasspointMatch>>()); + when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider) + .thenReturn(null); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); @@ -217,15 +211,13 @@ public class PasspointNetworkEvaluatorTest { // Setup matching providers for ScanDetail with TEST_SSID1. Pair<PasspointProvider, PasspointMatch> roamingProvider = Pair.create( TEST_PROVIDER1, PasspointMatch.RoamingProvider); - List<Pair<PasspointProvider, PasspointMatch>> matchedProviders = new ArrayList<>(); - matchedProviders.add(roamingProvider); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); - // Return matchedProviders for the first ScanDetail (TEST_SSID1) and an empty list for + // Return roamingProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for // for the second (TEST_SSID2); - when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(matchedProviders) - .thenReturn(new ArrayList<Pair<PasspointProvider, PasspointMatch>>()); + when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(roamingProvider) + .thenReturn(null); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); @@ -262,17 +254,13 @@ public class PasspointNetworkEvaluatorTest { TEST_PROVIDER1, PasspointMatch.HomeProvider); Pair<PasspointProvider, PasspointMatch> roamingProvider = Pair.create( TEST_PROVIDER2, PasspointMatch.RoamingProvider); - List<Pair<PasspointProvider, PasspointMatch>> providerForScanDetail1 = new ArrayList<>(); - providerForScanDetail1.add(homeProvider); - List<Pair<PasspointProvider, PasspointMatch>> providerForScanDetail2 = new ArrayList<>(); - providerForScanDetail2.add(roamingProvider); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); - // Return providerForScanDetail1 for the first ScanDetail (TEST_SSID1) and - // providerForScanDetail2 for the second (TEST_SSID2); + // Return homeProvider for the first ScanDetail (TEST_SSID1) and + // roamingProvider for the second (TEST_SSID2); when(mPasspointManager.matchProvider(any(ScanResult.class))) - .thenReturn(providerForScanDetail1).thenReturn(providerForScanDetail2); + .thenReturn(homeProvider).thenReturn(roamingProvider); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); @@ -307,8 +295,6 @@ public class PasspointNetworkEvaluatorTest { // Setup matching providers for both ScanDetail. Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create( TEST_PROVIDER1, PasspointMatch.HomeProvider); - List<Pair<PasspointProvider, PasspointMatch>> matchedProviders = new ArrayList<>(); - matchedProviders.add(homeProvider); // Setup currently connected network WifiConfiguration currentNetwork = new WifiConfiguration(); @@ -319,7 +305,7 @@ public class PasspointNetworkEvaluatorTest { // Returning the same matching provider for both ScanDetail. List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); when(mPasspointManager.matchProvider(any(ScanResult.class))) - .thenReturn(matchedProviders).thenReturn(matchedProviders); + .thenReturn(homeProvider).thenReturn(homeProvider); WifiConfiguration config = mEvaluator.evaluateNetworks(scanDetails, currentNetwork, currentBssid, true, false, connectableNetworks); assertEquals(1, connectableNetworks.size()); |