Skip to content

Commit

Permalink
Add Refaster template for StepVerifier#create to use Fluent API
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Oct 28, 2021
1 parent e1bdb09 commit 2ff14bd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ PublisherProbe<T> after() {
}
}

/** Use the fluent API style when using {@link StepVerifier#create} for {@link Mono}. */
static final class StepVerifierCreateMono<T> {
@BeforeTemplate
StepVerifier.FirstStep<? extends T> before(Mono<T> mono) {
return StepVerifier.create(mono);
}

@AfterTemplate
StepVerifier.FirstStep<? extends T> after(Flux<T> mono) {

This comment has been minimized.

Copy link
@werli

werli Nov 10, 2021

Member

Shouldn't this be a Mono? 🤔

return mono.as(StepVerifier::create);
}
}

/** Use the fluent API style when using {@link StepVerifier#create} for {@link Flux}. */
static final class StepVerifierCreateFlux<T> {
@BeforeTemplate
StepVerifier.FirstStep<? extends T> before(Flux<T> flux) {
return StepVerifier.create(flux);
}

@AfterTemplate
StepVerifier.FirstStep<? extends T> after(Flux<T> flux) {
return flux.as(StepVerifier::create);
}
}

/** Don't unnecessarily call {@link StepVerifier.Step#expectNext(Object[])}. */
static final class StepVerifierStepExpectNextEmpty<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
}

ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierCreate() {
return ImmutableSet.of(StepVerifier.create(Mono.just(1)), StepVerifier.create(Flux.just(1)));
}

StepVerifier.Step<Integer> testStepVerifierStepExpectNextEmpty() {
return StepVerifier.create(Mono.just(0)).expectNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty());
}

ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierCreate() {
return ImmutableSet.of(
Mono.just(1).as(StepVerifier::create), Flux.just(1).as(StepVerifier::create));
}

StepVerifier.Step<Integer> testStepVerifierStepExpectNextEmpty() {
return StepVerifier.create(Mono.just(0));
}
Expand Down

0 comments on commit 2ff14bd

Please sign in to comment.