Merge "Address a few unittest comments."

This commit is contained in:
Erik Kline
2017-01-21 04:36:27 +00:00
committed by Gerrit Code Review

View File

@@ -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));