Skip to content

Commit

Permalink
Cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and rickie committed Oct 9, 2023
1 parent 365eee4 commit effcb21
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,52 @@ Flux<T> after(Flux<T> flux, T object) {
}

/** Prefer {@link Flux#empty()} over more contrived alternatives. */
static final class FluxEmpty<T> {
// XXX: In combination with the `IsEmpty` matcher introduced by
// https://github.com/PicnicSupermarket/error-prone-support/pull/744, the non-varargs overloads of
// most methods referenced here can be rewritten as well. Additionally, some invocations of
// methods such as `Flux#fromIterable`, `Flux#fromArray` and `Flux#justOrEmpty` can also be
// rewritten.
static final class FluxEmpty<T, S extends Comparable<? super S>> {
@BeforeTemplate
Flux<T> before() {
Flux<T> before(
int prefetch,
Function<? super Object[], ? extends T> combinator,
Comparator<? super T> comparator) {
return Refaster.anyOf(
Flux.concat(),
Flux.concatDelayError(),
Flux.firstWithSignal(),
Flux.just(),
Flux.merge(),
Flux.mergeSequential());
Flux.merge(prefetch),
Flux.mergeComparing(comparator),
Flux.mergeComparing(prefetch, comparator),
Flux.mergeComparingDelayError(prefetch, comparator),
Flux.mergeDelayError(prefetch),
Flux.mergePriority(comparator),
Flux.mergePriority(prefetch, comparator),
Flux.mergePriorityDelayError(prefetch, comparator),
Flux.mergeSequential(),
Flux.mergeSequential(prefetch),
Flux.mergeSequentialDelayError(prefetch),
Flux.zip(combinator),
Flux.zip(combinator, prefetch));
}

@BeforeTemplate
Flux<T> before(int prefetch, Function<Object[], T> combinator) {
return Refaster.anyOf(
Flux.combineLatest(combinator), Flux.combineLatest(combinator, prefetch));
}

@BeforeTemplate
Flux<S> before() {
return Refaster.anyOf(Flux.mergeComparing(), Flux.mergePriority());
}

@BeforeTemplate
Flux<Integer> before(int start) {
return Flux.range(start, 0);
}

@AfterTemplate
Expand All @@ -445,6 +481,19 @@ Flux<T> after() {
}
}

/** Prefer {@link Flux#just(Object)} over more contrived alternatives. */
static final class FluxJust {
@BeforeTemplate
Flux<Integer> before(int start) {
return Flux.range(start, 1);
}

@AfterTemplate
Flux<Integer> after(int start) {
return Flux.just(start);
}
}

/** 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 @@ -148,14 +148,35 @@ ImmutableSet<Flux<String>> testFluxDefaultIfEmpty() {
Flux.just("baz").switchIfEmpty(Flux.just("qux")));
}

ImmutableSet<Flux<Void>> testFluxEmpty() {
ImmutableSet<Flux<?>> testFluxEmpty() {
return ImmutableSet.of(
Flux.concat(),
Flux.concatDelayError(),
Flux.firstWithSignal(),
Flux.just(),
Flux.merge(),
Flux.mergeSequential());
Flux.merge(1),
Flux.mergeComparing((a, b) -> 0),
Flux.mergeComparing(1, (a, b) -> 0),
Flux.mergeComparingDelayError(1, (a, b) -> 0),
Flux.mergeDelayError(1),
Flux.mergePriority((a, b) -> 0),
Flux.mergePriority(1, (a, b) -> 0),
Flux.mergePriorityDelayError(1, (a, b) -> 0),
Flux.mergeSequential(),
Flux.mergeSequential(1),
Flux.mergeSequentialDelayError(1),
Flux.zip(v -> v),
Flux.zip(v -> v, 1),
Flux.combineLatest(v -> v),
Flux.combineLatest(v -> v, 1),
Flux.mergeComparing(),
Flux.mergePriority(),
Flux.range(0, 0));
}

Flux<Integer> testFluxJust() {
return Flux.range(0, 1);
}

ImmutableSet<Mono<?>> testMonoIdentity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,35 @@ ImmutableSet<Flux<String>> testFluxDefaultIfEmpty() {
Flux.just("foo").defaultIfEmpty("bar"), Flux.just("baz").defaultIfEmpty("qux"));
}

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

Flux<Integer> testFluxJust() {
return Flux.just(0);
}

ImmutableSet<Mono<?>> testMonoIdentity() {
Expand Down

0 comments on commit effcb21

Please sign in to comment.