From b91bd29be1925a76ec278c8b9536f6092390fc6d Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 14 Dec 2021 11:48:55 +0100 Subject: [PATCH] Replace ExpectedException in MissingInvocationInOrderCheckerTest (#2511) As part of #2510 --- .../MissingInvocationInOrderCheckerTest.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/mockito/internal/verification/checkers/MissingInvocationInOrderCheckerTest.java b/src/test/java/org/mockito/internal/verification/checkers/MissingInvocationInOrderCheckerTest.java index 7ce7907ef7..899d0d3bc8 100644 --- a/src/test/java/org/mockito/internal/verification/checkers/MissingInvocationInOrderCheckerTest.java +++ b/src/test/java/org/mockito/internal/verification/checkers/MissingInvocationInOrderCheckerTest.java @@ -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; @@ -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(); @@ -57,11 +55,12 @@ 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 @@ -69,14 +68,16 @@ 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 @@ -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() {