diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index df5559ec8e..3166ce36f7 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1913,6 +1913,22 @@ Duration after(StepVerifier.LastStep step, Predicate predicate) { } } + /** + * Prefer {@link StepVerifier.LastStep#verifyErrorMatches(Predicate)} over more verbose + * alternatives. + */ + static final class StepVerifierLastStepVerifyErrorMatchesAssertions { + @BeforeTemplate + void before(StepVerifier.LastStep step, Predicate predicate) { + step.expectError().verifyThenAssertThat().hasOperatorErrorMatching(predicate); + } + + @AfterTemplate + void after(StepVerifier.LastStep step, Predicate predicate) { + step.verifyErrorMatches(predicate); + } + } + /** * Prefer {@link StepVerifier.LastStep#verifyErrorSatisfies(Consumer)} over more verbose * alternatives. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 0e5fdaaa6a..587275cdb5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -651,6 +651,14 @@ Duration testStepVerifierLastStepVerifyErrorMatches() { .verify(); } + void testStepVerifierLastStepVerifyErrorMatchesAssertions() { + Mono.empty() + .as(StepVerifier::create) + .expectError() + .verifyThenAssertThat() + .hasOperatorErrorMatching(IllegalArgumentException.class::equals); + } + Duration testStepVerifierLastStepVerifyErrorSatisfies() { return Mono.empty().as(StepVerifier::create).expectErrorSatisfies(t -> {}).verify(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index dd50924a2a..d4220669d1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -632,6 +632,12 @@ Duration testStepVerifierLastStepVerifyErrorMatches() { .verifyErrorMatches(IllegalArgumentException.class::equals); } + void testStepVerifierLastStepVerifyErrorMatchesAssertions() { + Mono.empty() + .as(StepVerifier::create) + .verifyErrorMatches(IllegalArgumentException.class::equals); + } + Duration testStepVerifierLastStepVerifyErrorSatisfies() { return Mono.empty().as(StepVerifier::create).verifyErrorSatisfies(t -> {}); }