android.test.mock.MockContentResolver Java Examples
The following examples show how to use
android.test.mock.MockContentResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationProviderTestCase.java From background-geolocation-android with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { super.setUp(); mResolver = new MockContentResolver(); RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext( new DelegatedMockContext(getContext()), // The context that most methods are delegated to getContext(), // The context that file methods are delegated to filenamePrefix); mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); ProviderInfo providerInfo = new ProviderInfo(); providerInfo.authority = mProviderAuthority; mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, providerInfo); assertNotNull(mProvider); mResolver.addProvider(mProviderAuthority, mProvider); }
Example #2
Source File: PickerPresenterTest.java From boxing with Apache License 2.0 | 6 votes |
@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); } }); }
Example #3
Source File: SearchEngineTest.java From mytracks with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: MyTracksProviderUtilsImplTest.java From mytracks with Apache License 2.0 | 6 votes |
@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); }
Example #5
Source File: SimpleOperationTest.java From arca-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); }
Example #6
Source File: TrayProviderTestCase.java From tray with Apache License 2.0 | 6 votes |
public ContentResolver getMockResolver() { final MockContentResolver mockContentResolver = new MockContentResolver(mTargetContext); for (String authority : mProviders.keySet()) { mockContentResolver.addProvider(authority, mProviders.get(authority)); } return mockContentResolver; }
Example #7
Source File: ProviderTestRule.java From android-test with Apache License 2.0 | 6 votes |
public ProviderTestRule build() { Set<WeakReference<ContentProvider>> mProvidersRef = new HashSet<>(); MockContentResolver resolver = new MockContentResolver(); DelegatingContext context = new DelegatingContext( InstrumentationRegistry.getInstrumentation().getTargetContext(), prefix, resolver); for (Map.Entry<String, Class<? extends ContentProvider>> entry : providerClasses.entrySet()) { ContentProvider provider = createProvider(entry.getKey(), entry.getValue(), resolver, context); mProvidersRef.add(new WeakReference<>(provider)); } return new ProviderTestRule( mProvidersRef, new HashSet<>(databaseArgsMap.values()), resolver, context); }
Example #8
Source File: RowsTest.java From SMP with GNU General Public License v3.0 | 5 votes |
private Rows initRows(String[][] data, Filter filter) { MockContentResolver resolver = new MockContentResolver(); TestContentProvider provider = new TestContentProvider(getContext(), data); resolver.addProvider(MediaStore.AUTHORITY, provider); Rows rows = new Rows(resolver, new ParametersStub(), null); rows.setFilter(filter); rows.init(); return rows; }
Example #9
Source File: ContactsManagerTest.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@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); }
Example #10
Source File: RowsTest.java From SMP with GNU General Public License v3.0 | 5 votes |
private Rows initRows(String[][] data, Filter filter) { MockContentResolver resolver = new MockContentResolver(); TestContentProvider provider = new TestContentProvider(getContext(), data); resolver.addProvider(MediaStore.AUTHORITY, provider); Rows rows = new Rows(resolver, new ParametersStub(), null); rows.setFilter(filter); rows.init(); return rows; }
Example #11
Source File: FileTrackExporterTest.java From mytracks with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); MockContentResolver mockContentResolver = new MockContentResolver(); RenamingDelegatingContext targetContext = new RenamingDelegatingContext( getContext(), getContext(), "test."); Context context = new MockContext(mockContentResolver, targetContext); MyTracksProvider myTracksProvider = new MyTracksProvider(); myTracksProvider.attachInfo(context, null); mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, myTracksProvider); setContext(context); myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); oldProviderUtilsFactory = TestingProviderUtilsFactory.installWithInstance( myTracksProviderUtils); mocksControl = EasyMock.createStrictControl(); trackWriter = mocksControl.createMock(TrackWriter.class); Track track = new Track(); track.setName(TRACK_NAME); track.setId(TRACK_ID); tracks = new Track[] {track}; outputStream = new ByteArrayOutputStream(); TrackExporterListener trackExporterListener = new TrackExporterListener() { @Override public void onProgressUpdate(int number, int max) { // Safe to ignore } }; fileTrackExporter = new FileTrackExporter( myTracksProviderUtils, tracks, trackWriter, trackExporterListener); }
Example #12
Source File: TrackDataHubTest.java From mytracks with Apache License 2.0 | 5 votes |
@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); }
Example #13
Source File: ProviderTestRule.java From android-test with Apache License 2.0 | 4 votes |
private ContentProvider createProvider( String auth, Class<? extends ContentProvider> clazz, MockContentResolver resolver, Context context) { ContentProvider provider; try { provider = clazz.getConstructor().newInstance(); } catch (NoSuchMethodException me) { Log.e( TAG, "NoSuchMethodException occurred when trying create new Instance for " + clazz.toString()); throw new RuntimeException(me); } catch (InvocationTargetException ite) { Log.e( TAG, "InvocationTargetException occurred when trying create new Instance for " + clazz.toString()); throw new RuntimeException(ite); } catch (IllegalAccessException iae) { Log.e( TAG, "IllegalAccessException occurred when trying create new Instance for " + clazz.toString()); throw new RuntimeException(iae); } catch (InstantiationException ie) { Log.e( TAG, "InstantiationException occurred when trying create new Instance for " + clazz.toString()); throw new RuntimeException(ie); } ProviderInfo providerInfo = new ProviderInfo(); providerInfo.authority = auth; // attachInfo will call ContentProvider.onCreate(), so will refresh the context // used by ContentProvider. provider.attachInfo(context, providerInfo); resolver.addProvider(providerInfo.authority, provider); return provider; }
Example #14
Source File: SupportRequestDispatcherTest.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
private RequestDispatcher getDispatcher() { final MockContentResolver resolver = new MockContentResolver(); resolver.addProvider(AUTHORITY, mProvider); final RequestExecutor executor = new RequestExecutor.DefaultRequestExecutor(resolver); return new SupportRequestDispatcher(executor, getContext(), mLoaderManager); }
Example #15
Source File: ModernRequestDispatcherTest.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
private RequestDispatcher getDispatcher() { final MockContentResolver resolver = new MockContentResolver(); resolver.addProvider(AUTHORITY, mProvider); final RequestExecutor executor = new RequestExecutor.DefaultRequestExecutor(resolver); return new ModernRequestDispatcher(executor, getContext(), mLoaderManager); }
Example #16
Source File: SimpleOperationTest.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public ContentResolver getContentResolver() { final MockContentResolver resolver = new MockContentResolver(); resolver.addProvider(AUTHORITY, mProvider); return resolver; }
Example #17
Source File: MyTracksProviderUtilsImplTest.java From mytracks with Apache License 2.0 | 4 votes |
/** * Tests the method {@link MyTracksProviderUtilsImpl#createContentValues(Waypoint)}. */ public void testCreateContentValues_waypoint() { long trackId = System.currentTimeMillis(); Track track = getTrack(trackId, 10); providerUtils.insertTrack(track); // Bottom long startTime = 1000L; // AverageSpeed double minGrade = -20.11; TripStatistics statistics = new TripStatistics(); statistics.setStartTime(startTime); statistics.setStopTime(2500L); statistics.setTotalTime(1500L); statistics.setMovingTime(700L); statistics.setTotalDistance(750.0); statistics.setTotalElevationGain(50.0); statistics.setMaxSpeed(60.0); statistics.setMaxElevation(1250.0); statistics.setMinElevation(1200.0); statistics.setMaxGrade(15.0); statistics.setMinGrade(minGrade); statistics.setBounds(-10000, 20000, 30000, -40000); // Insert at first. Waypoint waypoint = new Waypoint(); waypoint.setDescription(TEST_DESC); waypoint.setType(WaypointType.STATISTICS); waypoint.setTripStatistics(statistics); Location loc = new Location("test"); loc.setLatitude(22); loc.setLongitude(22); loc.setAccuracy((float) 1 / 100.0f); loc.setAltitude(2.5); waypoint.setLocation(loc); providerUtils.insertWaypoint(waypoint); MyTracksProviderUtilsImpl myTracksProviderUtilsImpl = new MyTracksProviderUtilsImpl( new MockContentResolver()); long waypointId = System.currentTimeMillis(); waypoint.setId(waypointId); ContentValues contentValues = myTracksProviderUtilsImpl.createContentValues(waypoint); assertEquals(waypointId, contentValues.get(WaypointsColumns._ID)); assertEquals(22 * 1000000, contentValues.get(WaypointsColumns.LONGITUDE)); assertEquals(TEST_DESC, contentValues.get(WaypointsColumns.DESCRIPTION)); assertEquals(startTime, contentValues.get(WaypointsColumns.STARTTIME)); assertEquals(minGrade, contentValues.get(WaypointsColumns.MINGRADE)); }
Example #18
Source File: LocationProviderTestCase.java From background-geolocation-android with Apache License 2.0 | 4 votes |
public MockContentResolver getMockContentResolver() { return mResolver; }