Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Aug 14, 2023
1 parent 2f1095a commit b198db4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1328,11 +1328,13 @@ StepVerifier.Step<T> after(StepVerifier.Step<T> step, T object) {
}
}

/** Avoid value collection when verifying that a {@link Flux} emits exactly one value. */
static final class FluxAsStepVerifierExpectNext<T> {
/** Avoid list collection when verifying that a {@link Flux} emits exactly one value. */
// XXX: This rule assumes that the matched collector does not drop elements. Consider introducing
// a `@Matches(DoesNotDropElements.class)` or `@NotMatches(MayDropElements.class)` guard.
static final class FluxAsStepVerifierExpectNext<T, L extends List<T>> {
@BeforeTemplate
StepVerifier.Step<ImmutableList<T>> before(Flux<T> flux, T object) {
return flux.collect(toImmutableList())
StepVerifier.Step<L> before(Flux<T> flux, Collector<? super T, ?, L> listCollector, T object) {
return flux.collect(listCollector)
.as(StepVerifier::create)
.assertNext(list -> assertThat(list).containsExactly(object));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,16 @@ ImmutableSet<StepVerifier.Step<String>> testStepVerifierStepExpectNext() {
StepVerifier.create(Mono.just("baz")).expectNextMatches("qux"::equals));
}

Duration testFluxAsStepVerifierExpectNext() {
return Flux.just(1)
.collect(toImmutableList())
.as(StepVerifier::create)
.assertNext(list -> assertThat(list).containsExactly(2))
.verifyComplete();
ImmutableSet<StepVerifier.Step<?>> testFluxAsStepVerifierExpectNext() {
return ImmutableSet.of(
Flux.just(1)
.collect(toImmutableList())
.as(StepVerifier::create)
.assertNext(list -> assertThat(list).containsExactly(2)),
Flux.just(3)
.collect(toCollection(ArrayList::new))
.as(StepVerifier::create)
.assertNext(list -> assertThat(list).containsExactly(4)));
}

Duration testStepVerifierLastStepVerifyComplete() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,10 @@ ImmutableSet<StepVerifier.Step<String>> testStepVerifierStepExpectNext() {
StepVerifier.create(Mono.just("baz")).expectNext("qux"));
}

Duration testFluxAsStepVerifierExpectNext() {
return Flux.just(1).as(StepVerifier::create).expectNext(2).verifyComplete();
ImmutableSet<StepVerifier.Step<?>> testFluxAsStepVerifierExpectNext() {
return ImmutableSet.of(
Flux.just(1).as(StepVerifier::create).expectNext(2),
Flux.just(3).as(StepVerifier::create).expectNext(4));
}

Duration testStepVerifierLastStepVerifyComplete() {
Expand Down

0 comments on commit b198db4

Please sign in to comment.