Search in sources :

Example 1 with TestBroadcastReceiver

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);
}
Also used : IntentFilter(android.content.IntentFilter) TestBroadcastReceiver(org.robolectric.android.TestBroadcastReceiver) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) TestBroadcastReceiver(org.robolectric.android.TestBroadcastReceiver) Test(org.junit.Test)

Example 2 with TestBroadcastReceiver

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");
}
Also used : IntentFilter(android.content.IntentFilter) TestBroadcastReceiver(org.robolectric.android.TestBroadcastReceiver) Activity(android.app.Activity) Test(org.junit.Test)

Example 3 with TestBroadcastReceiver

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");
}
Also used : IntentFilter(android.content.IntentFilter) TestBroadcastReceiver(org.robolectric.android.TestBroadcastReceiver) Activity(android.app.Activity) Test(org.junit.Test)

Example 4 with TestBroadcastReceiver

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")));
}
Also used : IntentFilter(android.content.IntentFilter) TestBroadcastReceiver(org.robolectric.android.TestBroadcastReceiver) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) TestBroadcastReceiver(org.robolectric.android.TestBroadcastReceiver) Test(org.junit.Test)

Aggregations

IntentFilter (android.content.IntentFilter)4 Test (org.junit.Test)4 TestBroadcastReceiver (org.robolectric.android.TestBroadcastReceiver)4 Activity (android.app.Activity)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Intent (android.content.Intent)2