Java 类android.test.mock.MockContentResolver 实例源码

项目:GitHub    文件:PickerPresenterTest.java   
@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);
        }
    });
}
项目:boxing    文件:PickerPresenterTest.java   
@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);
        }
    });
}
项目:skeletoid    文件:ShareLogFilesUtilsUnitTests.java   
@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());
    }
项目:mobile-messaging-sdk-android    文件:GeoEnabledConsistencyReceiverTest.java   
@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);
}
项目:mytracks    文件:SearchEngineTest.java   
@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);
}
项目:mytracks    文件:MyTracksProviderUtilsImplTest.java   
@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);
}
项目:AppHub    文件:ProviderTestCase2MockContext.java   
/**
 * 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());
}
项目:mc_backup    文件:DBProviderTestCase.java   
@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());
}
项目:f-droid    文件:ProviderTestCase2MockContext.java   
/**
 * 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());
}
项目:vinyl    文件:PlanetContentProviderTest.java   
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();
}
项目:reark    文件:GitHubRepositoryStoreTest.java   
@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();
}
项目:reark    文件:GitHubRepositoryStoreCoreTest.java   
@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();
}
项目:arca-android    文件:SimpleOperationTest.java   
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();
}
项目:reark    文件:GitHubRepositoryStoreTest.java   
@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();
}
项目:reark    文件:GitHubRepositoryStoreCoreTest.java   
@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();
}
项目:altidroid    文件:SkydiveControllerTest.java   
@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>();
}
项目:StockAnalyze    文件:XmlPullParserTest.java   
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());
}
项目:Impala    文件:LoginPresenterShould.java   
@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);
}
项目:mytracks    文件:TrackDataHubTest.java   
@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);
}
项目:mytracks    文件:FileTrackExporterTest.java   
@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);
}
项目:fdroid    文件:MultiRepoUpdaterTest.java   
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()));
}
项目:fdroid    文件:ProviderTestCase2MockContext.java   
/**
 * 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());
}
项目:AppHub    文件:MultiRepoUpdaterTest.java   
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()));
}
项目:mc_backup    文件:TestHealthReportProvider.java   
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();
}
项目:mc_backup    文件:TestHealthReportProvider.java   
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);
}
项目:tray    文件:TrayProviderTestCase.java   
public ContentResolver getMockResolver() {
    final MockContentResolver mockContentResolver = new MockContentResolver(mTargetContext);
    for (String authority : mProviders.keySet()) {
        mockContentResolver.addProvider(authority, mProviders.get(authority));
    }
    return mockContentResolver;
}
项目:SMP    文件:RowsTest.java   
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;
}
项目:vinyl    文件:PlanetContentProviderTest.java   
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();
}
项目:injected-test-runner    文件:InjectedContentProviderTestCase.java   
@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());
}
项目:injected-test-runner    文件:InjectedContentProviderTestCase.java   
@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());
}
项目:ammo-core    文件:JsonSerializerTest.java   
private MockContentResolver utilGetContentResolver()
{
    final MockContentResolver mcr = new MockContentResolver();
    mcr.addProvider(AmmoMockSchema01.AUTHORITY,
                    AmmoMockProvider01.getInstance(getContext()));

    return mcr;
}
项目:ammo-core    文件:MockContextRenaming.java   
@Override
public ContentResolver getContentResolver() {
    final ContentProvider provider = AmmoMockProvider01.getInstance(null);

    // Content resolver
    final MockContentResolver resolver = new MockContentResolver();
    resolver.addProvider(AmmoMockSchema01.AUTHORITY, provider);
    return resolver;
}
项目:StockAnalyze    文件:PortfolioTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();

    Context context = new IsolatedContext(new MockContentResolver(), getContext());
    this.portfolio = new Portfolio(context);
}
项目:StockAnalyze    文件:DataManagerTest.java   
@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);
}
项目:StockAnalyze    文件:ChartinfrastructureTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    if (this.infrastructure == null) {
        this.infrastructure = new Infrastructure(new IsolatedContext(new MockContentResolver(), getContext()));
    }
}
项目:StockAnalyze    文件:StockInfrastructureTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    if (this.infrastructure == null) {
        this.infrastructure = new Infrastructure(new IsolatedContext(new MockContentResolver(), getContext()));
    }
}
项目:StockAnalyze    文件:ChartInfrastructureTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    if (this.infrastructure == null) {
        this.infrastructure = new Infrastructure(new IsolatedContext(new MockContentResolver(), getContext()));
    }
}
项目:Calendar_lunar    文件:DbTestUtils.java   
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);
}
项目:mytracks    文件:MyTracksProviderUtilsImplTest.java   
/**
 * 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));
}
项目:RxCursorLoader    文件:RxCursorLoaderInstrumentedTest.java   
@Before
public void setup() {
    mContentResolver = new MockContentResolver();
    mContentResolver.addProvider(TestContentProvider.AUTHORITY, new TestContentProvider());
}