MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1),
200, "OK");
fakeResponse.setEntity(new StringEntity("foobar"));
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
Request<String> request = new Request<String>(Request.Method.GET, "http://foo", null) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
return null;
}
@Override
protected void deliverResponse(String response) {
}
@Override
public Map<String, String> getHeaders() {
Map<String, String> result = new HashMap<String, String>();
result.put("requestheader", "foo");
return result;
}
@Override
public Map<String, String> getParams() {
Map<String, String> result = new HashMap<String, String>();
result.put("requestpost", "foo");
return result;
}
};
httpNetwork.performRequest(request);
assertEquals("foo", mockHttpStack.getLastHeaders().get("requestheader"));
assertEquals("requestpost=foo&", new String(mockHttpStack.getLastPostBody()));