### Question:
MsgAmRestClientImpl implements MsgAmRestClient { @Override public SendMessagesResponse sendMessage(final ClientSmsSendMessagesRequest request) { LOGGER.debug("MsgAm resource Client Performing send sms message to Msg.AM request with parameters - {}", request); final ResponseEntity<SendMessagesResponse> responseEntity = execute(request); if (responseEntity.getStatusCode().isError()) { LOGGER.error(" Failed to send sms - {}", responseEntity); throw new MsgAmClientRuntimeException(request.getMessage().getSourceNumber(), request.getMessage().getPhoneNumber()); } final SendMessagesResponse response = responseEntity.getBody(); LOGGER.debug("MsgAm resource Client Successfully sent text message with request - {}, response message - {}", request, response); return response; } MsgAmRestClientImpl(final String apiUrl, final RestClient restClient); @Override SendMessagesResponse sendMessage(final ClientSmsSendMessagesRequest request);  }### Answer:
@Test public void sendMessageStatusOk() { final ClientSmsSendMessagesRequest clientSmsSendMessagesRequest = new ClientSmsSendMessagesRequest( "sms_send", 1L, uuid(), uuid(), uuid(), uuid(), uuid()); final SendMessagesResponse response = new SendMessagesResponse( uuid(), uuid(), uuid(), new Message( clientSmsSendMessagesRequest.getMessage().getId(), clientSmsSendMessagesRequest.getMessage().getPhoneNumber(), 1L, 1 ) ); response.setResult("0"); final HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE); headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE); headers.add("Content-Charset", "UTF-8"); when(restClient.exchange(apiUrl, HttpMethod.POST, new HttpEntity<>(clientSmsSendMessagesRequest, headers), SendMessagesResponse.class)) .thenReturn(new ResponseEntity<>(response, HttpStatus.OK)); assertThat(client.sendMessage(clientSmsSendMessagesRequest)).isEqualTo(response); verify(restClient).exchange(apiUrl, HttpMethod.POST, new HttpEntity<>(clientSmsSendMessagesRequest, headers), SendMessagesResponse.class); }
@Test public void sendMessageStatusFailed() { final ClientSmsSendMessagesRequest clientSmsSendMessagesRequest = new ClientSmsSendMessagesRequest( "sms_send", 1L, uuid(), uuid(), uuid(), uuid(), uuid()); final SendMessagesResponse response = new SendMessagesResponse( uuid(), uuid(), uuid(), new Message( clientSmsSendMessagesRequest.getMessage().getId(), clientSmsSendMessagesRequest.getMessage().getPhoneNumber(), 1L, 1 ) ); response.setResult("0"); final HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE); headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE); headers.add("Content-Charset", "UTF-8"); when(restClient.exchange(apiUrl, HttpMethod.POST, new HttpEntity<>(clientSmsSendMessagesRequest, headers), SendMessagesResponse.class)) .thenReturn(new ResponseEntity<>(response, HttpStatus.SERVICE_UNAVAILABLE)); assertThatThrownBy(() -> client.sendMessage(clientSmsSendMessagesRequest)) .isInstanceOf(MsgAmClientRuntimeException.class) .hasFieldOrPropertyWithValue("senderNumber", clientSmsSendMessagesRequest.getMessage().getSourceNumber()) .hasFieldOrPropertyWithValue("recipientNumber", clientSmsSendMessagesRequest.getMessage().getPhoneNumber()); verify(restClient).exchange(apiUrl, HttpMethod.POST, new HttpEntity<>(clientSmsSendMessagesRequest, headers), SendMessagesResponse.class); }