Skip to content

Instantly share code, notes, and snippets.

Created August 2, 2013 12:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6139359 to your computer and use it in GitHub Desktop.
Save anonymous/6139359 to your computer and use it in GitHub Desktop.
@RunWith(RobolectricTestRunner.class)
public class MyCustomContentProviderTest {
private ContentResolver mContentResolver;
private ShadowContentResolver mShadowContentResolver;
private ShadowContentProvider mShadowContentProvider;
@Before
public void setUp() throws Exception {
mProvider = new MyCustomContentProvider();
mContentResolver = Robolectric.application.getContentResolver();
mShadowContentResolver = shadowOf(mContentResolver);
mProvider.onCreate();
ShadowContentResolver.registerProvider(MyCustomContentProvider.AUTHORITY, mProvider);
}
@Test
public void testInsert() {
// insert 1 item
ContentValues testRow = new ContentValues();
testRow.put(_ID, 1);
testRow.put(NAME, "name");
contentResolver.insert(CONTENT_URI, testRow);
// test that the item was inserted
assertThat(mShadowContentResolver.query(MyCustomContentProvider.CONTENT_URI, null, null, null, null), is(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment