我正在尝试捕获传递给我的webtarget的参数。但IntelliJ一直告诉我这是错误的
你不能捕获Entity.class或者我做错了吗?
代码段
private WebTarget webTarget;
response = target.request("application/hal+json").put(Entity.entity(inputString, MediaType.APPLICATION_JSON_TYPE));
我的测试
@RunWith(MockitoJUnitRunner.class)
public class ConnectorClientTest {
@Mock
WebTarget webTarget;
@Mock
Invocation.Builder builder;
@InjectMocks
ConnectorClient connectorClient;
@Before
public void setUp() throws Exception {
Response response = null;
when(webTarget.path(any())).thenReturn(webTarget);
when(webTarget.path(any())).thenReturn(webTarget);
when(webTarget.request(anyString())).thenReturn(builder);
when(builder.put(any(Entity.class)))
.thenReturn(response);
}
@Test
public void initiatePropertyIdentifierSearchTest(){
PropertyIdentifierSearchInput input = new
PropertyIdentifierSearchInput("12345670", BigInteger.valueOf(123));
connectorClient.initiatePropertyIdentifierSearch(input);
ArgumentCaptor<Entity> argument = ArgumentCaptor.forClass(Entity.class);
verify(webTarget.request((String[])
Mockito.any()).put(argument.capture()));
Entity entity = argument.getValue();
//assert the entity
}
答案 0 :(得分:2)
verify
行错了。您必须验证builder
:
verify(builder).put(argument.capture());