is a LocalBroadcastManager possible in Robolectric?

500 views
Skip to first unread message

Eric Harlow

unread,
Mar 5, 2013, 5:18:56 PM3/5/13
to robol...@googlegroups.com
Hello I am a complete beginner with Robolectric. 
Does anyone have some experience with LocalBroadcastManager in Robolectric? is it even possible?

my application code looks like this:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        Dispatcher instance = Dispatcher.getInstance();
        instance.setContext(getApplicationContext());
    IntentFilter filter = Dispatcher.getIntentFilter();
        LocalBroadcastManager messagePassingSystem = LocalBroadcastManager.getInstance(getApplicationContext());
    messagePassingSystem.registerReceiver(instance, filter);
     }
}

I know that getApplicationContext() is returning an object, and LocalBroadcastManager is returning null. 
How can I get a LocalBroadcastManger in robolectric?


my failure trace:

java.lang.NullPointerException
at com.myCompany.MyApplication.onCreate(MyApplication.java:94)
at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:234)
at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:177)
at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:157)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
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)

Phil Goodwin

unread,
Mar 12, 2013, 6:42:08 PM3/12/13
to robol...@googlegroups.com
Which version of Robolectric are you using? The internals of RobolectricTestRunner have been changing a lot recently, so you may find that your code just works with the latest version. 

The stack trace shows that the application's onCreate() is being called from setupApplicationState() which is very early in the test runner setup. It's possible that it's happening before the shadow classes have been registered. If that's what's happening then it's a bug and we should fix it. Please keep us posted.

Thanks,

Phil


--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages