Java – mockito simulates a response class

When I try to simulate javax ws. When rs.core responds, I receive an error message:

Why is that?

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

But when I tried to simulate httpservletresponse, there was no problem!

HttpServletResponse response1 = Mockito.mock(HttpServletResponse.class);

Solution

You can try this false response:

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

In this fragment, "when" is the mockito method, and the responsebuilder object returns a simple string

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>