JsonErrorUnmarshaller extends AbstractErrorUnmarshaller<JsonNode> { @Override public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception { if (jsonContent == null || NullNode.instance.equals(jsonContent)) { return null; } return MAPPER.treeToValue(jsonContent, exceptionClass); } JsonErrorUnmarshaller(Class<? extends AmazonServiceException> exceptionClass, String handledErrorCode); @Override AmazonServiceException unmarshall(JsonNode jsonContent); boolean matchErrorCode(String actualErrorCode); static final JsonErrorUnmarshaller DEFAULT_UNMARSHALLER; }
@Test public void unmarshall_ValidJsonContent_UnmarshallsCorrectly() throws Exception { CustomException ase = (CustomException) unmarshaller.unmarshall(JSON); assertEquals("Some error message", ase.getErrorMessage()); assertEquals("This is a customField", ase.getCustomField()); assertEquals(Integer.valueOf(42), ase.getCustomInt()); }
@Test public void unmarshall_EmptyJsonContent_returnsEmptyException() throws Exception { CustomException ase = (CustomException) unmarshaller.unmarshall(EMPTY_JSON); assertNull(ase.getErrorMessage()); assertNull(ase.getCustomField()); assertNull(ase.getCustomInt()); }
@Test public void unmarshall_NullNodeJsonContent_returnsNull() throws Exception { CustomException ase = (CustomException) unmarshaller.unmarshall(NullNode.instance); assertNull(ase); }
@Test public void unmarshall_NullJsonContent_returnsNull() throws Exception { CustomException ase = (CustomException) unmarshaller.unmarshall(null); assertNull(ase); }
@Test public void unmarshall_InvalidCaseJsonContent_DoesNotUnmarshallCustomFields() throws Exception { CustomException ase = (CustomException) unmarshaller.unmarshall(INVALID_CASE_JSON); assertEquals("Some error message", ase.getErrorMessage()); assertNull(ase.getCustomField()); assertNull(ase.getCustomInt()); }