Releases: szpak/mockito-java8
2.0.0-beta.2 - adjust API to changes in mockito-2.0.32-beta
#7 - Bug with throwing exception from void method using WithBDDMockito
Compatibility note. This is release can throw runtime exceptions with mockito <2.0.32-beta when certain changed methods are used.
2.0.0-beta - Mockito API methods available via interfaces (without static imports)
The new Mockito API methods available via interfaces allow to use methods from Mockito API without the need to use static imports. It is enough to make your test class implement WithBDDMockito
interface to have all methods from stubbing/mockito Mockito API available directly.
Please note: Versions 2.x are for 2.0.22-beta and newer. See versions 1.x for Mockito 1.10.x and earlier Mockito 2 betas.
//no need to use static imports!
public class SpaceShipTest implements WithBDDMockito {
@Test
public void shouldVerifyMethodExecution() {
//given
TacticalStation tsSpy = spy(TacticalStation.class);
willDoNothing().given(tsSpy).fireTorpedo(2);
//when
tsSpy.fireTorpedo(2);
tsSpy.fireTorpedo(2);
//then
then(tsSpy).should(times(2)).fireTorpedo(2);
}
}
The same code would work fine with a bunch of static imports. Of course they can be hidden in IDE and usually do not disturb much. Nevertheless to be able to write just a method name (e.g. mock(TacticalStation.class)
) without a class is it required to press ALT-ENTER (in IntelliJ IDEA) to add each static import on the first usage of a given method in a test class. The situation is even worse in Eclipse where it is required to earlier add BDDMockito
to "Favorites" in "Content Assist" to make it suggested by IDE.
Mockito methods are provided by 3 base interfaces, being an entry point for given set of methods:
WithBDDMockito
- stubbing/mocking API in BDD styleWithMockito
- classic stubbing/mocking APIWithAdditionalMatchers
- additional matchers
1.0.0-beta - Mockito API methods available via interfaces (without static imports)
The new Mockito API methods available via interfaces allow to use methods from Mockito API without the need to use static imports. It is enough to make your test class implement WithBDDMockito
interface to have all methods from stubbing/mockito Mockito API available directly.
Please note: Version 1.x are for Mockito 1.10.12+ and 2.0.x-beta up to 2.0.21-beta. See versions 2.x for newer Mockito 2 versions support.
//no need to use static imports!
public class SpaceShipTest implements WithBDDMockito {
@Test
public void shouldVerifyMethodExecution() {
//given
TacticalStation tsSpy = spy(TacticalStation.class);
willDoNothing().given(tsSpy).fireTorpedo(2);
//when
tsSpy.fireTorpedo(2);
tsSpy.fireTorpedo(2);
//then
then(tsSpy).should(times(2)).fireTorpedo(2);
}
}
The same code would work fine with a bunch of static imports. Of course they can be hidden in IDE and usually do not disturb much. Nevertheless to be able to write just a method name (e.g. mock(TacticalStation.class)
) without a class is it required to press ALT-ENTER (in IntelliJ IDEA) to add each static import on the first usage of a given method in a test class. The situation is even worse in Eclipse where it is required to earlier add BDDMockito
to "Favorites" in "Content Assist" to make it suggested by IDE.
Mockito methods are provided by 3 base interfaces, being an entry point for given set of methods:
WithBDDMockito
- stubbing/mocking API in BDD styleWithMockito
- classic stubbing/mocking APIWithAdditionalMatchers
- additional matchers
0.3.1 - Fix compatibility with Java 8u60+
#2 - Runtime exceptions for AssertionMatcher if used with Java 8u60 and 8u65