TemplateMarshaller implements IJsonMarshaller<Object> { @Override public String toJson(Object obj) throws JsonMarshallingException { try { return objectMapper.writeValueAsString(obj); } catch (JsonProcessingException ex) { throw new JsonMarshallingException(ex.getMessage()); } }  @Override String toJson(Object obj); @Override Object toJava(String json);  }
@Test public void testToJson() throws JsonMarshallingException, JsonProcessingException { System.out.println("toJson"); String obj = "in"; String expResult = "out"; when(objectMapper.writeValueAsString(eq(obj))).thenReturn(expResult); String result = instance.toJson(obj); assertThat(result).isEqualTo(expResult); }
@Test(expected = JsonMarshallingException.class) public void testToJsonFail() throws JsonMarshallingException, JsonProcessingException { System.out.println("toJson"); String obj = "in"; when(objectMapper.writeValueAsString(eq(obj))).thenThrow(JsonProcessingException.class); instance.toJson(obj); }