From 2ff14bd85f194a9bca18b3e58c73b18573bb762f Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 28 Oct 2021 13:19:49 +0200 Subject: [PATCH] Add Refaster template for StepVerifier#create to use Fluent API --- .../refastertemplates/ReactorTemplates.java | 26 +++++++++++++++++++ .../ReactorTemplatesTestInput.java | 4 +++ .../ReactorTemplatesTestOutput.java | 5 ++++ 3 files changed, 35 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java index f4ad0d81b61..7bcef1ee6f9 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java @@ -194,6 +194,32 @@ PublisherProbe after() { } } + /** Use the fluent API style when using {@link StepVerifier#create} for {@link Mono}. */ + static final class StepVerifierCreateMono { + @BeforeTemplate + StepVerifier.FirstStep before(Mono mono) { + return StepVerifier.create(mono); + } + + @AfterTemplate + StepVerifier.FirstStep after(Flux mono) { + return mono.as(StepVerifier::create); + } + } + + /** Use the fluent API style when using {@link StepVerifier#create} for {@link Flux}. */ + static final class StepVerifierCreateFlux { + @BeforeTemplate + StepVerifier.FirstStep before(Flux flux) { + return StepVerifier.create(flux); + } + + @AfterTemplate + StepVerifier.FirstStep after(Flux flux) { + return flux.as(StepVerifier::create); + } + } + /** Don't unnecessarily call {@link StepVerifier.Step#expectNext(Object[])}. */ static final class StepVerifierStepExpectNextEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java index 818b6d63724..b06f25dff5b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java @@ -59,6 +59,10 @@ ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty())); } + ImmutableSet> testStepVerifierCreate() { + return ImmutableSet.of(StepVerifier.create(Mono.just(1)), StepVerifier.create(Flux.just(1))); + } + StepVerifier.Step testStepVerifierStepExpectNextEmpty() { return StepVerifier.create(Mono.just(0)).expectNext(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java index b144223c612..c66326afaa5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java @@ -60,6 +60,11 @@ ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty()); } + ImmutableSet> testStepVerifierCreate() { + return ImmutableSet.of( + Mono.just(1).as(StepVerifier::create), Flux.just(1).as(StepVerifier::create)); + } + StepVerifier.Step testStepVerifierStepExpectNextEmpty() { return StepVerifier.create(Mono.just(0)); }