MockitoPlus Java library
<dependency>
<groupId>io.github.mockitoplus</groupId>
<artifactId>mockitoplus</artifactId>
<version>USE-LATEST-VERSION</version>
<scope>test</scope>
</dependency>
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.thenReturn("bonjour")
.failAlternatingInvocations();
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.thenReturn("bonjour")
.firstInvocationFails();
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.thenReturn("bonjour")
.intermittentFailures();
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.failEveryInvocation();
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.thenReturn("bonjour")
.intermittentFailures()
.exception(() -> new IllegalStateException("sorry"));
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.thenReturn("bonjour")
.fixedDelay(Duration.of(100, MILLIS));
import static org.mockito.Mockito.mock;
import static io.github.mockitoplus.MockitoPlus.when;
Duration lowerBound = Duration.of(1, SECONDS);
Duration upperBound = Duration.of(20, SECONDS);
HelloWorld hello = mock(HelloWorld.class);
when(hello.sayHello(any()))
.thenReturn("bonjour")
.randomDelay(lowerBound, upperBound);
- Every change on the main development branch is released as
-SNAPSHOT
version to Sonatype snapshot repo at https://oss.sonatype.org/content/repositories/snapshots/io/github/mockitoplus/mockitoplus/ - In order to release a non-snapshot version to Maven Central push an annotated tag, for example:
git tag -a -m "Release 0.x.y" v0.x.y
git push origin v0.x.y
- At the moment, you may not create releases from GitHub Web UI. Doing so will make the CI build fail because the CI creates the changelog and posts to GitHub releases. We'll support this in the future.