void mockHandler(ref HttpRequestContext ctx) { ctx.response.writeBodyString("Hello world!"); } ResponseCachingOutputStream stream = new ResponseCachingOutputStream(); HttpRequestContext ctx = new HttpRequestContextBuilder() .response() .withOutputStream(stream) .and() .build(); mockHandler(ctx); assert(stream.getBody() == "Hello world!", stream.getBody());
A byte output stream implementation that caches HTTP header and body content as it's written, so that you can fetch and inspect the contents later. This is mainly intended as a helper for unit tests that involve checking the raw response body for request handlers.
To use this, create an instance and supply it to an HttpResponseBuilder when building a mocked request context: