Skip to content

Commit 088418a

Browse files
author
“Akshay
committed
Fixing and adding test method
1 parent 91ff140 commit 088418a

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

iterableapi/src/test/java/com/iterable/iterableapi/IterableInboxTest.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import java.io.IOException;
1717
import java.util.List;
18+
import java.util.concurrent.CountDownLatch;
19+
import java.util.concurrent.TimeUnit;
1820

1921
import okhttp3.mockwebserver.MockResponse;
2022
import okhttp3.mockwebserver.MockWebServer;
@@ -83,28 +85,61 @@ public void testInboxMessageOrdering() throws Exception {
8385
}
8486

8587
@Test
86-
public void testRemoveMessage() throws Exception {
88+
public void testRemoveMessageSuccessCallbackOnSuccessfulResponse() throws Exception {
89+
final CountDownLatch signal = new CountDownLatch(1);
8790
dispatcher.enqueueResponse("/inApp/getMessages", new MockResponse().setBody(IterableTestUtils.getResourceString("inapp_payload_inbox_multiple.json")));
8891
final IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager();
8992
inAppManager.syncInApp();
9093
shadowOf(getMainLooper()).idle();
9194
List<IterableInAppMessage> inboxMessages = inAppManager.getInboxMessages();
9295
assertEquals(2, inboxMessages.size());
9396
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+
94101
inAppManager.removeMessage(inboxMessages.get(0), new IterableHelper.SuccessHandler() {
95102
@Override
96103
public void onSuccess(@NonNull JSONObject data) {
97-
assertEquals(1, inAppManager.getInboxMessages().size());
98-
assertEquals("message2", inAppManager.getInboxMessages().get(0).getMessageId());
104+
signal.countDown();
99105
}
100106
}, new IterableHelper.FailureHandler() {
101107
@Override
102108
public void onFailure(@NonNull String reason, @Nullable JSONObject data) {
103109
assertFalse(true);
104110
}
105111
});
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));
114+
}
115+
116+
@Test
117+
public void testRemoveMessageFailureCallbackOnFailedResponse() throws Exception {
118+
final CountDownLatch signal = new CountDownLatch(1);
119+
dispatcher.enqueueResponse("/inApp/getMessages", new MockResponse().setBody(IterableTestUtils.getResourceString("inapp_payload_inbox_multiple.json")));
120+
final IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager();
121+
inAppManager.syncInApp();
122+
shadowOf(getMainLooper()).idle();
123+
List<IterableInAppMessage> inboxMessages = inAppManager.getInboxMessages();
124+
assertEquals(2, inboxMessages.size());
125+
assertEquals(1, inAppManager.getUnreadInboxMessagesCount());
126+
127+
final JSONObject responseData = new JSONObject("{\"key\":\"value\"}");
128+
dispatcher.enqueueResponse("/events/inAppConsume", new MockResponse().setResponseCode(500).setBody(responseData.toString()));
129+
130+
inAppManager.removeMessage(inboxMessages.get(0), new IterableHelper.SuccessHandler() {
131+
@Override
132+
public void onSuccess(@NonNull JSONObject data) {
133+
assertFalse(true);
134+
}
135+
}, new IterableHelper.FailureHandler() {
136+
@Override
137+
public void onFailure(@NonNull String reason, @Nullable JSONObject data) {
138+
signal.countDown();
139+
}
140+
});
141+
shadowOf(getMainLooper()).idle();
142+
assertTrue("Message remove failure callback called", signal.await(1, TimeUnit.SECONDS));
108143
}
109144

110145
@Test

0 commit comments

Comments
 (0)