本文整理汇总了Java中android.test.mock.MockContentResolver类的典型用法代码示例。如果您正苦于以下问题:Java MockContentResolver类的具体用法?Java MockContentResolver怎么用?Java MockContentResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockContentResolver类属于android.test.mock包,在下文中一共展示了MockContentResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupMockAndViews
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Before
public void setupMockAndViews() {
MockitoAnnotations.initMocks(this);
PowerMockito.mockStatic(BoxingManager.class);
PowerMockito.mockStatic(TextUtils.class);
PowerMockito.when(BoxingManager.getInstance()).thenReturn(mPickerManager);
mPresenter = new PickerPresenter(mView);
MockContentResolver contentResolver = new MockContentResolver();
Mockito.when(mView.getAppCr()).thenReturn(contentResolver);
PowerMockito.when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
CharSequence charSequence = (CharSequence) invocation.getArguments()[0];
return !(charSequence != null && charSequence.length() > 0);
}
});
}
示例2: testSendLogsSingle
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Test
public void testSendLogsSingle() {
Activity activity = mock(Activity.class);
Context context = mock(Context.class);
File file = mock(File.class);
MockContentResolver resolver = new MockContentResolver();
when(file.getPath()).thenReturn("/com/mindera/skeletoid");
when(activity.getFilesDir()).thenReturn(file);
when(activity.getPackageName()).thenReturn("com.mindera.skeletoid");
when(activity.getApplicationContext()).thenReturn(context);
when(activity.getContentResolver()).thenReturn(resolver);
when(context.getFilesDir()).thenReturn(file);
Uri uri = mock(Uri.class);
mockStatic(FileProvider.class);
when(FileProvider.getUriForFile(any(Activity.class), any(String.class), any(File.class))).thenReturn(uri);
mockStatic(Intent.class);
ArgumentCaptor<Intent> intentArgument = ArgumentCaptor.forClass(Intent.class);
ArgumentCaptor<String> titleArgument = ArgumentCaptor.forClass(String.class);
ShareLogFilesUtils.sendLogs(activity, "intentChooserTitle", "subjectTitle", "bodyText", new String[0], file);
verifyStatic();
Intent.createChooser(intentArgument.capture(), titleArgument.capture());
assertNotNull(intentArgument.getValue());
// assertEquals(Intent.ACTION_SEND, intentArgument.getValue().getAction());
assertNotNull(titleArgument.getValue());
// assertEquals("intentChooserTitle", titleArgument.getValue());
}
示例3: test_shouldFirstCallIsLocationModeOn_whenVersionKitKatOrAboveAndGeoActivated
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Test
public void test_shouldFirstCallIsLocationModeOn_whenVersionKitKatOrAboveAndGeoActivated() throws Settings.SettingNotFoundException {
//noinspection WrongConstant
Mockito.when(contextMock.getSystemService(Mockito.eq(Context.LOCATION_SERVICE))).thenReturn(locationManagerMock);
MockContentResolver mockContentResolver = new MockContentResolver();
Mockito.when(contextMock.getContentResolver()).thenReturn(mockContentResolver);
Mockito.when(geoHelperSpy.isLocationModeOn(context)).thenReturn(true);
Mockito.when(geoHelperSpy.isKitKatOrAbove()).thenReturn(true);
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.GEOFENCING_ACTIVATED, true);
// When
geoEnabledConsistencyReceiverWithSpy.onReceive(context, providersChangedIntent);
// Then
Mockito.verify(geoHelperSpy, Mockito.times(1)).isLocationModeOn(context);
Mockito.verify(geoHelperSpy, Mockito.never()).isNetworkProviderAvailable(context);
}
示例4: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
MockContentResolver mockContentResolver = new MockContentResolver();
RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
getContext(), getContext(), "test.");
MockContext context = new MockContext(mockContentResolver, targetContext);
MyTracksProvider provider = new MyTracksProvider();
provider.attachInfo(context, null);
mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, provider);
setContext(context);
providerUtils = MyTracksProviderUtils.Factory.get(context);
engine = new SearchEngine(providerUtils);
}
示例5: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
MockContentResolver mockContentResolver = new MockContentResolver();
RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
getContext(), getContext(), "test.");
context = new MockContext(mockContentResolver, targetContext);
MyTracksProvider provider = new MyTracksProvider();
provider.attachInfo(context, null);
mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, provider);
setContext(context);
providerUtils = MyTracksProviderUtils.Factory.get(context);
providerUtils.deleteAllTracks(context);
}
示例6: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
/**
* Sets up the environment for the test fixture.
* <p>
* Creates a new
* {@link android.test.mock.MockContentResolver}, a new IsolatedContext
* that isolates the provider's file operations, and a new instance of
* the provider under test within the isolated environment.
* </p>
*
* @throws Exception
*/
@Override
protected void setUp() throws Exception {
super.setUp();
mResolver = new MockContentResolver();
final String filenamePrefix = "test.";
RenamingDelegatingContext targetContextWrapper = new
RenamingDelegatingContext(
createMockContext(new MockContext2()), // The context that most methods are delegated to
getContext(), // The context that file methods are delegated to
filenamePrefix);
mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
mProvider = mProviderClass.newInstance();
mProvider.attachInfo(mProviderContext, null);
assertNotNull(mProvider);
mResolver.addProvider(mProviderAuthority, getProvider());
}
示例7: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
File cache = getContext().getCacheDir();
fakeProfileDirectory = new File(cache.getAbsolutePath() + getCacheSuffix());
System.out.println("Test: Creating profile directory " + fakeProfileDirectory.getAbsolutePath());
if (!fakeProfileDirectory.mkdir()) {
throw new IllegalStateException("Could not create temporary directory.");
}
final Context context = getContext();
assertNotNull(context);
resolver = new MockContentResolver();
provider = providerClass.newInstance();
provider.attachInfo(context, null);
assertNotNull(provider);
resolver.addProvider(providerAuthority, getProvider());
}
示例8: testInsertPlanet
import android.test.mock.MockContentResolver; //导入依赖的package包/类
public void testInsertPlanet() {
MockContentResolver contentResolver = getMockContentResolver();
Cursor cursor = contentResolver.query(PlanetContract.Planet.contentUri(), PlanetRecord.projection(), null, null, null);
Assert.assertEquals(8, cursor.getCount());
cursor.close();
// Sorry, Neil deGrasse Tyson...
ContentValues contentValues = PlanetRecord.contentValuesBuilder()
.inhabitedByHumans(false)
.radiusInMeters(1.5e6)
.name("Pluto")
.build();
contentResolver.insert(PlanetContract.Planet.contentUri(), contentValues);
cursor = contentResolver.query(PlanetContract.Planet.contentUri(), PlanetRecord.projection(), null, null, null);
Assert.assertEquals(9, cursor.getCount());
cursor.moveToLast();
Planet planet = PlanetRecord.wrapCursor(cursor);
assertEquals("Pluto", planet.name());
assertEquals(1.5e6, planet.radiusInMeters());
assertEquals(false, planet.inhabitedByHumans());
cursor.close();
}
示例9: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
setContext(InstrumentationRegistry.getTargetContext());
final ProviderInfo providerInfo = new ProviderInfo();
providerInfo.authority = GitHubProvider.AUTHORITY;
contentProvider = new GitHubProvider();
contentProvider.attachInfo(InstrumentationRegistry.getTargetContext(), providerInfo);
contentProvider.delete(GITHUB_REPOSITORIES, null, null);
Thread.sleep(PROVIDER_WAIT_TIME);
final MockContentResolver contentResolver = new MockContentResolver();
contentResolver.addProvider(GitHubProvider.AUTHORITY, contentProvider);
gitHubRepositoryStore = new GitHubRepositoryStore(contentResolver, gson);
testObserver = new TestObserver<>();
super.setUp();
}
示例10: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
setContext(InstrumentationRegistry.getTargetContext());
final ProviderInfo providerInfo = new ProviderInfo();
providerInfo.authority = GitHubProvider.AUTHORITY;
contentProvider = new GitHubProvider();
contentProvider.attachInfo(InstrumentationRegistry.getTargetContext(), providerInfo);
contentProvider.delete(GITHUB_REPOSITORIES, null, null);
Thread.sleep(PROVIDER_WAIT_TIME);
final MockContentResolver contentResolver = new MockContentResolver();
contentResolver.addProvider(GitHubProvider.AUTHORITY, contentProvider);
gitHubRepositoryStoreCore = new GitHubRepositoryStoreCore(contentResolver, new Gson());
super.setUp();
}
示例11: testSimpleOperationNotifiesChangeOnSuccess
import android.test.mock.MockContentResolver; //导入依赖的package包/类
public void testSimpleOperationNotifiesChangeOnSuccess() {
final AssertionLatch latch = new AssertionLatch(1);
final MockContext context = new MockContext() {
@Override
public ContentResolver getContentResolver() {
return new MockContentResolver() {
@Override
public void notifyChange(final Uri u, final ContentObserver o) {
latch.countDown();
}
};
}
};
final TestSimpleOperation operation = new TestSimpleOperation(Uri.EMPTY);
operation.onSuccess(context, null);
latch.assertComplete();
}
示例12: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
final MockContentResolver contentResolver = new MockContentResolver();
contentResolver.addProvider("", new AlarmsProvider());
contentResolver.addProvider(".log", new LogProvider());
mContext = getInstrumentation().getContext();
mController = new SkydiveController(new ContextWrapper(mContext) {
@Override
public ContentResolver getContentResolver() {
return contentResolver;
}
});
mFiredAlarms = new ArrayList<Alarm>();
}
示例13: XmlPullParserTest
import android.test.mock.MockContentResolver; //导入依赖的package包/类
public XmlPullParserTest() {
String root = "http://tomas-vondracek.net/Data/upload/test/";
String xml1 = "akcie_cz_rss.xml";
String xml2 = "patria_cz_rss.xml";
String xml3 = "cyrrus_cz_rss.xml";
try {
this.dataUrl1 = new URL(root + xml1);
this.dataUrl2 = new URL(root + xml2);
this.dataUrl3 = new URL(root + xml3);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.feed = new Feed();
this.feed.setCountryCode("cz");
this.feed.setFeedId(0);
this.feed.setTitle("xml test feed");
this.feed.setUrl(this.dataUrl1);
this.context = new IsolatedContext(new MockContentResolver(), getContext());
}
示例14: populateContactToEmailList
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@Test
public void populateContactToEmailList() {
List<String> contactList = new ArrayList<>(2);
ContentResolver resolver = new MockContentResolver();
when(contactUtil.getEmailList(resolver)).thenReturn(Observable.just(contactList));
loginPresenter.populateAutoComplete(resolver);
verify(view).addEmailsToAutoComplete(contactList);
}
示例15: setUp
import android.test.mock.MockContentResolver; //导入依赖的package包/类
@UsesMocks({ MyTracksProviderUtils.class, DataSource.class, TrackDataListener.class })
@Override
protected void setUp() throws Exception {
super.setUp();
context = new MockContext(new MockContentResolver(), new RenamingDelegatingContext(
getContext(), getContext(), "test."));
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
myTracksProviderUtils = AndroidMock.createMock(MyTracksProviderUtils.class);
dataSource = AndroidMock.createMock(DataSource.class, context);
trackDataManager = new TrackDataManager();
trackDataHub = new TrackDataHub(
context, trackDataManager, myTracksProviderUtils, TARGET_POINTS) {
@Override
protected DataSource newDataSource() {
return dataSource;
}
@Override
protected void runInHanderThread(Runnable runnable) {
// Run everything in the same thread
runnable.run();
}
};
trackDataListener1 = AndroidMock.createStrictMock(
"trackDataListener1", TrackDataListener.class);
trackDataListener2 = AndroidMock.createStrictMock(
"trackDataListener2", TrackDataListener.class);
PreferencesUtils.setLong(context, R.string.recording_track_id_key, TRACK_ID);
}