From 787b32592fda308a8577966634796a735d8d3829 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 ef0734e2da0..34988de4e57 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 @@ -1397,4 +1397,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 3a15f612b9e..8ee932d952a 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 @@ -446,4 +446,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 67812db80fd..353b67184ec 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 @@ -435,4 +435,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(); + } }