Skip to content

Commit

Permalink
Introduce FluxEmpty Refaster rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Venorcis committed Oct 6, 2023
1 parent 5596b58 commit cd1f5f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,25 @@ Flux<T> after(Flux<T> flux, T object) {
}
}

/** Prefer {@link Flux#empty()} over more contrived ways of creating an empty flux. */
static final class FluxEmpty<T> {
@BeforeTemplate
Flux<T> before() {
return Refaster.anyOf(
Flux.just(),
Flux.concat(),
Flux.concatDelayError(),
Flux.firstWithSignal(),
Flux.merge(),
Flux.mergeSequential());
}

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

/** Don't unnecessarily transform a {@link Mono} to an equivalent instance. */
static final class MonoIdentity<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ ImmutableSet<Flux<String>> testFluxDefaultIfEmpty() {
Flux.just("baz").switchIfEmpty(Flux.just("qux")));
}

ImmutableSet<Flux<Void>> testFluxEmpty() {
return ImmutableSet.of(
Flux.just(),
Flux.concat(),
Flux.concatDelayError(),
Flux.firstWithSignal(),
Flux.merge(),
Flux.mergeSequential());
}

ImmutableSet<Mono<?>> testMonoIdentity() {
return ImmutableSet.of(
Mono.just(1).switchIfEmpty(Mono.empty()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ ImmutableSet<Flux<String>> testFluxDefaultIfEmpty() {
Flux.just("foo").defaultIfEmpty("bar"), Flux.just("baz").defaultIfEmpty("qux"));
}

ImmutableSet<Flux<Void>> testFluxEmpty() {
return ImmutableSet.of(
Flux.empty(), Flux.empty(), Flux.empty(), Flux.empty(), Flux.empty(), Flux.empty());
}

ImmutableSet<Mono<?>> testMonoIdentity() {
return ImmutableSet.of(
Mono.just(1),
Expand Down

0 comments on commit cd1f5f9

Please sign in to comment.