Search in sources :

Example 6 with TestableLooper

use of android.testing.TestableLooper in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp("GsmInboundSmsHandlerTest");
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    doReturn(true).when(userManager).isUserUnlocked();
    doReturn(true).when(userManager).isUserRunning(any(UserHandle.class));
    List<UserHandle> userHandles = new ArrayList();
    userHandles.add(UserHandle.SYSTEM);
    doReturn(userHandles).when(userManager).getUserHandles(anyBoolean());
    mSmsMessage.mWrappedSmsMessage = mGsmSmsMessage;
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    mMessageBody, /* messageBody */
    false, /* isClass0 */
    mSubId0);
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), anyBoolean(), nullable(String.class), nullable(String.class), nullable(String.class), anyBoolean(), anyInt());
    createMockInboundSmsTracker();
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mGsmInboundSmsHandler = GsmInboundSmsHandler.makeInboundSmsHandler(mContext, mSmsStorageMonitor, mPhone);
    mSmsFilters = new ArrayList<>();
    mSmsFilters.add(mSmsFilter);
    mSmsFilters.add(mSmsFilter2);
    mGsmInboundSmsHandler.setSmsFiltersForTesting(mSmsFilters);
    monitorTestableLooper(new TestableLooper(mGsmInboundSmsHandler.getHandler().getLooper()));
    processAllMessages();
}
Also used : Context(android.content.Context) FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) MockContentResolver(android.test.mock.MockContentResolver) TestableLooper(android.testing.TestableLooper) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) Before(org.junit.Before)

Aggregations

TestableLooper (android.testing.TestableLooper)6 Context (android.content.Context)4 MockContentResolver (android.test.mock.MockContentResolver)3 RemoteException (android.os.RemoteException)2 UserManager (android.os.UserManager)2 FakeSmsContentProvider (com.android.internal.telephony.FakeSmsContentProvider)2 InboundSmsTracker (com.android.internal.telephony.InboundSmsTracker)2 Before (org.junit.Before)2 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentResolver (android.content.ContentResolver)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 Looper (android.os.Looper)1 Message (android.os.Message)1 MessageQueue (android.os.MessageQueue)1 PersistableBundle (android.os.PersistableBundle)1 UserHandle (android.os.UserHandle)1