I have a resource:
@Path("/")
public class Resource {
@GET
public Response getResponse() {
//..
final GenericEntity<List<BusinessObject>> entity = new GenericEntity<List<BusinessObject>>(businessobjects) { };
return Response.status(httpResultCode).entity(entity).build();
}
}
I want to unit test this method without using a Jersey client, but I don’t know how to get the body of the Response object. I can’t see a method that works. Here’s the test method:
@Test
public void testMethod() {
Resource resourceUnderTest = new Resource();
Response response = resourceUnderTest.getResponse();
List<BusinessObject> result = ???;
}
I can get the result I want if I go though a Jersey Client, but I would rather just call the method directly without making any HTTP requests.
This will return the object you pass into the entity method of response builder. The Response object doesn’t serialize the result. Looking at the previous method, getEntity will probably return GenericEntity> so you’d want code like this.