I have a method in a class called "HttpResponseHelper" that I am trying to Unit Test when it throws a JsonProcessingException, but I was having difficulties getting it do so:
private static void populateHTTPResponseWithData(ObjectNode httpResponse)
{
ObjectMapper mapper = new ObjectMapper();
responseMapData.keySet().forEach(item -> {
try
{
httpResponse.put(item, mapper.writeValueAsString(responseMapData.get(item)));
}
catch (JsonProcessingException e)
{
LOGGER.error("Json Processing Exception", e);
}
});
}
The httpResponse argument is type ObjectNode (Jackson library), and then inside the method body a mapper object is created from the ObjectMapper class.
The resonseMapData is a ConcurrentHashMap> from a class called "MessageProcessResults". It looks like here its looping through the keySet and inserting a String for the Key Value pair inside of the httpResponse argument.
I tried using mockito on mapper to return a malformed JSON, but it looks like it writes the value as a String and passes each time.
Does anyone have any suggestions or is there a simple way to do this? Thank you for taking the time to read this question and possibly help me :D