From 607539557391d24debe47b452a1fcddffaa5a98a Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 7 Oct 2023 00:22:11 +0200 Subject: [PATCH] Cover more cases --- .../refasterrules/ReactorRules.java | 55 ++++++++++++++++++- .../refasterrules/ReactorRulesTestInput.java | 25 ++++++++- .../refasterrules/ReactorRulesTestOutput.java | 30 +++++++++- 3 files changed, 103 insertions(+), 7 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 5092c3fa24d..cb3de8203c5 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 @@ -427,16 +427,52 @@ Flux after(Flux flux, T object) { } /** Prefer {@link Flux#empty()} over more contrived alternatives. */ - static final class FluxEmpty { + // XXX: In combination with the `IsEmpty` matcher introduced by + // https://github.com/PicnicSupermarket/error-prone-support/pull/744, the non-varargs overloads of + // most methods referenced here can be rewritten as well. Additionally, some invocations of + // methods such as `Flux#fromIterable`, `Flux#fromArray` and `Flux#justOrEmpty` can also be + // rewritten. + static final class FluxEmpty> { @BeforeTemplate - Flux before() { + Flux before( + int prefetch, + Function combinator, + Comparator comparator) { return Refaster.anyOf( Flux.concat(), Flux.concatDelayError(), Flux.firstWithSignal(), Flux.just(), Flux.merge(), - Flux.mergeSequential()); + Flux.merge(prefetch), + Flux.mergeComparing(comparator), + Flux.mergeComparing(prefetch, comparator), + Flux.mergeComparingDelayError(prefetch, comparator), + Flux.mergeDelayError(prefetch), + Flux.mergePriority(comparator), + Flux.mergePriority(prefetch, comparator), + Flux.mergePriorityDelayError(prefetch, comparator), + Flux.mergeSequential(), + Flux.mergeSequential(prefetch), + Flux.mergeSequentialDelayError(prefetch), + Flux.zip(combinator), + Flux.zip(combinator, prefetch)); + } + + @BeforeTemplate + Flux before(int prefetch, Function combinator) { + return Refaster.anyOf( + Flux.combineLatest(combinator), Flux.combineLatest(combinator, prefetch)); + } + + @BeforeTemplate + Flux before() { + return Refaster.anyOf(Flux.mergeComparing(), Flux.mergePriority()); + } + + @BeforeTemplate + Flux before(int start) { + return Flux.range(start, 0); } @AfterTemplate @@ -445,6 +481,19 @@ Flux after() { } } + /** Prefer {@link Flux#just(Object)} over more contrived alternatives. */ + static final class FluxJust { + @BeforeTemplate + Flux before(int start) { + return Flux.range(start, 1); + } + + @AfterTemplate + Flux after(int start) { + return Flux.just(start); + } + } + /** Don't unnecessarily transform a {@link Mono} to an equivalent instance. */ static final class MonoIdentity { @BeforeTemplate 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 96e1649171b..29d57f4a863 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 @@ -148,14 +148,35 @@ ImmutableSet> testFluxDefaultIfEmpty() { Flux.just("baz").switchIfEmpty(Flux.just("qux"))); } - ImmutableSet> testFluxEmpty() { + ImmutableSet> testFluxEmpty() { return ImmutableSet.of( Flux.concat(), Flux.concatDelayError(), Flux.firstWithSignal(), Flux.just(), Flux.merge(), - Flux.mergeSequential()); + Flux.merge(1), + Flux.mergeComparing((a, b) -> 0), + Flux.mergeComparing(1, (a, b) -> 0), + Flux.mergeComparingDelayError(1, (a, b) -> 0), + Flux.mergeDelayError(1), + Flux.mergePriority((a, b) -> 0), + Flux.mergePriority(1, (a, b) -> 0), + Flux.mergePriorityDelayError(1, (a, b) -> 0), + Flux.mergeSequential(), + Flux.mergeSequential(1), + Flux.mergeSequentialDelayError(1), + Flux.zip(v -> v), + Flux.zip(v -> v, 1), + Flux.combineLatest(v -> v), + Flux.combineLatest(v -> v, 1), + Flux.mergeComparing(), + Flux.mergePriority(), + Flux.range(0, 0)); + } + + Flux testFluxJust() { + return Flux.range(0, 1); } ImmutableSet> testMonoIdentity() { 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 ad308cee82d..bec6b715f60 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 @@ -152,9 +152,35 @@ ImmutableSet> testFluxDefaultIfEmpty() { Flux.just("foo").defaultIfEmpty("bar"), Flux.just("baz").defaultIfEmpty("qux")); } - ImmutableSet> testFluxEmpty() { + ImmutableSet> testFluxEmpty() { return ImmutableSet.of( - Flux.empty(), Flux.empty(), Flux.empty(), Flux.empty(), Flux.empty(), Flux.empty()); + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty()); + } + + Flux testFluxJust() { + return Flux.just(0); } ImmutableSet> testMonoIdentity() {