Search in sources :

Example 76 with MockContentResolver

use of android.test.mock.MockContentResolver in project platform_packages_providers_telephonyprovider by aosp-mirror.

the class ServiceStateProviderTest method setUp.

@Before
public void setUp() throws Exception {
    mContext = mock(Context.class);
    mContentResolver = new MockContentResolver() {

        @Override
        public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
            throw new RuntimeException("notifyChange!");
        }
    };
    doReturn(mContentResolver).when(mContext).getContentResolver();
    testServiceState = new ServiceState();
    testServiceState.setStateOutOfService();
    testServiceStateForSubId1 = new ServiceState();
    testServiceStateForSubId1.setStateOff();
    // Mock out the actual phone state
    ServiceStateProvider provider = new ServiceStateProvider() {

        @Override
        public ServiceState getServiceState(int subId) {
            if (subId == 1) {
                return testServiceStateForSubId1;
            } else {
                return testServiceState;
            }
        }

        @Override
        public int getDefaultSubId() {
            return 0;
        }
    };
    ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.authority = "service-state";
    provider.attachInfoForTesting(mContext, providerInfo);
    mContentResolver.addProvider("service-state", provider);
}
Also used : Context(android.content.Context) ServiceState(android.telephony.ServiceState) ProviderInfo(android.content.pm.ProviderInfo) MockContentResolver(android.test.mock.MockContentResolver) Uri(android.net.Uri) ContentObserver(android.database.ContentObserver) Before(org.junit.Before)

Example 77 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_opt_telephony by LineageOS.

the class CdmaInboundSmsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp("CdmaInboundSmsHandlerTest");
    Field field = SmsMessage.class.getDeclaredField("mEnvelope");
    field.setAccessible(true);
    field.set(mCdmaSmsMessage, mSmsEnvelope);
    UserManager userManager = (UserManager) mContextFixture.getTestDouble().getSystemService(Context.USER_SERVICE);
    doReturn(true).when(userManager).isUserUnlocked();
    try {
        doReturn(new int[] { UserHandle.USER_SYSTEM }).when(mIActivityManager).getRunningUserIds();
    } catch (RemoteException re) {
        fail("Unexpected RemoteException: " + re.getStackTrace());
    }
    byte[] smsPdu = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
    mSmsMessage.mWrappedSmsMessage = mCdmaSmsMessage;
    doReturn(smsPdu).when(mCdmaSmsMessage).getPdu();
    mInboundSmsTrackerCV.put("destination_port", 1 << 16);
    mInboundSmsTrackerCV.put("pdu", HexDump.toHexString(smsPdu));
    mInboundSmsTrackerCV.put("address", "1234567890");
    mInboundSmsTrackerCV.put("reference_number", 1);
    mInboundSmsTrackerCV.put("sequence", 1);
    mInboundSmsTrackerCV.put("count", 1);
    mInboundSmsTrackerCV.put("date", System.currentTimeMillis());
    mInboundSmsTrackerCV.put("message_body", "This is the message body of a single-part " + "message");
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    doReturn(1).when(mInboundSmsTracker).getMessageCount();
    doReturn(-1).when(mInboundSmsTracker).getDestPort();
    doReturn(mInboundSmsTrackerCV).when(mInboundSmsTracker).getContentValues();
    doReturn(smsPdu).when(mInboundSmsTracker).getPdu();
    doReturn("This is the message body").when(mInboundSmsTracker).getMessageBody();
    doReturn("1234567890").when(mInboundSmsTracker).getAddress();
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mCdmaInboundSmsHandlerTestHandler = new CdmaInboundSmsHandlerTestHandler(TAG);
    mCdmaInboundSmsHandlerTestHandler.start();
    waitUntilReady();
}
Also used : FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) Field(java.lang.reflect.Field) UserManager(android.os.UserManager) RemoteException(android.os.RemoteException) MockContentResolver(android.test.mock.MockContentResolver) Before(org.junit.Before)

Example 78 with MockContentResolver

