From 2e5d1f1e8726b770228f1254ba57b4fc054eecb6 Mon Sep 17 00:00:00 2001 From: tijana-ninkovic Date: Sat, 20 Jul 2024 12:57:45 +0200 Subject: [PATCH] Extend `FluxJust` Refaster rule (#1253) --- .../errorprone/refasterrules/ReactorRules.java | 15 ++++++++++----- .../refasterrules/ReactorRulesTestInput.java | 4 ++-- .../refasterrules/ReactorRulesTestOutput.java | 4 ++-- 3 files changed, 14 insertions(+), 9 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 273e0eea17..1f97c40fd3 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 @@ -481,15 +481,20 @@ Flux after() { } /** Prefer {@link Flux#just(Object)} over more contrived alternatives. */ - static final class FluxJust { + static final class FluxJust { @BeforeTemplate - Flux before(int start) { - return Flux.range(start, 1); + Flux before(int value) { + return Flux.range(value, 1); + } + + @BeforeTemplate + Flux before(T value) { + return Mono.just(value).repeat().take(1); } @AfterTemplate - Flux after(int start) { - return Flux.just(start); + Flux after(T value) { + return Flux.just(value); } } 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 1efc888cc4..3702be49e9 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 @@ -183,8 +183,8 @@ ImmutableSet> testFluxEmpty() { Flux.range(0, 0)); } - Flux testFluxJust() { - return Flux.range(0, 1); + ImmutableSet> testFluxJust() { + return ImmutableSet.of(Flux.range(0, 1), Mono.just(2).repeat().take(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 7e4c325bf1..7cb8a551b2 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 @@ -187,8 +187,8 @@ ImmutableSet> testFluxEmpty() { Flux.empty()); } - Flux testFluxJust() { - return Flux.just(0); + ImmutableSet> testFluxJust() { + return ImmutableSet.of(Flux.just(0), Flux.just(2)); } ImmutableSet> testMonoIdentity() {