public void testResponseObject() throws Exception {
Object[] components = {new MultiFormatWriter(), new MyResource()};
JaxRsHandler handler = HandlerCreator.getHandler("", components);
Request requestMock = EasyMock.createNiceMock(Request.class);
ResponseImpl responseImpl = new ResponseImpl();
expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
String[] acceptHeaders = {"test/string2;q=.8", "test/string1;q=.7"};
expect(requestMock.getHeaderNames()).andReturn(
Collections.singleton(HeaderName.ACCEPT)).anyTimes();
expect(requestMock.getHeaderValues(HeaderName.ACCEPT))
.andReturn(acceptHeaders).anyTimes();
RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
expect(requestURI.getPath()).andReturn("/");
expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
replay(requestMock);
replay(requestURI);
handler.handle(requestMock, responseImpl);
responseImpl.consumeBody();
assertTrue(writerCalled);
Assert.assertArrayEquals(entity.getBytes(), responseImpl.getBodyBytes());
String[] contentType = responseImpl.getHeaders().get(HeaderName.CONTENT_TYPE);
Assert.assertTrue(contentType.length == 1);
Assert.assertEquals("test/string2",contentType[0]);
String[] contentLength = responseImpl.getHeaders().get(HeaderName.CONTENT_LENGTH);
Assert.assertTrue(contentLength.length == 1);
Assert.assertEquals(Integer.toString(entity.length()), contentLength[0]);
Assert.assertEquals(ResponseStatus.SUCCESS, responseImpl.getStatus());
}