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

Commit 93dc55f2 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix Telecom unit tests.

Ensure mock context can handle sending broadcast for the phone account
intents.
Fix register/unregister TelecomServiceImpl tests that no longer send
intents directly.

Test: Unit
Bug: 37106957
Change-Id: I414f888f1897108fd991e7b0a7e24fc9cc892c59
parent 9533e0a4
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -466,22 +466,10 @@ public class TelecomServiceImplTest extends TelecomTestCase {
        if (shouldSucceed) {
            assertFalse(didExceptionOccur);
            verify(mFakePhoneAccountRegistrar).registerPhoneAccount(testPhoneAccount);
            verify(mContext).sendBroadcastAsUser(intentCaptor.capture(), eq(UserHandle.ALL),
                    anyString());

            Intent capturedIntent = intentCaptor.getValue();
            assertEquals(TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED,
                    capturedIntent.getAction());
            Bundle intentExtras = capturedIntent.getExtras();
            assertEquals(1, intentExtras.size());
            assertEquals(testPhoneAccount.getAccountHandle(),
                    intentExtras.get(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
        } else {
            assertTrue(didExceptionOccur);
            verify(mFakePhoneAccountRegistrar, never())
                    .registerPhoneAccount(any(PhoneAccount.class));
            verify(mContext, never())
                    .sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), anyString());
        }
    }

@@ -497,14 +485,6 @@ public class TelecomServiceImplTest extends TelecomTestCase {

        mTSIBinder.unregisterPhoneAccount(phHandle);
        verify(mFakePhoneAccountRegistrar).unregisterPhoneAccount(phHandle);
        verify(mContext).sendBroadcastAsUser(intentCaptor.capture(), eq(UserHandle.ALL),
                anyString());
        Intent capturedIntent = intentCaptor.getValue();
        assertEquals(TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED,
                capturedIntent.getAction());
        Bundle intentExtras = capturedIntent.getExtras();
        assertEquals(1, intentExtras.size());
        assertEquals(phHandle, intentExtras.get(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
    }

    @SmallTest
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -311,6 +312,7 @@ public class TelecomSystemTest extends TelecomTestCase {
        super.setUp();
        mSpyContext = mComponentContextFixture.getTestDouble().getApplicationContext();
        doReturn(mSpyContext).when(mSpyContext).getApplicationContext();
        doNothing().when(mSpyContext).sendBroadcastAsUser(any(), any(), any());

        mNumOutgoingCallsMade = 0;