mercredi 9 septembre 2020

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 is never called. Any ideas?

Aucun commentaire:

Enregistrer un commentaire