diff options
| author | 2017-01-21 04:43:27 +0000 | |
|---|---|---|
| committer | 2017-01-21 04:43:27 +0000 | |
| commit | d4d464ae2cc34fc30426d214ffa24c278584f07a (patch) | |
| tree | 67f47f80486e85918b6e1146c2fbfb21d1f2f102 | |
| parent | ac05acad456ede60d532d5ac40d1b3eecc5bc559 (diff) | |
| parent | 9c3a298748b913c2331e25d561a9bd94e9733aec (diff) | |
Merge "Address a few unittest comments."
am: 9c3a298748
Change-Id: I2d41cdbe05653bcbed9d3b38b440c06b98006809
| -rw-r--r-- | tests/net/java/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/tests/net/java/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java b/tests/net/java/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java index b4d48712cfe0..0cd065169713 100644 --- a/tests/net/java/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java +++ b/tests/net/java/com/android/server/connectivity/tethering/UpstreamNetworkMonitorTest.java @@ -22,6 +22,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Mockito.reset; import android.content.Context; @@ -69,12 +70,13 @@ public class UpstreamNetworkMonitorTest { @Test public void testDoesNothingBeforeStarted() { - UpstreamNetworkMonitor unm = new UpstreamNetworkMonitor(null, null, EVENT_UNM_UPDATE); - assertFalse(unm.mobileNetworkRequested()); - // Given a null Context, and therefore a null ConnectivityManager, - // these would cause an exception, if they actually attempted anything. - unm.updateMobileRequiresDun(true); - unm.updateMobileRequiresDun(false); + assertTrue(mCM.hasNoCallbacks()); + assertFalse(mUNM.mobileNetworkRequested()); + + mUNM.updateMobileRequiresDun(true); + assertTrue(mCM.hasNoCallbacks()); + mUNM.updateMobileRequiresDun(false); + assertTrue(mCM.hasNoCallbacks()); } @Test @@ -85,7 +87,7 @@ public class UpstreamNetworkMonitorTest { assertEquals(1, mCM.trackingDefault.size()); mUNM.stop(); - assertTrue(mCM.isEmpty()); + assertTrue(mCM.hasNoCallbacks()); } @Test @@ -97,11 +99,11 @@ public class UpstreamNetworkMonitorTest { assertTrue(mCM.isListeningForDun()); mUNM.stop(); - assertTrue(mCM.isEmpty()); + assertTrue(mCM.hasNoCallbacks()); } @Test - public void testCanRequestMobileNetwork() throws Exception { + public void testRequestsMobileNetwork() throws Exception { assertFalse(mUNM.mobileNetworkRequested()); assertEquals(0, mCM.requested.size()); @@ -123,11 +125,11 @@ public class UpstreamNetworkMonitorTest { mUNM.stop(); assertFalse(mUNM.mobileNetworkRequested()); - assertTrue(mCM.isEmpty()); + assertTrue(mCM.hasNoCallbacks()); } @Test - public void testCanRequestDunNetwork() throws Exception { + public void testRequestsDunNetwork() throws Exception { assertFalse(mUNM.mobileNetworkRequested()); assertEquals(0, mCM.requested.size()); @@ -149,7 +151,7 @@ public class UpstreamNetworkMonitorTest { mUNM.stop(); assertFalse(mUNM.mobileNetworkRequested()); - assertTrue(mCM.isEmpty()); + assertTrue(mCM.hasNoCallbacks()); } private static class TestConnectivityManager extends ConnectivityManager { @@ -162,7 +164,7 @@ public class UpstreamNetworkMonitorTest { super(ctx, svc); } - boolean isEmpty() { + boolean hasNoCallbacks() { return trackingDefault.isEmpty() && listening.isEmpty() && requested.isEmpty() && @@ -225,6 +227,8 @@ public class UpstreamNetworkMonitorTest { } else if (requested.containsKey(cb)) { requested.remove(cb); legacyTypeMap.remove(cb); + } else { + fail("Unexpected callback removed"); } assertFalse(trackingDefault.contains(cb)); |