mardi 12 avril 2016

How to verify invocations of the same mock method with the same argument that changes state between invocations in mockito?

I have the following code to be unit tested:

public void foo() {
    Entity entity = //...
    persistence.save(entity);
    entity.setDate(new Date());
    persistence.save(entity);
}

I would like to verify that on the first invocation of persistence.save entity.getDate() returns null.

Therefore I'm unable to use Mockito.verify(/*...*/) because at that time the method foo already completed and entity.setDate(Date) was called.

So I think I need to do verifications of invocations already at the time the invocations happen. How do I do this using Mockito?

Aucun commentaire:

Enregistrer un commentaire