Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
dart0 edited this page Jul 6, 2011 · 7 revisions

Static import

import static net.javacrumbs.mocksocket.http.HttpMockSocket.*;

Sample test

@Test
public void testHttpClientSequential() throws ClientProtocolException, IOException {
expectCall()
.andReturn("HTTP/1.0 200 OK\n\nTest")
.andReturn("HTTP/1.0 404 Not Found\n");
	
HttpClient httpclient = new DefaultHttpClient();

HttpGet httpget = new HttpGet(ADDRESS);
httpget.addHeader("Accept","text/plain");
HttpResponse getResponse = httpclient.execute(httpget);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
	
assertThat(recordedConnections(), hasItem(header("Accept", is("text/plain"))));
httpget.abort();
	
HttpPost httppost = new HttpPost(ADDRESS);
HttpResponse postResponse = httpclient.execute(httppost);
assertThat(postResponse.getStatusLine().getStatusCode(), is(404));
httppost.abort();
}

Cleanup

@After
public void reset()
{
reset();
}
Clone this wiki locally