This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathActivityWithReceiverTest.java
More file actions
80 lines (60 loc) · 2.23 KB
/
Copy pathActivityWithReceiverTest.java
File metadata and controls
80 lines (60 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.androidannotations.test15.receiver;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import android.content.Intent;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.support.v4.content.LocalBroadcastManager;
@RunWith(RobolectricTestRunner.class)
public class ActivityWithReceiverTest {
private ActivityWithReceiver_ activity;
@Before
public void setup() {
activity = Robolectric.buildActivity(ActivityWithReceiver_.class)
.create().start().resume().get();
}
@Test
public void onWifiStateChangedTest() {
Intent intent = new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION);
activity.sendBroadcast(intent);
assertTrue(activity.wifiChangeIntentReceived);
}
@Test
public void onLocalWifiStateChangedTest() {
Intent intent = new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION);
LocalBroadcastManager.getInstance(Robolectric.application)
.sendBroadcast(intent);
assertTrue(activity.localWifiChangeIntentReceived);
}
// @Test
// due to a bug in robolectric this test does not yet work
// see https://github.com/robolectric/robolectric/issues/1244
public void onDataShemeHttpTest() {
Intent intentFtp = new Intent("CUSTOM_HTTP_ACTION");
intentFtp.setData(Uri.parse("ftp://androidannotations.org"));
activity.sendBroadcast(intentFtp);
assertFalse(activity.dataSchemeHttpIntentReceived);
Intent intentHttp = new Intent("CUSTOM_HTTP_ACTION");
intentHttp.setData(Uri.parse("http://androidannotations.org"));
activity.sendBroadcast(intentHttp);
assertTrue(activity.dataSchemeHttpIntentReceived);
}
@Test
public void onBroadcastWithTwoActionsTest() {
Intent intent1 = new Intent("org.androidannotations.ACTION_1");
Intent intent2 = new Intent("org.androidannotations.ACTION_2");
assertFalse(activity.action1Fired);
assertFalse(activity.action2Fired);
activity.sendBroadcast(intent1);
assertTrue(activity.action1Fired);
assertFalse(activity.action2Fired);
activity.sendBroadcast(intent2);
assertTrue(activity.action1Fired);
assertTrue(activity.action2Fired);
}
}