Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4d464ae authored by Erik Kline's avatar Erik Kline Committed by android-build-merger
Browse files

Merge "Address a few unittest comments."

am: 9c3a2987

Change-Id: I2d41cdbe05653bcbed9d3b38b440c06b98006809
parents ac05acad 9c3a2987
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -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));