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

Commit f1f11c27 authored by Nikhil Nayunigari's avatar Nikhil Nayunigari Committed by Android (Google) Code Review
Browse files

Merge "Fix a flaky test in EthernetInterfaceTracker" into main

parents d1f4131f 1884f4ef
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -25,12 +25,15 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.mock

@Ignore
@RunWith(AndroidJUnit4::class)
class EthernetTrackerImplTest {
class EthernetInterfaceTrackerTest {
    private val mockEthernetManager = mock<EthernetManager>()

    private val context: Context =
@@ -44,9 +47,19 @@ class EthernetTrackerImplTest {

    private val ethernetTrackerImpl = EthernetTrackerImpl.getInstance(context)

    @Before
    fun setUp() {
        ethernetTrackerImpl.onInterfaceStateChanged(
            "eth0",
            EthernetManager.STATE_ABSENT,
            EthernetManager.ROLE_NONE,
            IpConfiguration(),
        )
    }

    @Test
    fun getInterface_shouldReturnEmpty() {
        assertNull(ethernetTrackerImpl.getInterface("id0"))
        assertNull(ethernetTrackerImpl.getInterface("eth0"))
    }

    @Test
@@ -57,23 +70,21 @@ class EthernetTrackerImplTest {
    @Test
    fun interfacesChanged_shouldUpdateInterfaces() {
        ethernetTrackerImpl.onInterfaceStateChanged(
            "id0",
            "eth0",
            EthernetManager.STATE_LINK_DOWN,
            EthernetManager.ROLE_NONE,
            IpConfiguration(),
        )

        assertNotNull(ethernetTrackerImpl.getInterface("id0"))
        assertEquals(ethernetTrackerImpl.availableInterfaces.size, 1)
        assertNotNull(ethernetTrackerImpl.getInterface("eth0"))

        ethernetTrackerImpl.onInterfaceStateChanged(
            "id0",
            "eth0",
            EthernetManager.STATE_ABSENT,
            EthernetManager.ROLE_NONE,
            IpConfiguration(),
        )

        assertNull(ethernetTrackerImpl.getInterface("id0"))
        assertEquals(ethernetTrackerImpl.availableInterfaces.size, 0)
        assertNull(ethernetTrackerImpl.getInterface("eth0"))
    }
}