Re: [mockito] Validate that an empty method really did nothing

986 views
Skip to first unread message

Eric Lefevre-Ardant

unread,
Feb 6, 2013, 9:20:40 AM2/6/13
to moc...@googlegroups.com

Well, you could use verifyZeroInteractions() on each dependency.

That said, I don't think there is much value in this kind of tests. After all, when you test normal methods, you don't usually check that the method has done nothing else at all. That would seem too strict and rigid.

Eric

On Feb 6, 2013 2:57 PM, <eric....@gmail.com> wrote:

Hi,
Sometimes classes implement interface and need to implement only some of the methods, not all. The method it does not need remains empty. Using this example

public void initialize(Object context) {
    // do nothing and return nothing
}

How can I validate (or assert) that, when being called, this method really did nothing as expected?

Thanks

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Adrian Elsener

unread,
Feb 7, 2013, 2:02:29 AM2/7/13
to moc...@googlegroups.com
Hi

all you can verify is, there are no interactions with context nor other
objects you ever passed to your Object under test.

But you will not be able to check if there were nothing done with the
state self... If you want to check this, I think there is no easy way...

You could do something like reflective checksum calculation.

Cheers
Adrian
Reply all
Reply to author
Forward
0 new messages