RuntimeException: Stub! at Uri.parse()

1,703 views
Skip to first unread message

František Hejl

unread,
Aug 29, 2013, 12:08:38 PM8/29/13
to robol...@googlegroups.com
Hi, I have a test class with one empty test method. Running the test fails with: java.lang.RuntimeException: Stub! at android.net.Uri.parse(Uri.java:52)

I'm using Roboelectric 2.1 (jar with dependencies) on Linux and Eclipse. I had the same result with the 2.2 snapshot.

Am I doing something wrong or is this a bug?

Full stack trace:

java.lang.RuntimeException: Stub!
at android.net.Uri.parse(Uri.java:52)
at org.robolectric.shadows.ShadowMediaStore.reset(ShadowMediaStore.java:27)
at org.robolectric.Robolectric.reset(Robolectric.java:1393)
at org.robolectric.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:37)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:217)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Thanks

Frédéric MINATCHY

unread,
Sep 2, 2013, 6:33:27 AM9/2/13
to robol...@googlegroups.com
I have the same issue

Davis Ford

unread,
Sep 24, 2013, 11:53:19 AM9/24/13
to robol...@googlegroups.com
+1 -- I just hit this also.  

I have a test for a very simple ContentProvider that looks a bit like below.  Test was working yesterday, but a clean build seems to have introduced this issue, and it isn't clear to me what changed exactly.  I'm still ramping up on robolectric, and would happily admit I may be doing it wrong, but it seems a few others are having this issue, so I thought I'd throw my test example out there.

@RunWith(RobolectricGradleTestRunner.class)
public class LibraryProviderTest {

  private Activity activity;
  // class under test
  private LibraryProvider provider;
  private ContentResolver resolver;

  private static final String AUTHORITY = "some-string-goes-here";
  private static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);

  private static final List<String> expectedColumns = Arrays.asList(new String[] {"library_version", "library_path", "resource_version", "resource_path"});

  @Before public void setUp() throws Exception {
    // class under test
    provider = new LibraryProvider();
    activity = new Activity();
    resolver = activity.getContentResolver();
    provider.onCreate();
    ShadowContentResolver.registerProvider(AUTHORITY, provider);
  }

  @Test public void testQueryReturnsExpectedColumns() {
    Cursor cursor = resolver.query(CONTENT_URI, null, null, null, null);
    String[] columns = cursor.getColumnNames();
    assertEquals(4, columns.length);
    for (String col : columns) {
      assertTrue(expectedColumns.contains(col));

Davis Ford

unread,
Sep 24, 2013, 11:58:02 AM9/24/13
to robol...@googlegroups.com
Ok, it seems it doesn't like the static final initializer that uses Uri.Parse()

This line:

private static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);

Once I removed that, and just call the API inside the context of the @Test method, everything worked again.  Hope that helps somebody.
Reply all
Reply to author
Forward
0 new messages