infinite / mockito-flex

0 stars 0 forks source link

Allow ensuring no more interactions made on mock #26

Open infinite opened 9 years ago

infinite commented 9 years ago

Add:

verifyNoMoreInteractions(...mocks)

that ensures there are no more interactions made on given mocks. If nothing given, all the mocks should be examined.

infinite commented 9 years ago

From Darren Bishop on 2011-04-20 09:09:04+00:00

I have implemented a verifyAll(test:*) function that, if used on it's own, should be called from an [After] annotated method. The test parameter expected should be passed a reference to the running test i.e. this.

I have also implemented a VerifyMocks async-statement to be used with the MockitoClassRunner or MockitoRule; VerifyMocks simply delegates to verifyAll().

verifyAll() utilises the MockInterceptor to perform the invocation checks - automatic verification with VerifyMocks is more convenient, but both MockitoClassRunner and MockitoRule need to be modified to use it.

Please find code and example modifications attached; the MockitoClassRunner and MockitoRule modifications include a check for [Test(verify='false')].

infinite commented 9 years ago

From loomis on 2011-04-20 09:16:30+00:00

Thanks for the contribution!

I'll review it later this week and include into the next release.

Regards, Kris

infinite commented 9 years ago

From Darren Bishop on 2011-06-18 19:11:13+00:00

I've found two bugs that prevent this from working:

From other mocking code that I've looked at (i.e. the Python version) I feel stubbed invocations should be tracked separately to normal invocations and normal invocations should not exist as duplicates to stubbed invocations if they match.

I made the following changes in InvocationsImpl.as to:

...allow recognition of manually verified invocations: {{{

!as3

public function countMatchingInvocations(wanted:Invocation):int { var counter:int; for each (var iv:Invocation in getEncounteredInvocations()) { if (wanted.matches(iv)) { counter ++; iv.verified = true; // <---- mark as matching for verifyAll(...) } } return counter; } }}}

...allow recognition of stubbed invocations: {{{

!as3

public function answerFor(actualInvocation:Invocation):* { for each (var invocation:Invocation in invocations.source) { if (invocation.isStubbed() && invocation.matches(actualInvocation)) { actualInvocation.verified = true; // <---- mark as matching for verifyAll(...) return invocation.answer(actualInvocation.stubbingContext); } } return null; } }}}

I don't think the designs really supports these changes go there i.e. just counting matches shouldn't make them verified, but there isn't a better place to put it.

What do you think?