### Question:
Http { public String submitPost(String url, byte[] postData) { String response = ""; try { URL u = new URL(url); HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); setupAuthorization(connection); connection.setRequestProperty("Content-Type", "applicaton/octet-stream"); connection.setRequestProperty("Content-Length", Integer.toString(postData.length)); connection.getOutputStream().write(postData); InputStream is = getResponseFrom(connection); response = IOUtils.toString(is); } catch (IOException e) { throw new RuntimeException("Error with connection.", e); } return response; } Http(String user, String password); String submitPost(String url, byte[] postData); String submitGet(String url); InputStream submitGetWithoutAuthentication(String url);  }### Answer:
@Test public void sendingPost() throws Exception { Http http = new Http("", ""); String response = http.submitPost("http: assertThat(response, containsString("<httpMethod>POST</httpMethod>")); }
@Test public void serverMustReceiveCredentials() throws Exception { Http http = new Http("user", "pw"); String response = http.submitPost("http: assertThat(response, containsString("<basicAuth>user:pw</basicAuth>")); }
@Test public void serverMustReceivePostData() throws Exception { Http http = new Http("", ""); byte[] bytesToSend = {4, 2}; String response = http.submitPost("http: assertThat(response, containsString("<contentLength>2</contentLength>")); assertThat(response, containsString("<content>42</content>")); }
@Test(expected=RuntimeException.class) public void sendingPostToUnauthorized() throws Exception { Http http = new Http("", ""); http.submitPost("http: }
@Test(expected=RuntimeException.class) public void sendingPostToUnreachable() throws Exception { Http http = new Http("", ""); http.submitPost("http: }