use of org.robolectric.android.TestBroadcastReceiver in project robolectric by robolectric.
the class ShadowApplicationTest method canFindAllReceiversForAnIntent.
@Test
public void canFindAllReceiversForAnIntent() throws Exception {
BroadcastReceiver expectedReceiver = new TestBroadcastReceiver();
ShadowApplication shadowApplication = shadowOf(RuntimeEnvironment.application);
assertFalse(shadowApplication.hasReceiverForIntent(new Intent("Foo")));
RuntimeEnvironment.application.registerReceiver(expectedReceiver, new IntentFilter("Foo"));
RuntimeEnvironment.application.registerReceiver(expectedReceiver, new IntentFilter("Foo"));
assertTrue(shadowApplication.getReceiversForIntent(new Intent("Foo")).size() == 2);
}
use of org.robolectric.android.TestBroadcastReceiver in project robolectric by robolectric.
the class ShadowApplicationTest method shouldNotThrowIfDoesNotContainsRegisteredReceiverOfAction.
@Test
public void shouldNotThrowIfDoesNotContainsRegisteredReceiverOfAction() {
Activity activity = Robolectric.setupActivity(Activity.class);
activity.registerReceiver(new TestBroadcastReceiver(), new IntentFilter("Foo"));
shadowOf(RuntimeEnvironment.application).assertNoBroadcastListenersOfActionRegistered(activity, "Bar");
}
use of org.robolectric.android.TestBroadcastReceiver in project robolectric by robolectric.
the class ShadowApplicationTest method shouldThrowIfContainsRegisteredReceiverOfAction.
@Test(expected = IllegalStateException.class)
public void shouldThrowIfContainsRegisteredReceiverOfAction() {
Activity activity = Robolectric.setupActivity(Activity.class);
activity.registerReceiver(new TestBroadcastReceiver(), new IntentFilter("Foo"));
shadowOf(RuntimeEnvironment.application).assertNoBroadcastListenersOfActionRegistered(activity, "Foo");
}
use of org.robolectric.android.TestBroadcastReceiver in project robolectric by robolectric.
the class ShadowApplicationTest method canAnswerIfReceiverIsRegisteredForIntent.
@Test
public void canAnswerIfReceiverIsRegisteredForIntent() throws Exception {
BroadcastReceiver expectedReceiver = new TestBroadcastReceiver();
ShadowApplication shadowApplication = shadowOf(RuntimeEnvironment.application);
assertFalse(shadowApplication.hasReceiverForIntent(new Intent("Foo")));
RuntimeEnvironment.application.registerReceiver(expectedReceiver, new IntentFilter("Foo"));
assertTrue(shadowApplication.hasReceiverForIntent(new Intent("Foo")));
}
Aggregations