use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method shouldSendBroadcastsWithDataScheme.
@Test
public void shouldSendBroadcastsWithDataScheme() throws Exception {
LocalBroadcastManager instance = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
final boolean[] called = new boolean[1];
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
called[0] = true;
}
};
IntentFilter intentFilter = new IntentFilter("com.foo");
intentFilter.addDataScheme("http");
instance.registerReceiver(receiver, intentFilter);
instance.sendBroadcast(new Intent("com.foo", Uri.parse("ftp://robolectric.org")));
assertFalse(called[0]);
instance.sendBroadcast(new Intent("com.foo", Uri.parse("http://robolectric.org")));
assertTrue(called[0]);
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method shouldUnregisterReceiver.
@Test
public void shouldUnregisterReceiver() throws Exception {
LocalBroadcastManager instance = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
final boolean[] called = new boolean[1];
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
called[0] = true;
}
};
instance.registerReceiver(receiver, new IntentFilter("com.foo"));
instance.unregisterReceiver(receiver);
instance.sendBroadcast(new Intent("com.foo"));
assertFalse(called[0]);
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method testGetSentBroadcastIntents.
@Test
public void testGetSentBroadcastIntents() throws Exception {
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
ShadowLocalBroadcastManager shadowLocalBroadcastManager = shadowOf(broadcastManager);
assertEquals(0, shadowLocalBroadcastManager.getSentBroadcastIntents().size());
Intent broadcastIntent = new Intent("foo");
broadcastManager.sendBroadcast(broadcastIntent);
assertEquals(1, shadowLocalBroadcastManager.getSentBroadcastIntents().size());
assertEquals(broadcastIntent, shadowLocalBroadcastManager.getSentBroadcastIntents().get(0));
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method testGetBroadcastIntents.
@Test
public void testGetBroadcastIntents() throws Exception {
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
broadcastManager.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
transcript.add("got intent " + intent.getAction());
}
}, IntentFilter.create("foo", "application/blatz"));
Intent intent1 = new Intent("foo").setType("application/blatz");
broadcastManager.sendBroadcast(intent1);
Intent intent2 = new Intent("bar").setType("application/blatz");
broadcastManager.sendBroadcast(intent2);
assertThat(transcript).containsExactly("got intent foo");
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method testGetRegisteredBroadcastReceivers.
@Test
public void testGetRegisteredBroadcastReceivers() throws Exception {
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
ShadowLocalBroadcastManager shadowLocalBroadcastManager = shadowOf(broadcastManager);
assertEquals(0, shadowLocalBroadcastManager.getRegisteredBroadcastReceivers().size());
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
}
};
IntentFilter filter = new IntentFilter("foo");
broadcastManager.registerReceiver(receiver, filter);
assertEquals(1, shadowLocalBroadcastManager.getRegisteredBroadcastReceivers().size());
ShadowLocalBroadcastManager.Wrapper capturedWrapper = shadowLocalBroadcastManager.getRegisteredBroadcastReceivers().get(0);
assertEquals(receiver, capturedWrapper.broadcastReceiver);
assertEquals(filter, capturedWrapper.intentFilter);
broadcastManager.unregisterReceiver(receiver);
assertEquals(0, shadowLocalBroadcastManager.getRegisteredBroadcastReceivers().size());
}
Aggregations