|
13 | 13 | import org.junit.Before;
|
14 | 14 | import org.junit.Test;
|
15 | 15 | import org.mockito.ArgumentCaptor;
|
| 16 | +import org.mockito.Mockito; |
16 | 17 | import org.powermock.api.mockito.PowerMockito;
|
17 | 18 | import org.powermock.core.MockRepository;
|
18 | 19 | import org.powermock.core.classloader.annotations.PrepareForTest;
|
19 | 20 | import org.robolectric.Robolectric;
|
20 | 21 | import org.robolectric.RuntimeEnvironment;
|
21 | 22 | import org.robolectric.android.controller.ServiceController;
|
22 | 23 |
|
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.Map; |
| 26 | + |
23 | 27 | import okhttp3.mockwebserver.MockWebServer;
|
24 | 28 |
|
25 | 29 | import static com.iterable.iterableapi.unit.IterableTestUtils.bundleToMap;
|
26 | 30 | import static com.iterable.iterableapi.unit.IterableTestUtils.getMapFromJsonResource;
|
| 31 | +import static junit.framework.Assert.assertEquals; |
27 | 32 | import static junit.framework.Assert.assertTrue;
|
| 33 | +import static org.mockito.ArgumentMatchers.any; |
28 | 34 | import static org.mockito.ArgumentMatchers.eq;
|
29 | 35 | import static org.mockito.Mockito.mock;
|
30 | 36 | import static org.mockito.Mockito.spy;
|
@@ -72,15 +78,18 @@ public void tearDown() throws Exception {
|
72 | 78 | @Test
|
73 | 79 | public void testOnMessageReceived() throws Exception {
|
74 | 80 | PowerMockito.mockStatic(IterableNotificationBuilder.class);
|
| 81 | + Mockito.when(IterableNotificationBuilder.isIterablePush(any(Bundle.class))).thenCallRealMethod(); |
75 | 82 |
|
76 | 83 | RemoteMessage. Builder builder = new RemoteMessage. Builder( "[email protected]");
|
77 |
| - builder.setData(getMapFromJsonResource("push_payload_custom_action.json")); |
| 84 | + builder.addData(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_custom_action.json")); |
78 | 85 | controller.get().onMessageReceived(builder.build());
|
79 | 86 |
|
80 | 87 | PowerMockito.verifyStatic(IterableNotificationBuilder.class);
|
81 | 88 | ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
|
82 | 89 | IterableNotificationBuilder.createNotification(eq(RuntimeEnvironment.application), bundleCaptor.capture());
|
83 |
| - assertTrue(bundleToMap(bundleCaptor.getValue()).equals(getMapFromJsonResource("push_payload_custom_action.json"))); |
| 90 | + Map<String, String> expectedPayload = new HashMap<>(); |
| 91 | + expectedPayload.put(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_custom_action.json")); |
| 92 | + assertEquals(expectedPayload, bundleToMap(bundleCaptor.getValue())); |
84 | 93 | }
|
85 | 94 |
|
86 | 95 | }
|
0 commit comments