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 500bd40e347..13468c4f3a9 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 @@ -5,6 +5,7 @@ import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.MoreCollectors; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; @@ -25,6 +26,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; +import reactor.util.context.Context; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; import tech.picnic.errorprone.refaster.matchers.ThrowsCheckedException; @@ -375,6 +377,19 @@ Flux after(Flux flux) { } } + /** Prefer {@link reactor.util.context.Context#empty()}} over more verbose alternatives. */ + static final class ContextEmpty { + @BeforeTemplate + Context before() { + return Context.of(ImmutableMap.of()); + } + + @AfterTemplate + Context after() { + return Context.empty(); + } + } + /** Prefer {@link PublisherProbe#empty()}} over more verbose alternatives. */ static final class PublisherProbeEmpty { @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 cbf5cc888f0..f22f0a95a62 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 @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; import java.util.Optional; @@ -12,6 +13,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; +import reactor.util.context.Context; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @@ -126,6 +128,10 @@ ImmutableSet> testFluxOnErrorComplete() { Flux.just(2).onErrorResume(e -> Flux.empty())); } + Context testContextEmpty() { + return Context.of(ImmutableMap.of()); + } + ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty())); } 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 94daf79ec9a..2bcc9c7d021 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 @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; import java.util.Optional; @@ -14,6 +15,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; +import reactor.util.context.Context; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @@ -124,6 +126,10 @@ ImmutableSet> testFluxOnErrorComplete() { return ImmutableSet.of(Flux.just(1).onErrorComplete(), Flux.just(2).onErrorComplete()); } + Context testContextEmpty() { + return Context.empty(); + } + ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty()); }