Created
August 2, 2013 12:00
-
-
Save anonymous/6139359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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