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);
}
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();
}
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();
}
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);
}
Aggregations