Java “;被通缉但未被援引;然而,与此模拟的”;错误

Java “;被通缉但未被援引;然而,与此模拟的”;错误,java,junit,mockito,assert,Java,Junit,Mockito,Assert,单元测试一直在给我答案= Wanted but not invoked: However, there were exactly 3 interactions with this mock. 我所要做的就是,测试方法执行的超时时间——如果该方法需要更多时间,则终止该方法,并将计数(以了解超时响应率)发布为度量 @测试 public void testTimeoutFunction()引发异常{ Response=getresponseforest(); 当(处理器) .process(任何(R

单元测试一直在给我答案=

Wanted but not invoked: However, there were exactly 3 interactions with this mock.
我所要做的就是,测试方法执行的超时时间——如果该方法需要更多时间,则终止该方法,并将计数(以了解超时响应率)发布为度量

@测试
public void testTimeoutFunction()引发异常{
Response=getresponseforest();
当(处理器)
.process(任何(Request.class)))
.thenAnswer((答案)调用->{
睡眠(100);
返回响应;
});
当(itemRequest.getRequestContext())。然后返回(itemRequestContext);
testClass=spy(新的testClass(处理器、执行器服务));
列表输出=testClass.getItemList(ID,itemRequest);
验证(testClass,次(1)).responseTimedOutCount();
assertTrue(output.isEmpty());
验证(testClass,超时(执行超时)).buildResponse(itemRequest);
验证(testClass,次(1)).buildResponse(itemRequest);
}
这是我正在测试的方法:

公共类TestClass{
@可视性测试
无效响应超出计数(){
//日志度量
}
专用CompletableFuture getResponseAsync(最终调度执行器服务延迟器,
最终项目请求(项目请求){
返回timeoutWithTimeoutFunction(延迟器、执行超时、TimeUnit.毫秒、,
CompletableFuture.SupplySync(()->getResponseWithTimeoutFunction(itemRequest),executorService),
Response.emptyResponse(),()->responseTimedOutCount());
}
私有响应getResponseWithTimeoutFunction(最终ItemRequest ItemRequest){
//做点什么然后回复
}
公共列表getItemList(最终字符串id,最终ItemRequest ItemRequest)引发异常{
final ScheduledExecutorService delayer=Executors.newScheduledThreadPool(1);
反应;
如果(验证id){
试一试{
response=getResponseAsync(delayer,itemRequest).get();
}捕获(最终可丢弃的t){
response=response.emptyResponse();
}最后{
delayer.shutdown();
}
返回转换(response,id).getItems();
}否则{
返回null;
}
}
}
Junit中的异常:

就本条而言—

verify(testClass, times(1)).responseTimedOutCount();

Wanted but not invoked:
testClass.responseTimedOutCount(); 

However, there were exactly 3 interactions with this mock:
testClass.getItemList(ID, itemRequest);
testClass.validateItemId(ID);
testClass.getResponseWithTimeoutFunction(itemRequest);

您发布的代码从未调用(甚至从未提及)
getResponseTimedOutCount()
(尽管它确实调用了
responseTimedOutCount()
)通过您发布的代码很难看出您想要实现的目标。您跳过了实现此目标所需的一些代码,因此很难判断这是否相关。我建议您生成一个较小的、自包含的示例,演示相同的问题。可能重复