kaisalmon / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Feature request/idea - "No more interactions" for a single method only #501

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I need to verify interaction with a mock, but ignoring most of mock's method 
calls except for one. And for that important method, I would like to be able to 
assert "verify no more interactions".

Currently there is no way to do that - verifyNoMoreInteractions() considers all 
method invocations, not just some particular one. I also tried to use inOrder + 
never() but it only lets me catch unexpected interactions at the end of the 
chain of calls. InOrder does not catch cases when extra interactions happen for 
the same method, i.e.

inOrder.verify(mock).call(1);
inOrder.verify(mock).call(3);
inOrder.verify(mock, never()).call(anyInt());

with the code under test does not catch invocation #2:

m.call(1);
m.call(2); // not caught!
m.call(3);
m.call(4); // caught!

What is the expected output? What do you see instead?

This is perfectly understandable for inOrder, however it would be nice to be 
able to verify that some method is no longer called, regardless of other 
methods... either as a feature of inOrder, which limits it to 1 method only, or 
as a feature of verifyNoMoreInteractions() where specific methods are being 
checked, not all methods of a mock(s).

What version of the product are you using? On what operating system?

Mockito 1.9.0, RHEL5

Original issue reported on code.google.com by b.traffi...@gmail.com on 12 Sep 2014 at 8:03

GoogleCodeExporter commented 8 years ago
I think it makes sense to me. Brice, wdyt?

Do you have any API suggestions?

Original comment by szcze...@gmail.com on 15 Sep 2014 at 6:09

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
If last question was to me, then after thinking about it more I don't see a 
nice way to model it as an InOrder feature... Overloading it in 
verifyNoMoreInteractions may also be confusing. Perhaps verify(mock, 
nomore()).call(...) - and leave it to matchers to capture either any() 
invocation or a subset of them.

Original comment by b.traffi...@gmail.com on 16 Sep 2014 at 12:31

GoogleCodeExporter commented 8 years ago
it could be something like:

verify(mock, noMoreInteractions()).method()

I was actually thinking about Brice, one of the team members :) Your feedback 
is greatly appreciated as you are the client of this feature!

Original comment by szcze...@gmail.com on 16 Sep 2014 at 12:16