Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockito mocking a Response class

When I try to mock a javax.ws.rs.core Response I get a error message:

Unable to create a JAX-RS runtime Delegate

Why does this happen?

 Response response = Mockito.mock(Response.class);

But when I try to mock a HttpServletResponse there is no issue with that!

 HttpServletResponse response1 = Mockito.mock(HttpServletResponse.class);
like image 361
meteor Avatar asked Jul 10 '15 18:07

meteor


1 Answers

You can try with a fake response like this:

ResponseBuilder responseBuilder = Response.ok();
when(client.form(any(Form.class))).thenReturn(responseBuilder.entity("his is a string").build();

In this snippet "when" is a mockito method, and responseBuilder object return a simple string.

like image 74
Tomas Pinto Avatar answered Oct 01 '22 18:10

Tomas Pinto