vendredi 2 novembre 2018

Wanted but not invoked while it is being invoked

I am trying to verify OAuth2RestTemplate patchForObject method is being called with Mockito.verify, but it's not working at all. I have other mocked method which aren't working aswell like getForObject which isn't being stubbed correctly and return the default null instead. Here is my code :

@RunWith(MockitoJUnitRunner.class)
public class ClientPaasTest {
    @Mock
    private OAuth2RestTemplate clientCredentialsRestTemplateMock;

    @InjectMocks
    private ClientPaas clientPaas;

    @Before
    public void setup() {
        Mockito.reset(clientCredentialsRestTemplateMock);
    }
    @Test
    public void testPatchCarteJetonInterac() {
        clientPaas.patchCarteJetonInterac(null, "carte1");   
        Mockito.verify(clientCredentialsRestTemplateMock).patchForObject(null, null, Object.class);
    }
}

And I am obtaining the following error :

Wanted but not invoked:
clientCredentialsRestTemplateMock.patchForObject(
    null,
    null,
    class java.lang.Object
);
-> at com.pmtcartes.util.ClientPaasTest.testPatchCarteJetonInterac
(ClientPaasTest.java:91)

However, there were other interactions with this mock:
clientCredentialsRestTemplateMock.patchForObject(
    null,
    null,
    class java.lang.Object
);
-> at
com.pmtcartes.util.ClientPaas.patchCarteJetonInterac(ClientPaas.java:70)

Which looks exactly the same to me... Anyone has a solution? I've done this multiple time on many other projects. I am uncertain what is happening.

Aucun commentaire:

Enregistrer un commentaire