11package com .iterable .iterableapi ;
22
3+ import android .app .Application ;
34import android .content .ClipData ;
45import android .content .Context ;
56import android .content .Intent ;
67import android .os .Bundle ;
78import androidx .core .app .RemoteInput ;
9+ import androidx .test .core .app .ApplicationProvider ;
810
911import org .json .JSONObject ;
1012import org .junit .After ;
1113import org .junit .Before ;
1214import org .junit .Test ;
1315import org .mockito .ArgumentCaptor ;
14- import org .robolectric .RuntimeEnvironment ;
1516
1617import java .util .concurrent .TimeUnit ;
1718
@@ -63,11 +64,12 @@ public void testPushOpenWithNonInitializedSDK() throws Exception {
6364 intent .putExtra (IterableConstants .ITERABLE_DATA_KEY , IterableTestUtils .getResourceString ("push_payload_silent_action.json" ));
6465
6566 // This must not crash
66- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
67+ iterablePushActionReceiver .onReceive (ApplicationProvider . getApplicationContext () , intent );
6768 }
6869
6970 @ Test
7071 public void testTrackPushOpenWithCustomAction () throws Exception {
72+ Application application = ApplicationProvider .getApplicationContext ();
7173 final JSONObject responseData = new JSONObject ("{\" key\" :\" value\" }" );
7274 stubAnyRequestReturningStatusCode (server , 200 , responseData );
7375
@@ -76,15 +78,15 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
7678 intent .putExtra (IterableConstants .ITERABLE_DATA_ACTION_IDENTIFIER , IterableConstants .ITERABLE_ACTION_DEFAULT );
7779 intent .putExtra (IterableConstants .ITERABLE_DATA_KEY , IterableTestUtils .getResourceString ("push_payload_custom_action.json" ));
7880
79- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
81+ iterablePushActionReceiver .onReceive (application , intent );
8082
8183 // Verify that IterableActionRunner was called with the proper action
8284 ArgumentCaptor <IterableAction > capturedAction = ArgumentCaptor .forClass (IterableAction .class );
8385 verify (actionRunnerMock ).executeAction (any (Context .class ), capturedAction .capture (), eq (IterableActionSource .PUSH ));
8486 assertEquals ("customAction" , capturedAction .getValue ().getType ());
8587
8688 // Verify that the main app activity was launched
87- Intent activityIntent = shadowOf (RuntimeEnvironment . application ).peekNextStartedActivity ();
89+ Intent activityIntent = shadowOf (application ).peekNextStartedActivity ();
8890 assertNotNull (activityIntent );
8991 assertEquals (Intent .ACTION_MAIN , activityIntent .getAction ());
9092
@@ -102,16 +104,17 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
102104
103105 @ Test
104106 public void testPushActionWithSilentAction () throws Exception {
107+ Application application = ApplicationProvider .getApplicationContext ();
105108 stubAnyRequestReturningStatusCode (server , 200 , "{}" );
106109 IterablePushActionReceiver iterablePushActionReceiver = new IterablePushActionReceiver ();
107110 Intent intent = new Intent (IterableConstants .ACTION_PUSH_ACTION );
108111 intent .putExtra (IterableConstants .ITERABLE_DATA_ACTION_IDENTIFIER , "silentButton" );
109112 intent .putExtra (IterableConstants .ITERABLE_DATA_KEY , IterableTestUtils .getResourceString ("push_payload_silent_action.json" ));
110113
111- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
114+ iterablePushActionReceiver .onReceive (application , intent );
112115
113116 // Verify that the main app activity was NOT launched
114- Intent activityIntent = shadowOf (RuntimeEnvironment . application ).peekNextStartedActivity ();
117+ Intent activityIntent = shadowOf (application ).peekNextStartedActivity ();
115118 assertNull (activityIntent );
116119 }
117120
@@ -129,7 +132,7 @@ public void testPushActionWithTextInput() throws Exception {
129132 clipDataIntent .putExtra (RemoteInput .EXTRA_RESULTS_DATA , resultsBundle );
130133 intent .setClipData (ClipData .newIntent (RESULTS_CLIP_LABEL , clipDataIntent ));
131134
132- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
135+ iterablePushActionReceiver .onReceive (ApplicationProvider . getApplicationContext () , intent );
133136
134137 // Verify that IterableActionRunner was called with the proper action
135138 ArgumentCaptor <IterableAction > actionCaptor = ArgumentCaptor .forClass (IterableAction .class );
@@ -147,7 +150,7 @@ public void testLegacyDeepLinkPayload() throws Exception {
147150 intent .putExtras (IterableTestUtils .getBundleFromJsonResource ("push_payload_legacy_deep_link.json" ));
148151 intent .putExtra (IterableConstants .ITERABLE_DATA_ACTION_IDENTIFIER , IterableConstants .ITERABLE_ACTION_DEFAULT );
149152
150- iterablePushActionReceiver .onReceive (RuntimeEnvironment . application , intent );
153+ iterablePushActionReceiver .onReceive (ApplicationProvider . getApplicationContext () , intent );
151154
152155 // Verify that IterableActionRunner was called with openUrl action
153156 ArgumentCaptor <IterableAction > capturedAction = ArgumentCaptor .forClass (IterableAction .class );
0 commit comments