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

Commit 61fd9f9a authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Finish mocking in finally clause

Failure of testIpClientServiceAvailableAfterPolling could cause tests in
the same process to fail because the mockito session is not finalized.
Use try / finally to make sure finishMocking is called.

Test: atest ModuleNetworkStackClientTest
Bug: 139314310
Change-Id: I95cc24e789c5af5f655c875314ed97f50121166c
parent eb138e5d
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -95,15 +95,17 @@ class ModuleNetworkStackClientTest {
        // Force NetworkStack.getService() to return null: this cannot be done with
        // setServiceForTest, as passing null just restores default behavior.
        val session = mockitoSession().spyStatic(NetworkStack::class.java).startMocking()
        try {
            doReturn(null).`when` { NetworkStack.getService() }
            ModuleNetworkStackClient.getInstance(mContext).makeIpClient(TEST_IFNAME, mIpClientCb)

            Thread.sleep(TEST_TIMEOUT_MS)
            verify(mConnector, never()).makeIpClient(any(), any())
            NetworkStack.setServiceForTest(mConnectorBinder)

        } finally {
            // Restore behavior of NetworkStack to return what was set in setServiceForTest
            session.finishMocking()
        }

        // Use a longer timeout as polling can cause larger delays
        verify(mConnector, timeout(TEST_TIMEOUT_MS * 4)).makeIpClient(TEST_IFNAME, mIpClientCb)