mardi 8 décembre 2020

Mock when object is created with new keyword in the function

I have a function where i am creating an object of a class which comes from a library. The code is

SessionCodeChecks checks = new SessionCodeChecks(realmModel, session.getContext().getUri(), request, clientConnection, session, event, null, code, null, clientId, tabId, LoginActionsService.AUTHENTICATE_PATH);
        checks.initialVerify();

SessionCodeChecks class from a library which i need to mock . I am spying on the class object but getting InvalidUseOfMatchersException My test code is

SessionCodeChecks checks = Mockito.spy(new SessionCodeChecks(any(), any(), any(), any(), any(), any(), any(), anyString(), anyString(), anyString(), anyString(), anyString()));
        doNothing().when(checks).initialVerify();

How can i achieve it?

Aucun commentaire:

Enregistrer un commentaire