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(response().withContent("Test"))
	.andReturn(response().withStatus(404));
	
	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()
{
	HttpMockSocket.reset();
}
Clone this wiki locally