public HttpClient(String url) throws MalformedURLException { this(new HttpUrl(url)); }
HttpURLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true);
@Test public void constructor_shouldNotThrowExceptionIfItIsAnHttpUrl() throws MalformedURLException { HttpUrl url = new HttpUrl("http://something"); assertThat(url, notNullValue()); }
@Before public void setUp() throws IOException { HttpUrl url = mock(HttpUrl.class); client = new HttpClient(url); connection = mock(HttpURLConnection.class); when(url.openConnection()).thenReturn(connection); }
@Test public void constructor_shouldNotAllowNullUrls() throws MalformedURLException { exception.expect(MalformedURLException.class); exception.expectMessage("Url cannot be null"); new HttpUrl(null); }
@Test public void constructor_shouldThrowMalformedUrlExceptionIfTheUrlDoesNotHaveHttp() throws MalformedURLException { exception.expect(MalformedURLException.class); exception.expectMessage("Not a valid http url"); new HttpUrl("not_http"); }