summaryrefslogtreecommitdiff
path: root/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/java/com/android/server/ethernet/EthernetTrackerTest.java')
-rw-r--r--tests/java/com/android/server/ethernet/EthernetTrackerTest.java35
1 files changed, 29 insertions, 6 deletions
diff --git a/tests/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
index 5aca2e4..5087a9b 100644
--- a/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
+++ b/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
@@ -19,9 +19,13 @@ package com.android.server.ethernet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
@@ -55,8 +59,10 @@ import java.util.ArrayList;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class EthernetTrackerTest {
+ private static final String TEST_IFACE = "test123";
private static final int TIMEOUT_MS = 1_000;
private static final String THREAD_NAME = "EthernetServiceThread";
+ private static final IInternalNetworkManagementListener NULL_LISTENER = null;
private EthernetTracker tracker;
private HandlerThread mHandlerThread;
@Mock private Context mContext;
@@ -68,6 +74,7 @@ public class EthernetTrackerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
initMockResources();
+ when(mFactory.updateInterfaceLinkState(anyString(), anyBoolean(), any())).thenReturn(false);
mHandlerThread = new HandlerThread(THREAD_NAME);
mHandlerThread.start();
tracker = new EthernetTracker(mContext, mHandlerThread.getThreadHandler(), mFactory, mNetd);
@@ -294,16 +301,15 @@ public class EthernetTrackerTest {
@Test
public void testCreateEthernetTrackerConfigReturnsCorrectValue() {
- final String iface = "1";
final String capabilities = "2";
final String ipConfig = "3";
final String transport = "4";
- final String configString = String.join(";", iface, capabilities, ipConfig, transport);
+ final String configString = String.join(";", TEST_IFACE, capabilities, ipConfig, transport);
final EthernetTracker.EthernetTrackerConfig config =
EthernetTracker.createEthernetTrackerConfig(configString);
- assertEquals(iface, config.mIface);
+ assertEquals(TEST_IFACE, config.mIface);
assertEquals(capabilities, config.mCapabilities);
assertEquals(ipConfig, config.mIpConfig);
assertEquals(transport, config.mTransport);
@@ -317,16 +323,33 @@ public class EthernetTrackerTest {
@Test
public void testUpdateConfiguration() {
- final String iface = "testiface";
final NetworkCapabilities capabilities = new NetworkCapabilities.Builder().build();
final StaticIpConfiguration staticIpConfig = new StaticIpConfiguration();
final IInternalNetworkManagementListener listener = null;
- tracker.updateConfiguration(iface, staticIpConfig, capabilities, listener);
+ tracker.updateConfiguration(TEST_IFACE, staticIpConfig, capabilities, listener);
waitForIdle();
verify(mFactory).updateInterface(
- eq(iface), eq(EthernetTracker.createIpConfiguration(staticIpConfig)),
+ eq(TEST_IFACE), eq(EthernetTracker.createIpConfiguration(staticIpConfig)),
eq(capabilities), eq(listener));
}
+
+ @Test
+ public void testConnectNetworkCorrectlyCallsFactory() {
+ tracker.connectNetwork(TEST_IFACE, NULL_LISTENER);
+ waitForIdle();
+
+ verify(mFactory).updateInterfaceLinkState(eq(TEST_IFACE), eq(true /* up */),
+ eq(NULL_LISTENER));
+ }
+
+ @Test
+ public void testDisconnectNetworkCorrectlyCallsFactory() {
+ tracker.disconnectNetwork(TEST_IFACE, NULL_LISTENER);
+ waitForIdle();
+
+ verify(mFactory).updateInterfaceLinkState(eq(TEST_IFACE), eq(false /* up */),
+ eq(NULL_LISTENER));
+ }
}