use of android.test.mock.MockContentResolver 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();
    try {
        doReturn(new int[] { UserHandle.USER_SYSTEM }).when(mIActivityManager).getRunningUserIds();
    } catch (RemoteException re) {
        fail("Unexpected RemoteException: " + re.getStackTrace());
    }
    mSmsMessage.mWrappedSmsMessage = mGsmSmsMessage;
    mInboundSmsTrackerCV.put("destination_port", InboundSmsTracker.DEST_PORT_FLAG_NO_PORT);
    mInboundSmsTrackerCV.put("pdu", HexDump.toHexString(mSmsPdu));
    mInboundSmsTrackerCV.put("address", "1234567890");
    mInboundSmsTrackerCV.put("reference_number", 1);
    mInboundSmsTrackerCV.put("sequence", 1);
    mInboundSmsTrackerCV.put("count", 1);
    mInboundSmsTrackerCV.put("date", System.currentTimeMillis());
    mInboundSmsTrackerCV.put("message_body", mMessageBody);
    mInboundSmsTrackerCV.put("display_originating_addr", "1234567890");
    doReturn(1).when(mInboundSmsTracker).getMessageCount();
    doReturn(1).when(mInboundSmsTracker).getReferenceNumber();
    doReturn("1234567890").when(mInboundSmsTracker).getAddress();
    doReturn(1).when(mInboundSmsTracker).getSequenceNumber();
    doReturn(1).when(mInboundSmsTracker).getIndexOffset();
    doReturn(-1).when(mInboundSmsTracker).getDestPort();
    doReturn(mMessageBody).when(mInboundSmsTracker).getMessageBody();
    doReturn(mSmsPdu).when(mInboundSmsTracker).getPdu();
    doReturn(mInboundSmsTrackerCV.get("date")).when(mInboundSmsTracker).getTimestamp();
    doReturn(mInboundSmsTrackerCV).when(mInboundSmsTracker).getContentValues();
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mGsmInboundSmsHandlerTestHandler = new GsmInboundSmsHandlerTestHandler(TAG);
    mGsmInboundSmsHandlerTestHandler.start();
    waitUntilReady();
}
Also used : FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) UserManager(android.os.UserManager) RemoteException(android.os.RemoteException) MockContentResolver(android.test.mock.MockContentResolver) Before(org.junit.Before)

Example 79 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class ContactsManagerTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    // Fake content provider
    mFakeContactsContentProvider = new FakeContactsContentProvider();
    mMatrixCursor = new MatrixCursor(ContactsDictionaryConstants.PROJECTION);
    // Add the fake content provider to fake content resolver.
    final MockContentResolver contentResolver = new MockContentResolver();
    contentResolver.addProvider(ContactsContract.AUTHORITY, mFakeContactsContentProvider);
    // Add the fake content resolver to a fake context.
    final ContextWithMockContentResolver context = new ContextWithMockContentResolver(mContext);
    context.setContentResolver(contentResolver);
    mManager = new ContactsManager(context);
}
Also used : ContactsManager(com.android.inputmethod.latin.ContactsManager) MockContentResolver(android.test.mock.MockContentResolver) MatrixCursor(android.database.MatrixCursor) Before(org.junit.Before)

Aggregations

MockContentResolver (android.test.mock.MockContentResolver)79 Account (android.accounts.Account)22 MockContext (android.test.mock.MockContext)17 AtomicFile (com.android.internal.os.AtomicFile)16 File (java.io.File)16 FileOutputStream (java.io.FileOutputStream)16 Context (android.content.Context)13 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 ContextWrapper (android.content.ContextWrapper)10 Bundle (android.os.Bundle)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 ComponentName (android.content.ComponentName)4 MockContentProvider (com.android.contacts.common.test.mocks.MockContentProvider)4 PeriodicSync (android.content.PeriodicSync)3 ProviderInfo (android.content.pm.ProviderInfo)3 IsolatedContext (android.test.IsolatedContext)3 Uri (android.net.Uri)2 RemoteException (android.os.RemoteException)2