如何使用Mockito模拟Jax RS客户端?
Foo expected = new Foo();
when(restClient.target(anyString())
.path(anyString()) //Got NPE here
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(expected, MediaType.APPLICATION_JSON))
.readEntity(Foo.class)
).thenReturn(expected);
答案 0 :(得分:0)
你必须模拟每个方法调用:
when(restClient.target(anyString()).thenReturn(...)
when(target.path(anyString()).thenReturn(...)
...
我不知道restClient返回的内容......也许它只是返回restClient?