Skip to content

Commit c3432df

Browse files
committed
Add basic toJSONObject unit test
- tests OSInAppMessageInternal (not OSInAppMessage) - only tests "messageId" as this test was added when modifying the JSON key from "id" to "messageId"
1 parent 94c7523 commit c3432df

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

OneSignalSDK/unittest/src/test/java/com/test/onesignal/InAppMessageIntegrationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,27 @@ public void testLiquidIAMDisplayWaitsForGetTags() throws Exception {
19071907
assertEquals("in_app_messages/" + message.getMessageId() + "/impression", lastRequest.url);
19081908
}
19091909

1910+
// Test toJSONObject() method currently only checks JSON for "messageId"
1911+
@Test
1912+
public void testInAppMessageInternalToJSONObject_messageId() throws Exception {
1913+
// 1. Create a basic test IAM
1914+
OSTestInAppMessageInternal iam = InAppMessagingHelpers.buildTestMessage(null);
1915+
1916+
// 2. Set a message ID for the IAM
1917+
String messageId = new String(new char[64]).replace('\0', '0');
1918+
iam.setMessageId(messageId);
1919+
1920+
// 3. Init
1921+
OneSignalInit();
1922+
threadAndTaskWait();
1923+
1924+
// 4. call toJSONObject() on IAM
1925+
JSONObject testJsonObj = iam.toJSONObject();
1926+
1927+
// 5. Check "messageId" in JSON Object
1928+
assertEquals(messageId, testJsonObj.optString("messageId"));
1929+
}
1930+
19101931
private void setMockRegistrationResponseWithMessages(ArrayList<OSTestInAppMessageInternal> messages) throws JSONException {
19111932
final JSONArray jsonMessages = new JSONArray();
19121933

0 commit comments

Comments
 (0)