Convenience Extension to use mockito without static imports.
Inspired by https://blog.javabien.net/2014/04/23/what-if-assertj-used-java-8/ and https://github.com/szpak/mockito-java8
- Java >= 8
- Mockito >= 3.2.4
The version corresponds with the used version of mockito, so the same version can be used for both. The first release exists for mockito 3.2.4
<dependency>
<groupId>eu.benschroeder</groupId>
<artifactId>mockito-extension</artifactId>
<version>${mockito.version}</version>
</dependency>
import eu.benschroeder.mockito.WithMockito;
class MyUnitTest implements WithMockito {
@Test
void testAnyMethod() {
String anyParam = randomAlphabetic();
when(myService.anyMethod(anyParam)).thenReturn("anyReturnValue");
...
verify(myService, times(2)).anyMethod(anyParam);
verify(myService, never()).anyOtherMethod(anyParam);
}
}
import eu.benschroeder.mockito.WithBDDMockito;
class MyBDDStyleUnitTest implements WithBDDMockito {
@Test
void testAnyMethod() {
String anyParam = randomAlphabetic();
given(myService.anyMethod(anyParam)).willReturn("anyReturnValue");
...
then(myService).should().anyMethod(anyParam);
then(myService).should(never()).anyOtherMethod(anyParam);
}
}