|
16 | 16 | import java.util.UUID; |
17 | 17 | import java.util.concurrent.TimeUnit; |
18 | 18 |
|
| 19 | +import okhttp3.HttpUrl; |
19 | 20 | import okhttp3.mockwebserver.MockResponse; |
20 | 21 | import okhttp3.mockwebserver.MockWebServer; |
21 | 22 | import okhttp3.mockwebserver.RecordedRequest; |
|
25 | 26 | import static junit.framework.Assert.assertNull; |
26 | 27 | import static junit.framework.Assert.assertTrue; |
27 | 28 | import static org.mockito.ArgumentMatchers.any; |
| 29 | +import static org.mockito.ArgumentMatchers.eq; |
28 | 30 | import static org.mockito.Mockito.doReturn; |
29 | 31 | import static org.mockito.Mockito.mock; |
30 | 32 | import static org.mockito.Mockito.never; |
@@ -310,4 +312,28 @@ public void testUpdateUserWithUserId() throws Exception { |
310 | 312 | assertEquals("value", requestJson.getJSONObject(IterableConstants.KEY_DATA_FIELDS).getString("key")); |
311 | 313 | } |
312 | 314 |
|
| 315 | + @Test |
| 316 | + public void testGetInAppMessages() throws Exception { |
| 317 | + server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); |
| 318 | + |
| 319 | + IterableHelper.IterableActionHandler handlerMock = mock(IterableHelper.IterableActionHandler.class); |
| 320 | + |
| 321 | + IterableApi.initialize(RuntimeEnvironment.application, "apiKey", new IterableConfig.Builder().setAutoPushRegistration(false).build()); |
| 322 | + IterableApi.getInstance().setEmail("test@email.com"); |
| 323 | + IterableApi.getInstance().getInAppMessages(10, handlerMock); |
| 324 | + Thread.sleep(1000); // Since the network request is queued from a background thread, we need to wait |
| 325 | + Robolectric.flushBackgroundThreadScheduler(); |
| 326 | + |
| 327 | + verify(handlerMock).execute(eq("{}")); |
| 328 | + |
| 329 | + RecordedRequest getInAppMessagesRequest = server.takeRequest(1, TimeUnit.SECONDS); |
| 330 | + assertNotNull(getInAppMessagesRequest); |
| 331 | + Uri uri = Uri.parse(getInAppMessagesRequest.getRequestUrl().toString()); |
| 332 | + assertEquals("/" + IterableConstants.ENDPOINT_GET_INAPP_MESSAGES, uri.getPath()); |
| 333 | + assertEquals("10", uri.getQueryParameter(IterableConstants.ITERABLE_IN_APP_COUNT)); |
| 334 | + assertEquals(IterableConstants.ITBL_PLATFORM_ANDROID, uri.getQueryParameter(IterableConstants.KEY_PLATFORM)); |
| 335 | + assertEquals(IterableConstants.ITBL_KEY_SDK_VERSION_NUMBER, uri.getQueryParameter(IterableConstants.ITBL_KEY_SDK_VERSION)); |
| 336 | + assertEquals(RuntimeEnvironment.application.getPackageName(), uri.getQueryParameter(IterableConstants.KEY_PACKAGE_NAME)); |
| 337 | + } |
| 338 | + |
313 | 339 | } |
0 commit comments