[英]How to use Mockito.doAnswer() with a void method with no parameters?
@Test
public void successfulHandshake(){
HandshakeImpl1Server handShake = new HandshakeImpl1Server();
handShake.setHttpStatus((short) 101);
authUnderTest.authenticate(callback);
doAnswer(invocation -> {
websocket.onOpen(handShake);
return null;
}).when(websocket).open();
verify(websocket,times(1)).send(any(String.class));
}
永遠不會調用 doAnswer。 有任何想法嗎?
您需要在調用被測方法之前而不是之后存根您的方法。
在調用 authUnderTest.authenticate 之前移動 doAnswer
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.