[java8] Entry points to methods from Mockito API via interfaces

17 views
Skip to first unread message

Marcin Zajączkowski

unread,
Nov 19, 2015, 4:59:49 PM11/19/15
to mocki...@googlegroups.com
Hi guys,

I've enhanced mockito-java8 with the interfaces with default methods
which under the hood delegate to Mockito static methods. Thanks to that
it is enough to implement selected interface to have all those method
available directly without a need to use static imports.

Useful to not have to press ALT-ENTER in Idea a few times in the first
test in a class and even more for Eclipse users (where Mockito classes
have to be explicitly added in Eclipse configuration to make static
imports work at all - can be somehow painful for people starting with
Mockito - experienced many time on my testing/TDD training sessions :) ).

As it could be possibly a part of Mockito one day ;), I would like to
get feedback what do you think about the idea in general before
releasing the new version with it.

In addition I'm not sure how fine grained interfaces are needed.
Proposal to be discussed is here:
https://github.com/szpak/mockito-java8/tree/feature/defaultMethods/src/main/java/info/solidsoft/mockito/java8/api

The solution is fully functional (unless I missed some important methods
:) ), but I still need to find a way how to generate JavaDocs
automatically for those interfaces.

I'm looking forward to hearing from you
Marcin

--
http://blog.solidsoft.info/ - Working code is not enough

Szczepan Faber

unread,
Nov 24, 2015, 10:17:16 AM11/24/15
to mocki...@googlegroups.com
Hey,

I absolutely love the idea!!!

Some feedback:

- the static methods are intended to stay and won't change. Are you
compat with 1.* or 2.* beta? I've changed how the Matchers work a bit
in 2.0
- javadoc does not inform how to use the interfaces (e.g. that the
intention is that the test class should implement the interface) /
does not show the code sample
- it seems confusing to have so many interfaces available. Without
thorough thinking (I'm sure you did yours) it seems that we need 3
interfaces: Mockito, BDDMockito, AdditionalMatchers, right? Javadoc
does not say when should the specific interfaces be used.

This is really cool. I'd love to merge that to Mockito at some point.

Cheers!
> --
> You received this message because you are subscribed to the Google Groups "mockito-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev...@googlegroups.com.
> To post to this group, send email to mocki...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mockito-dev.
> For more options, visit https://groups.google.com/d/optout.



--
Szczepan Faber
Founder mockito.org; Core dev gradle.org
tweets as @szczepiq; blogs at blog.mockito.org

Marcin Zajączkowski

unread,
Nov 24, 2015, 6:44:43 PM11/24/15
to mocki...@googlegroups.com
On 2015-11-24 16:17, Szczepan Faber wrote:
> Hey,
>
> I absolutely love the idea!!!
>
> Some feedback:
>
> - the static methods are intended to stay and won't change. Are you
> compat with 1.* or 2.* beta? I've changed how the Matchers work a bit
> in 2.0

I've noticed that a while ago. Thanks to that mockito-java8 1.x and 2.x
would have to be released :).

> - javadoc does not inform how to use the interfaces (e.g. that the
> intention is that the test class should implement the interface) /
> does not show the code sample

Good point. It's something I like very much in Mockito javadoc. I will
make an update.

> - it seems confusing to have so many interfaces available. Without
> thorough thinking (I'm sure you did yours) it seems that we need 3
> interfaces: Mockito, BDDMockito, AdditionalMatchers, right? Javadoc
> does not say when should the specific interfaces be used.

To simplify the things I've just reduced number of public interfaces to 3:
- WithMockito - BDD and classic stubbing/mocking API - I see no sense
to keep BDD separately - more people should use it :)
- WithMockitoAndMatchers - mocking API + Mockito matchers

- WithMatchers - just Mockito matchers - in some cases people could
prefer to have only Mockito methods "imported". Nevertheless
WithMockitoAndMatchers can be used instead, so I'm seriously considering
its removal from the API.

All other interfaces are with package scope to no being suggested by IDE.

WDYT?

Marcin

Szczepan Faber

unread,
Nov 26, 2015, 5:31:42 PM11/26/15
to mocki...@googlegroups.com
Hey,

Great stuff!!!

>To simplify the things I've just reduced number of public interfaces to 3

I think the biggest simplicity is when you mirror the original Mockito
classes + the 'With' prefix. This way they can be later on merged to
Mockito codebase.

For Mockito 2.* I'm wondering if we can compile those extra classes
with java8 compat and include them in the distro.

Cheers!
Reply all
Reply to author
Forward
0 new messages