mocking events / functions with optional parameters

191 views
Skip to first unread message

Roaders

unread,
Jul 8, 2010, 8:30:33 AM7/8/10
to mockito-flex
Hi

Firstly I think an easier way of mocking events would be a good idea:

mockito.mockEvents( myDelegate );

at the moment you have to do something along the lines of this:

mockito.given( myDelegate.addEventListener( mockito.any(),
mockito.any() ) ).will( mockito.callOriginal() );
mockito.given( myDelegate.dispatchEvent( mockito.any() ) ).will( mockito.callOriginal() );

and my second point - it would be nice if you didn't have to specify
every variation of optionally passed parameters. To make the above
bulletproof I have to do this:

mockito.given( myDelegate.addEventListener( mockito.any(),
mockito.any() ) ).will( mockito.callOriginal() );
mockito.given( myDelegate.addEventListener( mockito.any(),
mockito.any(), mockito.any() ) ).will( mockito.callOriginal() );
mockito.given( myDelegate.addEventListener( mockito.any(),
mockito.any(), mockito.any(),
mockito.any() ) ).will( mockito.callOriginal() );
mockito.given( myDelegate.addEventListener( mockito.any(),
mockito.any(), mockito.any(), mockito.any(),
mockito.any() ) ).will( mockito.callOriginal() );
mockito.given( myDelegate.dispatchEvent( mockito.any() ) ).will( mockito.callOriginal() );

perhaps an anyOrNone() call would sort that:

mockito.given( myDelegate.addEventListener( mockito.any(),
mockito.any(), mockito.anyOrNone(), mockito.anyOrNone(),
mockito.anyOrNone() ) ).will( mockito.callOriginal() );
mockito.given( myDelegate.dispatchEvent( mockito.any() ) ).will( mockito.callOriginal() );

Apologies if this second suggestion is already catered for.

Kris

unread,
Jul 8, 2010, 9:10:49 AM7/8/10
to mockit...@googlegroups.com
Hi,

Thanks for the suggestions.

On mockEvents() - I'm not sure if I want this specific feature in a framework. Instead of mocking it actually turns on 'real' event dispatching on your subject. So it's more in a spirit of the partial mocks that I have a reservation for. However I can understand your motivation and I'm open to hear from the others :) - if more people wants it I'll add something like:

withTrueDispatching(*:mock):*

But you know what? Mockito has been written with high adaptability in mind ;).

The org.mockito.integrations.currentMockito provides access to the current Mockito instance (the same one used by the executed test). You could write a convenience function that uses currentMockito and registers all the steps for you.


The optional arguments is something that's been around for a while. I'll see if this is something I can figure out during function matching.

Regards,
Kris


--
You received this message because you are subscribed to the Google Groups "mockito-flex" group.
To post to this group, send email to mockit...@googlegroups.com.
To unsubscribe from this group, send email to mockito-flex...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito-flex?hl=en.


loomis

unread,
Aug 26, 2010, 4:55:43 PM8/26/10
to mockito-flex
I created issues #24 and #25 for above proposals.

Kris
Reply all
Reply to author
Forward
0 new messages