JMockit withCapture() 返回 null

JMockit withCapture() returning null

我正在尝试使用 JMockit 的验证来验证传递给模拟的参数。模拟似乎在工作,但参数没有被捕获并且 returns null.

@Test
public void testHTTPRequestGeneration() throws IOException{

    final CloseableHttpClient anyInstance = HttpClientBuilder.create().build();

    new NonStrictExpectations(CloseableHttpClient.class) {
        {
            anyInstance.execute((HttpUriRequest)any); 
            result = new MockHTTPResponse();    
        }   
    };

    Entity entity = new Entity();
    entity.setType(Entity1);
    handler.processEvent(entity);

    new Verifications() {{
        HttpUriRequest httpUriRequest;
        anyInstance.execute(httpUriRequest = withCapture());
        System.out.println("---->"+httpUriRequest);
    }};

}

在上面,执行的响应被模拟得很好,我得到 return 值作为 "new MockHTTPResponse()"。但是验证块没有捕获它。

尝试添加 times 字段来验证方法调用的次数。

   new Verifications() {{
        HttpUriRequest httpUriRequest;
        anyInstance.execute(httpUriRequest = withCapture()); times = 1;
        System.out.println("---->"+httpUriRequest);
    }};