@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); } }); }
@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()); }
@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); }
@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); }
@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); }
/** * 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()); }
@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()); }
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(); }
@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(); }
@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(); }
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(); }
@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>(); }
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()); }
@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); }
@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); }
@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); }
public TestContext() { super(getInstrumentation().getTargetContext(), "test."); resolver = new MockContentResolver(); resolver.addProvider(AppProvider.getAuthority(), prepareProvider(new AppProvider())); resolver.addProvider(ApkProvider.getAuthority(), prepareProvider(new ApkProvider())); resolver.addProvider(RepoProvider.getAuthority(), prepareProvider(new RepoProvider())); resolver.addProvider(TempAppProvider.getAuthority(), prepareProvider(new TempAppProvider())); resolver.addProvider(TempApkProvider.getAuthority(), prepareProvider(new TempApkProvider())); }
/** * 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 @Before protected void setUp() throws Exception { super.setUp(); mResolver = new MockContentResolver(); final String filenamePrefix = "test."; final 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, new ContextWrapper(targetContextWrapper) { // The FDroidProvider class needs access to an application context in order to initialize // the singleton DBHelper instance. @Override public Context getApplicationContext() { return targetContextWrapper; } }); mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, null); assertNotNull(mProvider); mResolver.addProvider(mProviderAuthority, getProvider()); }
private void ensureCount(int expected, Uri uri) { final MockContentResolver resolver = getMockContentResolver(); Cursor cursor = resolver.query(uri, null, null, null, null); assertNotNull(cursor); assertEquals(expected, cursor.getCount()); cursor.close(); }
public void testEnsureMeasurements() { ensureMeasurementCount(0); final MockContentResolver resolver = getMockContentResolver(); // Note that we insert no fields. These are empty measurements. ContentValues values = new ContentValues(); resolver.insert(getCompleteUri("/fields/testm1/1"), values); ensureMeasurementCount(1); resolver.insert(getCompleteUri("/fields/testm1/1"), values); ensureMeasurementCount(1); resolver.insert(getCompleteUri("/fields/testm1/3"), values); ensureMeasurementCount(2); resolver.insert(getCompleteUri("/fields/testm2/1"), values); ensureMeasurementCount(3); Cursor cursor = resolver.query(getCompleteUri("/measurements/"), null, null, null, null); assertTrue(cursor.moveToFirst()); assertEquals("testm1", cursor.getString(1)); // 'id' is column 0. assertEquals(1, cursor.getInt(2)); assertTrue(cursor.moveToNext()); assertEquals("testm1", cursor.getString(1)); assertEquals(3, cursor.getInt(2)); assertTrue(cursor.moveToNext()); assertEquals("testm2", cursor.getString(1)); assertEquals(1, cursor.getInt(2)); assertFalse(cursor.moveToNext()); cursor.close(); resolver.delete(getCompleteUri("/measurements/"), null, null); }
public ContentResolver getMockResolver() { final MockContentResolver mockContentResolver = new MockContentResolver(mTargetContext); for (String authority : mProviders.keySet()) { mockContentResolver.addProvider(authority, mProviders.get(authority)); } return mockContentResolver; }
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; }
public void testQueryPlanets() { MockContentResolver contentResolver = getMockContentResolver(); Cursor cursor = contentResolver.query(PlanetContract.Planet.contentUri(), PlanetRecord.projection(), null, null, null); DatabaseUtils.dumpCursor(cursor); cursor.moveToFirst(); Assert.assertEquals(8, cursor.getCount()); Planet planet = PlanetRecord.wrapCursor(cursor); assertEquals("Mercury", planet.name()); assertEquals(2.43e6, planet.radiusInMeters()); assertEquals(false, planet.inhabitedByHumans()); cursor.close(); }
@Override public void setUp() throws Exception { super.setUp(); AndroidMockitoInitializer.setupMockito(this, getContext()); DaggerTestInitializer.addMockModuleToObjectGraph(this); resolver = new MockContentResolver(); provider = providerClass.newInstance(); provider.attachInfo(getContext().getApplicationContext(), null); resolver.addProvider(providerAuthority, getProvider()); }
@Override public void setUp() throws Exception { super.setUp(); GuiceInitializer.initialize(this, new AndroidTestCaseInitializationStrategy(this)); resolver = new MockContentResolver(); provider = providerClass.newInstance(); provider.attachInfo(getContext().getApplicationContext(), null); resolver.addProvider(providerAuthority, getProvider()); }
private MockContentResolver utilGetContentResolver() { final MockContentResolver mcr = new MockContentResolver(); mcr.addProvider(AmmoMockSchema01.AUTHORITY, AmmoMockProvider01.getInstance(getContext())); return mcr; }
@Override public ContentResolver getContentResolver() { final ContentProvider provider = AmmoMockProvider01.getInstance(null); // Content resolver final MockContentResolver resolver = new MockContentResolver(); resolver.addProvider(AmmoMockSchema01.AUTHORITY, provider); return resolver; }
@Override protected void setUp() throws Exception { super.setUp(); Context context = new IsolatedContext(new MockContentResolver(), getContext()); this.portfolio = new Portfolio(context); }
@Override protected void setUp() throws Exception { super.setUp(); this.context = new IsolatedContext(new MockContentResolver(), getContext()); sqlStore = StockDataSqlStore.getInstance(this.context); ConnectivityManager connectivity = (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE); this.dataManager = DataManager.getInstance(context); }
@Override protected void setUp() throws Exception { super.setUp(); if (this.infrastructure == null) { this.infrastructure = new Infrastructure(new IsolatedContext(new MockContentResolver(), getContext())); } }
public DbTestUtils(Resources resources) { this.contentResolver = new MockContentResolver(); this.context = new FakeContext(contentResolver, resources); this.sharedPreferences = new FakeSharedPreferences(); this.contentProvider = new FakeContentProvider(context); context.setSharedPreferences(sharedPreferences); }
/** * 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)); }
@Before public void setup() { mContentResolver = new MockContentResolver(); mContentResolver.addProvider(TestContentProvider.AUTHORITY, new TestContentProvider()); }