Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ExpectedException in MissingInvocationInOrderCheckerTest #2511

Merged
merged 1 commit into from Dec 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,13 +7,13 @@
import static java.util.Arrays.asList;

import static org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.List;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.exceptions.verification.VerificationInOrderFailure;
import org.mockito.exceptions.verification.WantedButNotInvoked;
Expand All @@ -34,8 +34,6 @@ public class MissingInvocationInOrderCheckerTest {

@Mock private IMethods mock;

@Rule public ExpectedException exception = ExpectedException.none();

@Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

private InOrderContext context = new InOrderContextImpl();
Expand All @@ -57,26 +55,29 @@ public void shouldReportWantedButNotInvoked() throws Exception {
invocations = asList(buildDifferentMethod().toInvocation());
wanted = buildSimpleMethod().toInvocationMatcher();

exception.expect(WantedButNotInvoked.class);
exception.expectMessage("Wanted but not invoked:");
exception.expectMessage("mock.simpleMethod()");

checkMissingInvocation(invocations, wanted, context);
assertThatThrownBy(
() -> {
checkMissingInvocation(invocations, wanted, context);
})
.isInstanceOf(WantedButNotInvoked.class)
.hasMessageContainingAll("Wanted but not invoked:", "mock.simpleMethod()");
}

@Test
public void shouldReportArgumentsAreDifferent() throws Exception {
invocations = asList(buildIntArgMethod().arg(1111).toInvocation());
wanted = buildIntArgMethod().arg(2222).toInvocationMatcher();

exception.expect(ArgumentsAreDifferent.class);

exception.expectMessage("Argument(s) are different! Wanted:");
exception.expectMessage("mock.intArgumentMethod(2222);");
exception.expectMessage("Actual invocations have different arguments:");
exception.expectMessage("mock.intArgumentMethod(1111);");

checkMissingInvocation(invocations, wanted, context);
assertThatThrownBy(
() -> {
checkMissingInvocation(invocations, wanted, context);
})
.isInstanceOf(ArgumentsAreDifferent.class)
.hasMessageContainingAll(
"Argument(s) are different! Wanted:",
"mock.intArgumentMethod(2222);",
"Actual invocations have different arguments:",
"mock.intArgumentMethod(1111);");
}

@Test
Expand All @@ -89,15 +90,17 @@ public void shouldReportWantedDiffersFromActual() throws Exception {
invocations = asList(invocation1, invocation2);
wanted = buildIntArgMethod().arg(2222).toInvocationMatcher();

exception.expect(VerificationInOrderFailure.class);

exception.expectMessage("Verification in order failure");
exception.expectMessage("Wanted but not invoked:");
exception.expectMessage("mock.intArgumentMethod(2222);");
exception.expectMessage("Wanted anywhere AFTER following interaction:");
exception.expectMessage("mock.intArgumentMethod(2222);");

checkMissingInvocation(invocations, wanted, context);
assertThatThrownBy(
() -> {
checkMissingInvocation(invocations, wanted, context);
})
.isInstanceOf(VerificationInOrderFailure.class)
.hasMessageContainingAll(
"Verification in order failure",
"Wanted but not invoked:",
"mock.intArgumentMethod(2222);",
"Wanted anywhere AFTER following interaction:",
"mock.intArgumentMethod(2222);");
}

private InvocationBuilder buildIntArgMethod() {
Expand Down