@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))); }
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; }
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; } }
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); }
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); }
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);  }