@Test public void shouldCallMarqetaApiOnSuccessfulCreateUserInvocation() { final CreateUserResponse response = new CreateUserResponse(); when(restTemplate.postForObject(any(), any(), any(), any(Object[].class))).thenReturn(response); final CreateUserRequest request = new CreateUserRequest(); assertThat(target.createUser(request), is(sameInstance(response))); verify(restTemplate).postForObject( eq("https: same(request), eq(CreateUserResponse.class), any(Object[].class) ); }
public CreateUserResponse createUser(CreateUserRequest request) { try { final String url = baseUrl + "/users"; return restTemplate.postForObject(url, request, CreateUserResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } }
MarqetaClient { public CreateUserResponse createUser(CreateUserRequest request) { try { final String url = baseUrl + "/users"; return restTemplate.postForObject(url, request, CreateUserResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } } }
MarqetaClient { public CreateUserResponse createUser(CreateUserRequest request) { try { final String url = baseUrl + "/users"; return restTemplate.postForObject(url, request, CreateUserResponse.class); } catch (HttpStatusCodeException cause) { throw errorFactory.fromResponseBody(cause.getResponseBodyAsString(), cause.getStatusCode()); } } @Autowired  MarqetaClient(RestTemplate restTemplate, MarqetaErrorFactory errorFactory); }
MarqetaClient { public CreateUserResponse createUser(CreateUserRequest request) { try { final String url = baseUrl + "/users"; return restTemplate.postForObject(url, request, CreateUserResponse.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 CreateUserResponse createUser(CreateUserRequest request) { try { final String url = baseUrl + "/users"; return restTemplate.postForObject(url, request, CreateUserResponse.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);  }