From 3742218839d757e8b55cab1587e134f72eb92dd3 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 12 Apr 2024 18:29:08 +0200 Subject: [PATCH] Suggestions --- .../refasterrules/ReactorRules.java | 47 ++++++------- .../refasterrules/ReactorRulesTestInput.java | 67 +++++++++---------- .../refasterrules/ReactorRulesTestOutput.java | 53 +++++++-------- 3 files changed, 78 insertions(+), 89 deletions(-) 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 99f5bfa6a4..e9d7c5d38b 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 @@ -1767,13 +1767,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(); } } @@ -1783,13 +1783,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); } } @@ -1906,25 +1906,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); } } @@ -1948,10 +1938,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) @@ -1962,8 +1953,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 587275cdb5..31024e3729 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 d4220669d1..c3e0e614b4 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() {