1
1
package com .iterable .iterableapi ;
2
2
3
+ import android .app .Application ;
3
4
import android .content .ClipData ;
4
5
import android .content .Context ;
5
6
import android .content .Intent ;
6
7
import android .os .Bundle ;
7
8
import androidx .core .app .RemoteInput ;
9
+ import androidx .test .core .app .ApplicationProvider ;
8
10
9
11
import org .json .JSONObject ;
10
12
import org .junit .After ;
11
13
import org .junit .Before ;
12
14
import org .junit .Test ;
13
15
import org .mockito .ArgumentCaptor ;
14
- import org .robolectric .RuntimeEnvironment ;
15
16
16
17
import java .util .concurrent .TimeUnit ;
17
18
@@ -63,11 +64,12 @@ public void testPushOpenWithNonInitializedSDK() throws Exception {
63
64
intent .putExtra (IterableConstants .ITERABLE_DATA_KEY , IterableTestUtils .getResourceString ("push_payload_silent_action.json" ));
64
65
65
66
// This must not crash
66
- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
67
+ iterablePushActionReceiver .onReceive (ApplicationProvider . getApplicationContext () , intent );
67
68
}
68
69
69
70
@ Test
70
71
public void testTrackPushOpenWithCustomAction () throws Exception {
72
+ Application application = ApplicationProvider .getApplicationContext ();
71
73
final JSONObject responseData = new JSONObject ("{\" key\" :\" value\" }" );
72
74
stubAnyRequestReturningStatusCode (server , 200 , responseData );
73
75
@@ -76,15 +78,15 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
76
78
intent .putExtra (IterableConstants .ITERABLE_DATA_ACTION_IDENTIFIER , IterableConstants .ITERABLE_ACTION_DEFAULT );
77
79
intent .putExtra (IterableConstants .ITERABLE_DATA_KEY , IterableTestUtils .getResourceString ("push_payload_custom_action.json" ));
78
80
79
- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
81
+ iterablePushActionReceiver .onReceive (application , intent );
80
82
81
83
// Verify that IterableActionRunner was called with the proper action
82
84
ArgumentCaptor <IterableAction > capturedAction = ArgumentCaptor .forClass (IterableAction .class );
83
85
verify (actionRunnerMock ).executeAction (any (Context .class ), capturedAction .capture (), eq (IterableActionSource .PUSH ));
84
86
assertEquals ("customAction" , capturedAction .getValue ().getType ());
85
87
86
88
// Verify that the main app activity was launched
87
- Intent activityIntent = shadowOf (RuntimeEnvironment . application ).peekNextStartedActivity ();
89
+ Intent activityIntent = shadowOf (application ).peekNextStartedActivity ();
88
90
assertNotNull (activityIntent );
89
91
assertEquals (Intent .ACTION_MAIN , activityIntent .getAction ());
90
92
@@ -102,16 +104,17 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
102
104
103
105
@ Test
104
106
public void testPushActionWithSilentAction () throws Exception {
107
+ Application application = ApplicationProvider .getApplicationContext ();
105
108
stubAnyRequestReturningStatusCode (server , 200 , "{}" );
106
109
IterablePushActionReceiver iterablePushActionReceiver = new IterablePushActionReceiver ();
107
110
Intent intent = new Intent (IterableConstants .ACTION_PUSH_ACTION );
108
111
intent .putExtra (IterableConstants .ITERABLE_DATA_ACTION_IDENTIFIER , "silentButton" );
109
112
intent .putExtra (IterableConstants .ITERABLE_DATA_KEY , IterableTestUtils .getResourceString ("push_payload_silent_action.json" ));
110
113
111
- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
114
+ iterablePushActionReceiver .onReceive (application , intent );
112
115
113
116
// Verify that the main app activity was NOT launched
114
- Intent activityIntent = shadowOf (RuntimeEnvironment . application ).peekNextStartedActivity ();
117
+ Intent activityIntent = shadowOf (application ).peekNextStartedActivity ();
115
118
assertNull (activityIntent );
116
119
}
117
120
@@ -129,7 +132,7 @@ public void testPushActionWithTextInput() throws Exception {
129
132
clipDataIntent .putExtra (RemoteInput .EXTRA_RESULTS_DATA , resultsBundle );
130
133
intent .setClipData (ClipData .newIntent (RESULTS_CLIP_LABEL , clipDataIntent ));
131
134
132
- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
135
+ iterablePushActionReceiver .onReceive (ApplicationProvider . getApplicationContext () , intent );
133
136
134
137
// Verify that IterableActionRunner was called with the proper action
135
138
ArgumentCaptor <IterableAction > actionCaptor = ArgumentCaptor .forClass (IterableAction .class );
@@ -147,7 +150,7 @@ public void testLegacyDeepLinkPayload() throws Exception {
147
150
intent .putExtras (IterableTestUtils .getBundleFromJsonResource ("push_payload_legacy_deep_link.json" ));
148
151
intent .putExtra (IterableConstants .ITERABLE_DATA_ACTION_IDENTIFIER , IterableConstants .ITERABLE_ACTION_DEFAULT );
149
152
150
- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
153
+ iterablePushActionReceiver .onReceive (ApplicationProvider . getApplicationContext () , intent );
151
154
152
155
// Verify that IterableActionRunner was called with openUrl action
153
156
ArgumentCaptor <IterableAction > capturedAction = ArgumentCaptor .forClass (IterableAction .class );
0 commit comments