|
15 | 15 |
|
16 | 16 | import java.io.IOException; |
17 | 17 | import java.util.List; |
| 18 | +import java.util.concurrent.CountDownLatch; |
| 19 | +import java.util.concurrent.TimeUnit; |
18 | 20 |
|
19 | 21 | import okhttp3.mockwebserver.MockResponse; |
20 | 22 | import okhttp3.mockwebserver.MockWebServer; |
@@ -83,28 +85,32 @@ public void testInboxMessageOrdering() throws Exception { |
83 | 85 | } |
84 | 86 |
|
85 | 87 | @Test |
86 | | - public void testRemoveMessage() throws Exception { |
| 88 | + public void testRemoveMessageSuccessCallbackOnSuccessfulResponse() throws Exception { |
| 89 | + final CountDownLatch signal = new CountDownLatch(1); |
87 | 90 | dispatcher.enqueueResponse("/inApp/getMessages", new MockResponse().setBody(IterableTestUtils.getResourceString("inapp_payload_inbox_multiple.json"))); |
88 | 91 | final IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager(); |
89 | 92 | inAppManager.syncInApp(); |
90 | 93 | shadowOf(getMainLooper()).idle(); |
91 | 94 | List<IterableInAppMessage> inboxMessages = inAppManager.getInboxMessages(); |
92 | 95 | assertEquals(2, inboxMessages.size()); |
93 | 96 | assertEquals(1, inAppManager.getUnreadInboxMessagesCount()); |
| 97 | + |
| 98 | + final JSONObject responseData = new JSONObject("{\"key\":\"value\"}"); |
| 99 | + dispatcher.enqueueResponse("/events/inAppConsume", new MockResponse().setResponseCode(200).setBody(responseData.toString())); |
| 100 | + |
94 | 101 | inAppManager.removeMessage(inboxMessages.get(0), new IterableHelper.SuccessHandler() { |
95 | 102 | @Override |
96 | 103 | public void onSuccess(@NonNull JSONObject data) { |
97 | | - assertEquals(1, inAppManager.getInboxMessages().size()); |
98 | | - assertEquals("message2", inAppManager.getInboxMessages().get(0).getMessageId()); |
| 104 | + signal.countDown(); |
99 | 105 | } |
100 | 106 | }, new IterableHelper.FailureHandler() { |
101 | 107 | @Override |
102 | 108 | public void onFailure(@NonNull String reason, @Nullable JSONObject data) { |
103 | 109 | assertFalse(true); |
104 | 110 | } |
105 | 111 | }); |
106 | | - assertEquals(1, inAppManager.getInboxMessages().size()); |
107 | | - assertEquals("message2", inAppManager.getInboxMessages().get(0).getMessageId()); |
| 112 | + shadowOf(getMainLooper()).idle(); |
| 113 | + assertTrue("Message remove success callback called", signal.await(1, TimeUnit.SECONDS)); |
108 | 114 | } |
109 | 115 |
|
110 | 116 | @Test |
|
0 commit comments