@SuppressWarnings("ThrowableNotThrown") @Test(expected = MarqetaError.class) public void shouldThrowMarqetaErrorOnUnsuccessfulCreateCardInvocation() { final HttpStatusCodeException exception = new HttpClientErrorException(HttpStatus.BAD_REQUEST); doThrow(exception).when(restTemplate).postForObject(any(), any(), any(), any(Object[].class)); when(errorFactory.fromResponseBody(any(), any())).thenReturn(new MarqetaError()); try { target.createCard(new CreateCardRequest()); } finally { verify(errorFactory).fromResponseBody(exception.getResponseBodyAsString(), exception.getStatusCode()); } }
public CreateCardResponse createCard(CreateCardRequest request) { try { final String url = baseUrl + "/cards?show_pan=true&show_cvv_number=true"; return restTemplate.postForObject(url, request, CreateCardResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } }
MarqetaClient { public CreateCardResponse createCard(CreateCardRequest request) { try { final String url = baseUrl + "/cards?show_pan=true&show_cvv_number=true"; return restTemplate.postForObject(url, request, CreateCardResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } } }
MarqetaClient { public CreateCardResponse createCard(CreateCardRequest request) { try { final String url = baseUrl + "/cards?show_pan=true&show_cvv_number=true"; return restTemplate.postForObject(url, request, CreateCardResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } } @Autowired  MarqetaClient(RestTemplate restTemplate, MarqetaErrorFactory errorFactory); }
MarqetaClient { public CreateCardResponse createCard(CreateCardRequest request) { try { final String url = baseUrl + "/cards?show_pan=true&show_cvv_number=true"; return restTemplate.postForObject(url, request, CreateCardResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } } @Autowired  MarqetaClient(RestTemplate restTemplate, MarqetaErrorFactory errorFactory); void setBaseUrl(String baseUrl); CreateCardResponse createCard(CreateCardRequest request); CreateUserResponse createUser(CreateUserRequest request); }
MarqetaClient { public CreateCardResponse createCard(CreateCardRequest request) { try { final String url = baseUrl + "/cards?show_pan=true&show_cvv_number=true"; return restTemplate.postForObject(url, request, CreateCardResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } } @Autowired  MarqetaClient(RestTemplate restTemplate, MarqetaErrorFactory errorFactory); void setBaseUrl(String baseUrl); CreateCardResponse createCard(CreateCardRequest request); CreateUserResponse createUser(CreateUserRequest request);  }