From ebeec96b13c204b2e6e9d2c33c5dabf186707af1 Mon Sep 17 00:00:00 2001 From: Giovanni Zotta Date: Mon, 8 May 2023 00:47:03 +0200 Subject: [PATCH] Initial implementation --- .../errorprone/refasterrules/ReactorRules.java | 16 ++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 8 ++++++++ .../refasterrules/ReactorRulesTestOutput.java | 4 ++++ 3 files changed, 28 insertions(+) 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 c30bbd11df4..f451c94a7f1 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 @@ -1414,4 +1414,20 @@ Duration after(StepVerifier.LastStep step, Duration duration) { return step.verifyTimeout(duration); } } + + /** Avoid collecting when verifying only the given element is in the given {@link Flux}. */ + static final class VerifyOnlyElementInFlux { + @BeforeTemplate + Duration before(Flux flux, T object) { + return flux.collect(toImmutableList()) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(object)) + .verifyComplete(); + } + + @AfterTemplate + Duration after(Flux flux, T object) { + return flux.as(StepVerifier::create).expectNext(object).verifyComplete(); + } + } } 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 18ce1d1dab7..410d36fed03 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 @@ -450,4 +450,12 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).expectTimeout(Duration.ZERO).verify(); } + + Duration testVerifyOnlyElementInFlux() { + return Flux.just(1) + .collect(toImmutableList()) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(1)) + .verifyComplete(); + } } 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 c44d57e0ff2..62cf1b9c9d0 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 @@ -439,4 +439,8 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).verifyTimeout(Duration.ZERO); } + + Duration testVerifyOnlyElementInFlux() { + return Flux.just(1).as(StepVerifier::create).expectNext(1).verifyComplete(); + } }