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 02e7fb0de13..7f606e23ed1 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 @@ -1328,6 +1328,28 @@ StepVerifier.Step after(StepVerifier.Step step, T object) { } } + /** Avoid collecting when verifying only the given element is in the given {@link Flux}. */ + static final class FluxAsStepVerifierExpectNext { + @BeforeTemplate + StepVerifier.Step> before(Flux flux, T object) { + return flux.collect(toImmutableList()) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(object)); + } + + @BeforeTemplate + StepVerifier.Step> before2(Flux flux, T object) { + return flux.collect(toImmutableSet()) + .as(StepVerifier::create) + .assertNext(set -> assertThat(set).containsExactly(object)); + } + + @AfterTemplate + StepVerifier.Step after(Flux flux, T object) { + return flux.as(StepVerifier::create).expectNext(object); + } + } + /** Prefer {@link StepVerifier.LastStep#verifyComplete()} over more verbose alternatives. */ static final class StepVerifierLastStepVerifyComplete { @BeforeTemplate @@ -1430,20 +1452,4 @@ 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 18e9192d80d..74f44d061bf 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 @@ -1,6 +1,7 @@ package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.MoreCollectors.toOptional; import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; @@ -422,6 +423,20 @@ ImmutableSet> testStepVerifierStepExpectNext() { StepVerifier.create(Mono.just("baz")).expectNextMatches("qux"::equals)); } + ImmutableSet testFluxAsStepVerifierExpectNext() { + return ImmutableSet.of( + Flux.just(1) + .collect(toImmutableList()) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(2)) + .verifyComplete(), + Flux.just(3) + .collect(toImmutableSet()) + .as(StepVerifier::create) + .assertNext(set -> assertThat(set).containsExactly(4)) + .verifyComplete()); + } + Duration testStepVerifierLastStepVerifyComplete() { return StepVerifier.create(Mono.empty()).expectComplete().verify(); } @@ -454,12 +469,4 @@ 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 252a11ed33c..1136b736a59 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 @@ -413,6 +413,12 @@ ImmutableSet> testStepVerifierStepExpectNext() { StepVerifier.create(Mono.just("baz")).expectNext("qux")); } + ImmutableSet testFluxAsStepVerifierExpectNext() { + return ImmutableSet.of( + Flux.just(1).as(StepVerifier::create).expectNext(2).verifyComplete(), + Flux.just(3).as(StepVerifier::create).expectNext(4).verifyComplete()); + } + Duration testStepVerifierLastStepVerifyComplete() { return StepVerifier.create(Mono.empty()).verifyComplete(); } @@ -443,8 +449,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).verifyTimeout(Duration.ZERO); } - - Duration testVerifyOnlyElementInFlux() { - return Flux.just(1).as(StepVerifier::create).expectNext(1).verifyComplete(); - } }