Skip to content

Commit

Permalink
Add test when message is unparseable
Browse files Browse the repository at this point in the history
  • Loading branch information
ekawinataa committed Jun 19, 2024
1 parent a9ee36b commit c615d69
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ public void serializeShouldReturnMessageAsItIsWhenJsonPathConfigurationDoesNotMa
Assertions.assertEquals(JsonPath.parse(DEFAULT_JSON_MESSAGE).jsonString(), JsonPath.parse(result).jsonString());
}

@Test
public void serializeShouldThrowNumberFormatExceptionWhenPayloadTypecastIsUnparseable() {
String payload = "{\"key\": \"value\", \"long\":\"1234568129012312\",\"nested\": {\"int\": \"1234\"}, \"double\": \"12.1\"}";
String parameters = "[{\"jsonPath\": \"$.key\", \"type\": \"INTEGER\"}]";
Map<String, Function<String, Object>> property = serializerConfigConverter.convert(null, parameters);
Mockito.when(serializerConfig.getJsonTypecastMapping()).thenReturn(property);
Mockito.when(messageSerializer.serialize(Mockito.any())).thenReturn(payload);

Assertions.assertThrows(NumberFormatException.class,
() -> typecastedJsonSerializer.serialize(buildMessage("key", DEFAULT_JSON_MESSAGE)));
}


private Message buildMessage(String key, String payload) {
return new Message(
Expand Down

0 comments on commit c615d69

Please sign in to comment.