I have a service that saves an object. I create an instance of the service and save the object.
Service service;
...
service.save(obj);
In my test I mock the service instance and do the following:
@Mock
Service service;
...
@Test
public void test1{
...
when(service.save(obj)).thenReturn(-1);
}
The problem is, the actual method is getting called and a NullPointerException is being thrown. I do not want the method to be called.
I'm assuming the Object "obj" in both cases are the same since they return the same memory location on printing them. Also, I tried to use ArgumentCaptor but even that calls the method and throws an Exception before verifying whether the objects are equal.
Any ideas on what could be happening here?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire