Java Code Examples for android.test.mock.MockContentResolver#addProvider()

The following examples show how to use android.test.mock.MockContentResolver#addProvider() . 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 vote down vote up
@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: SearchEngineTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: MyTracksProviderUtilsImplTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: TrayProviderTestCase.java    From tray with Apache License 2.0 6 votes vote down vote up
public ContentResolver getMockResolver() {
    final MockContentResolver mockContentResolver = new MockContentResolver(mTargetContext);
    for (String authority : mProviders.keySet()) {
        mockContentResolver.addProvider(authority, mProviders.get(authority));
    }
    return mockContentResolver;
}
 
Example 5
Source File: FileTrackExporterTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: RowsTest.java    From SMP with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: ContactsManagerTest.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: RowsTest.java    From SMP with GNU General Public License v3.0 5 votes vote down vote up
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: ProviderTestRule.java    From android-test with Apache License 2.0 4 votes vote down vote up
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 10
Source File: SupportRequestDispatcherTest.java    From arca-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 11
Source File: ModernRequestDispatcherTest.java    From arca-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 12
Source File: SimpleOperationTest.java    From arca-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ContentResolver getContentResolver() {
    final MockContentResolver resolver = new MockContentResolver();
    resolver.addProvider(AUTHORITY, mProvider);
    return resolver;
}