Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Reactor ContextEmpty Refaster rule #306

Merged
merged 4 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -375,6 +377,19 @@ Flux<T> after(Flux<T> flux) {
}
}

/** Prefer {@link reactor.util.context.Context#empty()}} over more verbose alternatives. */
static final class ContextEmpty {
@BeforeTemplate
Context before() {
return Context.of(ImmutableMap.of());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users outside of Picnic might be more likely to use new HashMap<>(); let's add a case for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Better would be to introduce a Matcher for this, but that's something for a separate PR.)

}

@AfterTemplate
Context after() {
return Context.empty();
}
}

/** Prefer {@link PublisherProbe#empty()}} over more verbose alternatives. */
static final class PublisherProbeEmpty<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,12 +13,13 @@
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 {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(assertThat(0));
return ImmutableSet.of(assertThat(0), ImmutableMap.class);
}

ImmutableSet<Mono<?>> testMonoFromSupplier() {
Expand Down Expand Up @@ -126,6 +128,10 @@ ImmutableSet<Flux<Integer>> testFluxOnErrorComplete() {
Flux.just(2).onErrorResume(e -> Flux.empty()));
}

Context testContextEmpty() {
return Context.of(ImmutableMap.of());
}

ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,12 +15,13 @@
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 {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(assertThat(0));
return ImmutableSet.of(assertThat(0), ImmutableMap.class);
}

ImmutableSet<Mono<?>> testMonoFromSupplier() {
Expand Down Expand Up @@ -124,6 +126,10 @@ ImmutableSet<Flux<Integer>> testFluxOnErrorComplete() {
return ImmutableSet.of(Flux.just(1).onErrorComplete(), Flux.just(2).onErrorComplete());
}

Context testContextEmpty() {
return Context.empty();
}

ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty());
}
Expand Down