嘲笑响应课和使用读取方法阅读
我需要嘲笑一个具有返回javax.ws.rs.core.response的方法的类。该类遵循此方法调用。我将响应设置为如下:
when(methodCall).thenReturn(Response.status(Response.Status.OK).entity(someEntity).build());
现在,当使用Response..ReadEntity(String.Class)读取此响应时;它引发了一个错误:
java.lang.illegalstateException:在出站消息上不支持的方法。
我如何设置theTreturn中的响应,以返回readentity()方法可读取的入口消息。
PS我只能在测试类中进行更改。 我正在使用Junit 4.12和Mockito-All 1.9.5,Mockito-Inline 3.8.0
我正在嘲笑的类:
Response response = client.target().request().header().post();
String entity = response.readEntity(String.class);
I need to mock a class that has a method that returns javax.ws.rs.core.Response. The class follows this method call with a .readEntity(String.class). I'm setting the Response as follows:
when(methodCall).thenReturn(Response.status(Response.Status.OK).entity(someEntity).build());
Now when this Response is being read using response.readEntity(String.class); it throws an error:
java.lang.IllegalStateException : Method not supported on an outbound message.
How can I set the Response in thenReturn so as to return an inbound message readable by the readEntity() method.
P.S. I can't make changes in the main class, only in test class.
I'm using java 1.8 with junit 4.12 and mockito-all 1.9.5, mockito-inline 3.8.0
The class I'm mocking:
Response response = client.target().request().header().post();
String entity = response.readEntity(String.class);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须确保对响应进行模拟:
然后,我建议您以这种方式模拟
READENTITY
:First of all, you have to be sure that the response is mocked:
Then I suggest you to mock
readEntity
in this way: