Skip to content

Commit

Permalink
Drop redundant ::isInstance in onErrorResume
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Diederichs authored and rickie committed Oct 30, 2022
1 parent 16955a9 commit 710520e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@ Flux<T> after(Flux<T> flux) {
}
}

/** Drop redundant {@link Class#isInstance} in {@link Mono#onErrorResume(Function)}. */
static final class MonoOnErrorResume<T> {
@BeforeTemplate
Mono<T> before(Mono<T> mono, Class<? extends Throwable> clazz, Mono<T> other) {
return mono.onErrorResume(clazz::isInstance, e -> other);
}

@AfterTemplate
Mono<T> after(Mono<T> mono, Class<? extends Throwable> clazz, Mono<T> other) {
return mono.onErrorResume(clazz, e -> other);
}
}

/** Prefer {@link reactor.util.context.Context#empty()}} over more verbose alternatives. */
// XXX: Consider introducing an `IsEmpty` matcher that identifies a wide range of guaranteed-empty
// `Collection` and `Map` expressions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ ImmutableSet<Flux<Integer>> testFluxOnErrorComplete() {
Flux.just(2).onErrorResume(e -> Flux.empty()));
}

Mono<Integer> testMonoOnErrorResume() {
return Mono.just(1)
.onErrorResume(IllegalArgumentException.class::isInstance, e -> Mono.just(2));
}

ImmutableSet<Context> testContextEmpty() {
return ImmutableSet.of(Context.of(new HashMap<>()), Context.of(ImmutableMap.of()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ ImmutableSet<Flux<Integer>> testFluxOnErrorComplete() {
return ImmutableSet.of(Flux.just(1).onErrorComplete(), Flux.just(2).onErrorComplete());
}

Mono<Integer> testMonoOnErrorResume() {
return Mono.just(1).onErrorResume(IllegalArgumentException.class, e -> Mono.just(2));
}

ImmutableSet<Context> testContextEmpty() {
return ImmutableSet.of(Context.empty(), Context.empty());
}
Expand Down

0 comments on commit 710520e

Please sign in to comment.