### Question:
HttpRestServiceProviderImpl implements HttpRestServiceProvider { @Override public <T> Optional<T> put(final Object object, final String url, final Class<T> clazz) { final ResponseEntity<T> response = putHttpRequest(object, url, clazz); return createOptional(response, url, HttpMethod.PUT); } HttpRestServiceProviderImpl(final RestTemplate restTemplate);  HttpRestServiceProviderImpl(final RestTemplate restTemplate, final HttpHeaders defaultHttpHeaders); @Deprecated  HttpRestServiceProviderImpl(final RestTemplate restTemplate, final HttpHeadersProvider httpHeadersProvider); @Override Optional<T> get(final String url, final Class<T> clazz); @Override Optional<T> get(final String url, final HttpHeaders headers, final Class<T> clazz); @Override ResponseEntity<T> getHttpResponse(final String url, final Class<T> clazz); @Override ResponseEntity<T> getHttpResponse(final String url, final HttpHeaders headers, final Class<T> clazz); @Override Optional<T> post(final Object object, final String url, final Class<T> clazz); @Override ResponseEntity<T> postHttpRequest(final Object object, final String url, final Class<T> clazz); @Override ResponseEntity<T> postHttpRequest(final Object object, final String url, final HttpHeaders headers,
            final Class<T> clazz); @Override Optional<T> put(final Object object, final String url, final Class<T> clazz); @Override ResponseEntity<T> putHttpRequest(final Object object, final String url, final Class<T> clazz); @Override ResponseEntity<T> deleteHttpRequest(final String url, final Class<T> clazz);  }### Answer:
@Test public void test_put_returnOptionalPresentIfResponseIsOKAndHasBody() { final HttpRestServiceProvider objUnderTest = new HttpRestServiceProviderImpl(mockRestTemplate); when(mockRestTemplate.exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class), eq(String.class))) .thenReturn(mockEntity); when(mockEntity.getStatusCode()).thenReturn(HttpStatus.OK); when(mockEntity.hasBody()).thenReturn(true); when(mockEntity.getBody()).thenReturn(BODY); final Optional<String> actual = objUnderTest.put(BODY, DUMMY_URL, String.class); assertTrue(actual.isPresent()); verify(mockRestTemplate, atLeastOnce()).exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class), eq(String.class)); }
@Test public void test_put_returnOptionalPresentIfResponseIsOKAndHasNoBody() { final HttpRestServiceProvider objUnderTest = new HttpRestServiceProviderImpl(mockRestTemplate); when(mockRestTemplate.exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class), eq(String.class))) .thenReturn(mockEntity); when(mockEntity.getStatusCode()).thenReturn(HttpStatus.OK); when(mockEntity.hasBody()).thenReturn(false); final Optional<String> actual = objUnderTest.put(BODY, DUMMY_URL, String.class); assertFalse(actual.isPresent()); verify(mockRestTemplate, atLeastOnce()).exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class), eq(String.class)); }