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 3ce7bef77b..8999c921c0 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 @@ -1758,13 +1758,13 @@ StepVerifier.FirstStep after(Flux flux) { */ static final class StepVerifierVerify { @BeforeTemplate - void before(StepVerifier stepVerifier) { - stepVerifier.verifyThenAssertThat(); + StepVerifier.Assertions before(StepVerifier stepVerifier) { + return stepVerifier.verifyThenAssertThat(); } @AfterTemplate - void after(StepVerifier stepVerifier) { - stepVerifier.verify(); + Duration after(StepVerifier stepVerifier) { + return stepVerifier.verify(); } } @@ -1774,13 +1774,13 @@ void after(StepVerifier stepVerifier) { */ static final class StepVerifierVerifyDuration { @BeforeTemplate - void before(StepVerifier stepVerifier, Duration duration) { - stepVerifier.verifyThenAssertThat(duration); + StepVerifier.Assertions before(StepVerifier stepVerifier, Duration duration) { + return stepVerifier.verifyThenAssertThat(duration); } @AfterTemplate - void after(StepVerifier stepVerifier, Duration duration) { - stepVerifier.verify(duration); + Duration after(StepVerifier stepVerifier, Duration duration) { + return stepVerifier.verify(duration); } } @@ -1897,25 +1897,15 @@ Duration before(StepVerifier.LastStep step, Predicate predicate) { return step.expectErrorMatches(predicate).verify(); } - @AfterTemplate - Duration after(StepVerifier.LastStep step, Predicate predicate) { - return step.verifyErrorMatches(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); + @SuppressWarnings("StepVerifierVerify" /* This is a more specific template. */) + StepVerifier.Assertions before2(StepVerifier.LastStep step, Predicate predicate) { + return step.expectError().verifyThenAssertThat().hasOperatorErrorMatching(predicate); } @AfterTemplate - void after(StepVerifier.LastStep step, Predicate predicate) { - step.verifyErrorMatches(predicate); + Duration after(StepVerifier.LastStep step, Predicate predicate) { + return step.verifyErrorMatches(predicate); } } @@ -1939,10 +1929,11 @@ Duration after(StepVerifier.LastStep step, Consumer consumer) { * Prefer {@link StepVerifier.LastStep#verifyErrorSatisfies(Consumer)} with AssertJ over more * contrived alternatives. */ - static final class StepVerifierLastStepVerifyErrorSatisfiesAssertJ { + static final class StepVerifierLastStepVerifyErrorSatisfiesAssertJ { @BeforeTemplate - void before(StepVerifier.LastStep step, Class clazz, String message) { - Refaster.anyOf( + @SuppressWarnings("StepVerifierVerify" /* This is a more specific template. */) + StepVerifier.Assertions before(StepVerifier.LastStep step, Class clazz, String message) { + return Refaster.anyOf( step.expectError() .verifyThenAssertThat() .hasOperatorErrorOfType(clazz) @@ -1953,8 +1944,8 @@ void before(StepVerifier.LastStep step, Class clazz, String @AfterTemplate @UseImportPolicy(STATIC_IMPORT_ALWAYS) - void after(StepVerifier.LastStep step, Class clazz, String message) { - step.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(clazz).hasMessage(message)); + Duration after(StepVerifier.LastStep step, Class clazz, String message) { + return step.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(clazz).hasMessage(message)); } } 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 404d102350..3b32771ece 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 @@ -592,12 +592,12 @@ StepVerifier.FirstStep testStepVerifierFromFlux() { return StepVerifier.create(Flux.just(1)); } - void testStepVerifierVerify() { - Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat(); + Object testStepVerifierVerify() { + return Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat(); } - void testStepVerifierVerifyDuration() { - Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat(Duration.ZERO); + Object testStepVerifierVerifyDuration() { + return Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat(Duration.ZERO); } StepVerifier testStepVerifierVerifyLater() { @@ -644,42 +644,41 @@ ImmutableSet testStepVerifierLastStepVerifyErrorClass() { .verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(AssertionError.class))); } - Duration testStepVerifierLastStepVerifyErrorMatches() { - return Mono.empty() - .as(StepVerifier::create) - .expectErrorMatches(IllegalArgumentException.class::equals) - .verify(); - } - - void testStepVerifierLastStepVerifyErrorMatchesAssertions() { - Mono.empty() - .as(StepVerifier::create) - .expectError() - .verifyThenAssertThat() - .hasOperatorErrorMatching(IllegalArgumentException.class::equals); + ImmutableSet testStepVerifierLastStepVerifyErrorMatches() { + return ImmutableSet.of( + Mono.empty() + .as(StepVerifier::create) + .expectErrorMatches(IllegalArgumentException.class::equals) + .verify(), + Mono.empty() + .as(StepVerifier::create) + .expectError() + .verifyThenAssertThat() + .hasOperatorErrorMatching(IllegalStateException.class::equals)); } Duration testStepVerifierLastStepVerifyErrorSatisfies() { return Mono.empty().as(StepVerifier::create).expectErrorSatisfies(t -> {}).verify(); } - void testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() { - Mono.empty() - .as(StepVerifier::create) - .expectError() - .verifyThenAssertThat() - .hasOperatorErrorOfType(IllegalStateException.class) - .hasOperatorErrorWithMessage("foo"); - Mono.empty() - .as(StepVerifier::create) - .expectError(IllegalStateException.class) - .verifyThenAssertThat() - .hasOperatorErrorWithMessage("bar"); - Mono.empty() - .as(StepVerifier::create) - .expectErrorMessage("baz") - .verifyThenAssertThat() - .hasOperatorErrorOfType(IllegalStateException.class); + ImmutableSet testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() { + return ImmutableSet.of( + Mono.empty() + .as(StepVerifier::create) + .expectError() + .verifyThenAssertThat() + .hasOperatorErrorOfType(IllegalArgumentException.class) + .hasOperatorErrorWithMessage("foo"), + Mono.empty() + .as(StepVerifier::create) + .expectError(IllegalStateException.class) + .verifyThenAssertThat() + .hasOperatorErrorWithMessage("bar"), + Mono.empty() + .as(StepVerifier::create) + .expectErrorMessage("baz") + .verifyThenAssertThat() + .hasOperatorErrorOfType(AssertionError.class)); } Duration testStepVerifierLastStepVerifyErrorMessage() { 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 ac3f19c27e..7806946590 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 @@ -581,12 +581,12 @@ StepVerifier.FirstStep testStepVerifierFromFlux() { return Flux.just(1).as(StepVerifier::create); } - void testStepVerifierVerify() { - Mono.empty().as(StepVerifier::create).expectError().verify(); + Object testStepVerifierVerify() { + return Mono.empty().as(StepVerifier::create).expectError().verify(); } - void testStepVerifierVerifyDuration() { - Mono.empty().as(StepVerifier::create).expectError().verify(Duration.ZERO); + Object testStepVerifierVerifyDuration() { + return Mono.empty().as(StepVerifier::create).expectError().verify(Duration.ZERO); } StepVerifier testStepVerifierVerifyLater() { @@ -626,35 +626,34 @@ ImmutableSet testStepVerifierLastStepVerifyErrorClass() { Mono.empty().as(StepVerifier::create).verifyError(AssertionError.class)); } - Duration testStepVerifierLastStepVerifyErrorMatches() { - return Mono.empty() - .as(StepVerifier::create) - .verifyErrorMatches(IllegalArgumentException.class::equals); - } - - void testStepVerifierLastStepVerifyErrorMatchesAssertions() { - Mono.empty() - .as(StepVerifier::create) - .verifyErrorMatches(IllegalArgumentException.class::equals); + ImmutableSet testStepVerifierLastStepVerifyErrorMatches() { + return ImmutableSet.of( + Mono.empty() + .as(StepVerifier::create) + .verifyErrorMatches(IllegalArgumentException.class::equals), + Mono.empty() + .as(StepVerifier::create) + .verifyErrorMatches(IllegalStateException.class::equals)); } Duration testStepVerifierLastStepVerifyErrorSatisfies() { return Mono.empty().as(StepVerifier::create).verifyErrorSatisfies(t -> {}); } - void testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() { - Mono.empty() - .as(StepVerifier::create) - .verifyErrorSatisfies( - t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("foo")); - Mono.empty() - .as(StepVerifier::create) - .verifyErrorSatisfies( - t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("bar")); - Mono.empty() - .as(StepVerifier::create) - .verifyErrorSatisfies( - t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("baz")); + ImmutableSet testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() { + return ImmutableSet.of( + Mono.empty() + .as(StepVerifier::create) + .verifyErrorSatisfies( + t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("foo")), + Mono.empty() + .as(StepVerifier::create) + .verifyErrorSatisfies( + t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("bar")), + Mono.empty() + .as(StepVerifier::create) + .verifyErrorSatisfies( + t -> assertThat(t).isInstanceOf(AssertionError.class).hasMessage("baz"))); } Duration testStepVerifierLastStepVerifyErrorMessage() {