receivedBody = null;
Request requestMock = EasyMock.createNiceMock(Request.class);
Response responseMock = EasyMock.createNiceMock(Response.class);
RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
expect(requestMock.getMethod()).andReturn(Method.PUT).anyTimes();
String[] contentTypeHeader = { "application/x-mymessage" };
expect(requestMock.getHeaderValues(HeaderName.CONTENT_TYPE)).andReturn(
contentTypeHeader).anyTimes();
// this redundancy makes me prefer not to use mocks
Set<HeaderName> headerNames = new HashSet<HeaderName>();
headerNames.add(HeaderName.CONTENT_TYPE);
expect(requestMock.getHeaderNames()).andReturn(headerNames).anyTimes();
final String message = "The message in the body";
expect(requestMock.getMessageBody()).andReturn(new MessageBody2Write() {
@Override
public void writeTo(WritableByteChannel out) throws IOException {
out.write(ByteBuffer.wrap(message.getBytes()));
}
});
expect(requestURI.getPath()).andReturn(currentRequestUri);
expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
replay(requestMock);
replay(requestURI);
replay(responseMock);