Skip to content

Commit

Permalink
fix: fixed failing unit tests for invalid numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Desu Sai Venkat committed Feb 5, 2024
1 parent 10b8f8f commit d5d4230
Showing 1 changed file with 117 additions and 55 deletions.
172 changes: 117 additions & 55 deletions core/src/test/java/com/rudderstack/android/sdk/core/RudderGsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void setup() throws Exception {
)
.thenAnswer((Answer<String>) invocation -> "2022-03-14T06:46:41.365Z");
}

@Test
public void testRudderContextSerializationSynchronicity() {
AtomicInteger contextsSerialized = new AtomicInteger(0);
Expand Down Expand Up @@ -121,6 +122,7 @@ private RudderContext getRudderContext(int i) throws NoSuchFieldException, Illeg
ReflectionUtils.setPrivateField(context, "customContextMap", customContextMap);
return context;
}

private RudderContext getDefaultRudderContext() throws NoSuchFieldException, IllegalAccessException {
RudderContext context = Mockito.mock(RudderContext.class);
RudderApp app = Mockito.mock(RudderApp.class);
Expand Down Expand Up @@ -312,61 +314,121 @@ public void testGsonWithInvalidNumbers() {


String outputJsonString = RudderGson.serialize(message);
String expectedJsonString = "{\n" +
" \"messageId\": \"" + message.getMessageId() + "\",\n" +
" \"channel\": \"mobile\",\n" +
" \"originalTimestamp\": \"2022-03-14T06:46:41.365Z\",\n" +
" \"event\": \"TestEvent\",\n" +
" \"properties\": {\n" +
" \"maxValue\": 1.7976931348623157E308,\n" +
" \"double\": 45.0,\n" +
" \"positiveInfinity\": \"Infinity\",\n" +
" \"float\": 45.0,\n" +
" \"list\": [\n" +
" \"Infinity\",\n" +
" \"-Infinity\",\n" +
" 1.7976931348623157E308,\n" +
" 4.9E-324,\n" +
" \"NaN\"\n" +
" ],\n" +
" \"long\": 45,\n" +
" \"int\": 45,\n" +
" \"negativeInfinity\": \"-Infinity\",\n" +
" \"general\": 45,\n" +
" \"minValue\": 4.9E-324,\n" +
" \"nan\": \"NaN\",\n" +
" \"map\": {\n" +
" \"general\": 45,\n" +
" \"minValue\": 4.9E-324,\n" +
" \"maxValue\": 1.7976931348623157E308,\n" +
" \"double\": 45.0,\n" +
" \"positiveInfinity\": \"Infinity\",\n" +
" \"nan\": \"NaN\",\n" +
" \"float\": 45.0,\n" +
" \"list\": [\n" +
" \"Infinity\",\n" +
" \"-Infinity\",\n" +
" 1.7976931348623157E308,\n" +
" 4.9E-324,\n" +
" \"NaN\",\n" +
" 45,\n" +
" 45.0\n" +
" ],\n" +
" \"map\": {\n" +
" \"general\": 45,\n" +
" \"minValue\": 4.9E-324,\n" +
" \"maxValue\": 1.7976931348623157E308,\n" +
" \"double\": 45.0,\n" +
" \"positiveInfinity\": \"Infinity\",\n" +
" \"nan\": \"NaN\",\n" +
" \"negativeInfinity\": \"-Infinity\"\n" +
" },\n" +
" \"long\": 45,\n" +
" \"int\": 45,\n" +
" \"negativeInfinity\": \"-Infinity\"\n" +
" }\n" +
" },\n" +
" \"integrations\": {}\n" +
String expectedJsonString = "{" +
"\"messageId\": \"" + message.getMessageId() + "\"," +
"\"channel\": \"mobile\"," +
"\"context\": {" +
"\"traits\": {" +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"nan\": \"NaN\"," +
"\"float\": 45.0," +
"\"list\": [" +
"\"Infinity\"," +
"\"-Infinity\"," +
"1.7976931348623157E308," +
"4.9E-324," +
"\"NaN\"," +
"45," +
"45.0" +
"]," +
"\"map\": {" +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"nan\": \"NaN\"," +
"\"negativeInfinity\": \"-Infinity\"" +
"}," +
"\"long\": 45," +
"\"int\": 45," +
"\"negativeInfinity\": \"-Infinity\"" +
"}," +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"float\": 45.0," +
"\"list\": [" +
"\"Infinity\"," +
"\"-Infinity\"," +
"1.7976931348623157E308," +
"4.9E-324," +
"\"NaN\"," +
"45," +
"45.0" +
"]," +
"\"long\": 45," +
"\"int\": 45," +
"\"negativeInfinity\": \"-Infinity\"," +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"nan\": \"NaN\"," +
"\"map\": {" +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"nan\": \"NaN\"," +
"\"negativeInfinity\": \"-Infinity\"" +
"}" +
"}," +
"\"originalTimestamp\": \"2022-03-14T06:46:41.365Z\"," +
"\"event\": \"TestEvent\"," +
"\"properties\": {" +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"float\": 45.0," +
"\"list\": [" +
"\"Infinity\"," +
"\"-Infinity\"," +
"1.7976931348623157E308," +
"4.9E-324," +
"\"NaN\"" +
"]," +
"\"long\": 45," +
"\"int\": 45," +
"\"negativeInfinity\": \"-Infinity\"," +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"nan\": \"NaN\"," +
"\"map\": {" +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"nan\": \"NaN\"," +
"\"float\": 45.0," +
"\"list\": [" +
"\"Infinity\"," +
"\"-Infinity\"," +
"1.7976931348623157E308," +
"4.9E-324," +
"\"NaN\"," +
"45," +
"45.0" +
"]," +
"\"map\": {" +
"\"general\": 45," +
"\"minValue\": 4.9E-324," +
"\"maxValue\": 1.7976931348623157E308," +
"\"double\": 45.0," +
"\"positiveInfinity\": \"Infinity\"," +
"\"nan\": \"NaN\"," +
"\"negativeInfinity\": \"-Infinity\"" +
"}," +
"\"long\": 45," +
"\"int\": 45," +
"\"negativeInfinity\": \"-Infinity\"" +
"}" +
"}," +
"\"integrations\": {}" +
"}";
assertThat("Invalid Numbers are removed and the message is serialized perfectly", outputJsonString, is(expectedJsonString.replace("\n", "").replace(" ", "")));
}
Expand Down

0 comments on commit d5d4230

Please sign in to comment.