### Question:
MarqetaErrorFactory { public MarqetaError fromResponseBody(String responseBody, HttpStatus statusCode) { MarqetaError instance; try { instance = objectMapper.readValue(responseBody, MarqetaError.class); } catch (Exception cause) { throw new IllegalArgumentException("Failed to parse Marqeta error as JSON", cause); } instance.setStatusCode(statusCode); return instance; } @Autowired  MarqetaErrorFactory(ObjectMapper objectMapper); MarqetaError fromResponseBody(String responseBody, HttpStatus statusCode);  }### Answer:
@SuppressWarnings("ThrowableNotThrown") @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfFailedToParseJson() { target.fromResponseBody("This string cannot be properly parsed", HttpStatus.INTERNAL_SERVER_ERROR); }
@Test public void shouldReturnExpectedObjectIfSucceedToParseJson() { final HttpStatus statusCode = HttpStatus.BAD_REQUEST; final String errorCode = "400002"; final String errorMessage = "Birth date cannot be a future date"; final String responseBody = format("{\"error_code\":\"%s\",\"error_message\":\"%s\"}", errorCode, errorMessage); final MarqetaError result = target.fromResponseBody(responseBody, statusCode); assertThat(result, is(notNullValue())); assertThat(result.getStatusCode(), is(equalTo(statusCode))); assertThat(result.getErrorCode(), is(equalTo(errorCode))); assertThat(result.getErrorMessage(), is(equalTo(errorMessage))); }