### Question:
RestTemplate { public <T> T post(String path, String content, ResponseCallback<T> callback) { return handleResponse(callback, client.post(path, content)); } RestTemplate(HttpClient client); T get(String path, ResponseCallback<T> callback); T getUncached(String path, ResponseCallback<T> callback); HttpResponse get(String path); HttpResponse getUncached(String path); void put(String path); T put(String path, ResponseCallback<T> callback); T put(String path, String content, ResponseCallback<T> callback); T put(String path, HttpEntity httpEntity, ResponseCallback<T> callback); T copy(String path, String destinationUri, ResponseCallback<T> callback); void put(String path, String content); void put(String path, HttpEntity httpEntity); void put(String path, InputStream data, String contentType,
			long contentLength); T put(String path, InputStream data, String contentType,
			long contentLength, ResponseCallback<T> callback); T post(String path, String content, ResponseCallback<T> callback); T post(String path, HttpEntity httpEntity, ResponseCallback<T> callback); T post(String path, InputStream content, ResponseCallback<T> callback); T postUncached(String path, String content, ResponseCallback<T> callback); HttpResponse post(String path, String content ); HttpResponse postUncached(String path, String content ); T delete(String path, ResponseCallback<T> callback); void delete(String path); T head(String path, ResponseCallback<T> callback);  }### Answer:
@SuppressWarnings("unchecked") @Test public void successful_post3_should_call_success_and_release_connection() throws Exception { RestTemplate template = new RestTemplate(client); ResponseCallback<String> callback = mock(ResponseCallback.class); HttpResponse rsp = mock(HttpResponse.class); when(client.post(anyString(), anyString())).thenReturn(rsp); when(rsp.isSuccessful()).thenReturn(Boolean.TRUE); template.post("some_path", "content", callback); verify(callback).success(any(HttpResponse.class)); verify(rsp).releaseConnection(); }
@SuppressWarnings("unchecked") @Test public void failed_post3_should_call_error_and_release_connection() throws Exception { RestTemplate template = new RestTemplate(client); ResponseCallback<String> callback = mock(ResponseCallback.class); HttpResponse rsp = mock(HttpResponse.class); when(client.post(anyString(), anyString())).thenReturn(rsp); when(rsp.isSuccessful()).thenReturn(Boolean.FALSE); template.post("some_path", "content", callback); verify(callback).error(any(HttpResponse.class)); verify(rsp).releaseConnection(); }
@SuppressWarnings("unchecked") @Test public void exceptions_in_callback_should_be_rethrown_and_connection_released() throws Exception { RestTemplate template = new RestTemplate(client); ResponseCallback<String> callback = mock(ResponseCallback.class); HttpResponse rsp = mock(HttpResponse.class); when(client.post(anyString(), anyString())).thenReturn(rsp); when(rsp.isSuccessful()).thenReturn(Boolean.TRUE); when(callback.success(rsp)).thenThrow(new Exception("test")); try { template.post("some_path", "content", callback); fail("RT expected"); } catch (RuntimeException e) { } verify(rsp).releaseConnection(); }