我有一个模拟的 javax.ws.rs.client.WebTarget webTarget
。然后我执行以下操作:
Mockito.when(webTarget.path(Mockito.anyString())).thenReturn(webTarget).
现在我想从 webTarget 模拟中检索 .path(String)
方法期间设置的字符串。我有机会这样做吗?当时
webTarget.getUri()
不幸的是返回null
。
最佳答案
要获取字符串,您可以使用 ArgumentCaptor :
ArgumentCaptor<Person> argument = ArgumentCaptor.forClass(Person.class);
verify(mock).doSomething(argument.capture());
assertEquals("John", argument.getValue().getName());
或验证
Mockito.verify(webTarget).path("expectedString")
关于java - Mockito:获取模拟对象中字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30911552/