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 {Mono,Flux}OnErrorComplete Refaster rules #273

Merged
merged 3 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -271,11 +271,37 @@ Flux<S> after(Flux<T> flux) {
}
}

/** Prefer {@link Mono#onErrorComplete()} over more contrived alternatives. */
static final class MonoOnErrorComplete<T> {
@BeforeTemplate
Mono<T> before(Mono<T> mono) {
return mono.onErrorResume(e -> Mono.empty());
}

@AfterTemplate
Mono<T> after(Mono<T> mono) {
return mono.onErrorComplete();
}
}

/** Prefer {@link Flux#onErrorComplete()} over more contrived alternatives. */
static final class FluxOnErrorComplete<T> {
@BeforeTemplate
Flux<T> before(Flux<T> flux) {
return flux.onErrorResume(e -> Refaster.anyOf(Mono.empty(), Flux.empty()));
}

@AfterTemplate
Flux<T> after(Flux<T> flux) {
return flux.onErrorComplete();
}
}

/** Prefer {@link PublisherProbe#empty()}} over more verbose alternatives. */
static final class PublisherProbeEmpty<T> {
@BeforeTemplate
PublisherProbe<T> before() {
return Refaster.anyOf(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
Copy link
Member

Choose a reason for hiding this comment

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

Aiii, not sure how I misses this 😓.

return PublisherProbe.of(Refaster.anyOf(Mono.empty(), Flux.empty()));
}

@AfterTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ Flux<Number> testFluxCast() {
return Flux.just(1).map(Number.class::cast);
}

Mono<Integer> testMonoOnErrorComplete() {
return Mono.just(1).onErrorResume(e -> Mono.empty());
}

ImmutableSet<Flux<Integer>> testFluxOnErrorComplete() {
return ImmutableSet.of(
Flux.just(1).onErrorResume(e -> Mono.empty()),
Flux.just(2).onErrorResume(e -> Flux.empty()));
}

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 @@ -94,6 +94,14 @@ Flux<Number> testFluxCast() {
return Flux.just(1).cast(Number.class);
}

Mono<Integer> testMonoOnErrorComplete() {
return Mono.just(1).onErrorComplete();
}

ImmutableSet<Flux<Integer>> testFluxOnErrorComplete() {
return ImmutableSet.of(Flux.just(1).onErrorComplete(), Flux.just(2).onErrorComplete());
}

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