@Test
public void request() throws IOException {

    {
        String responseContent = "Response";
        String requestContent = "Request";
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(responseContent.getBytes("utf-8"));
        HttpURLConnection httpURLConnection = mock(HttpURLConnection.class);
        when(httpURLConnection.getOutputStream()).thenReturn(outputStream);
        when(httpURLConnection.getResponseCode()).thenReturn(-1);
        when(httpURLConnection.getContentLength()).thenReturn(responseContent.length());
        when(httpURLConnection.getInputStream()).thenReturn(inputStream);
        HttpClient httpClient = new HttpClient();
        httpClient.httpURLConnection = httpURLConnection;
        HttpResponse response = httpClient.request(requestContent, "utf-8");
        assertThat(response, is(not(nullValue())));
        assertThat(response.getStatusCode(), is(-1));
        assertThat(response.getContent(), is("Response"));
    }
    {
        String responseContent = "";
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(responseContent.getBytes("utf-8"));
        HttpURLConnection httpURLConnection = mock(HttpURLConnection.class);
        when(httpURLConnection.getDoOutput()).thenReturn(false);
        when(httpURLConnection.getOutputStream()).thenReturn(outputStream);
        when(httpURLConnection.getResponseCode()).thenReturn(-1);
        when(httpURLConnection.getContentLength()).thenReturn(responseContent.length());
        when(httpURLConnection.getInputStream()).thenReturn(inputStream);
        HttpClient httpClient = new HttpClient();
        httpClient.httpURLConnection = httpURLConnection;
        httpClient.request("something", "utf-8");
        assertThat(outputStream.size(), is(0));
    }
    {
        String responseContent = "";
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(responseContent.getBytes("utf-8"));
        HttpURLConnection httpURLConnection = mock(HttpURLConnection.class);
        when(httpURLConnection.getDoOutput()).thenReturn(true);
        when(httpURLConnection.getOutputStream()).thenReturn(outputStream);
        when(httpURLConnection.getResponseCode()).thenReturn(-1);
        when(httpURLConnection.getContentLength()).thenReturn(responseContent.length());
        when(httpURLConnection.getInputStream()).thenReturn(inputStream);
        HttpClient httpClient = new HttpClient();
        httpClient.httpURLConnection = httpURLConnection;
        httpClient.request("key=value&key2=value2", "utf-8");
        String expectedString = "key=value&key2=value2";
        assertThat(outputStream.size(), is(expectedString.length()));
        assertThat(outputStream.toByteArray(), is(expectedString.getBytes("utf-8")));
    }
}