Skip to content

Commit

Permalink
Introduce PublisherProbeAssertWas{,Not}Requested
Browse files Browse the repository at this point in the history
  • Loading branch information
werli authored and rickie committed Dec 9, 2024
1 parent b19fe10 commit 49f718c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,32 @@ void after(PublisherProbe<T> probe) {
}
}

/** Prefer {@link PublisherProbe#assertWasRequested()} over more verbose alternatives. */
static final class PublisherProbeAssertWasRequested<T> {
@BeforeTemplate
void before(PublisherProbe<T> probe) {
assertThat(probe.wasRequested()).isTrue();
}

@AfterTemplate
void after(PublisherProbe<T> probe) {
probe.assertWasRequested();
}
}

/** Prefer {@link PublisherProbe#assertWasNotRequested()} over more verbose alternatives. */
static final class PublisherProbeAssertWasNotRequested<T> {
@BeforeTemplate
void before(PublisherProbe<T> probe) {
assertThat(probe.wasRequested()).isFalse();
}

@AfterTemplate
void after(PublisherProbe<T> probe) {
probe.assertWasNotRequested();
}
}

/** Prefer {@link Mono#as(Function)} when creating a {@link StepVerifier}. */
static final class StepVerifierFromMono<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@ void testPublisherProbeAssertWasNotCancelled() {
assertThat(PublisherProbe.empty().wasCancelled()).isFalse();
}

void testPublisherProbeAssertWasRequested() {
assertThat(PublisherProbe.empty().wasRequested()).isTrue();
}

void testPublisherProbeAssertWasNotRequested() {
assertThat(PublisherProbe.empty().wasRequested()).isFalse();
}

ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierFromMono() {
return ImmutableSet.of(
StepVerifier.create(Mono.just(1)), Mono.just(2).flux().as(StepVerifier::create));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ void testPublisherProbeAssertWasNotCancelled() {
PublisherProbe.empty().assertWasNotCancelled();
}

void testPublisherProbeAssertWasRequested() {
PublisherProbe.empty().assertWasRequested();
}

void testPublisherProbeAssertWasNotRequested() {
PublisherProbe.empty().assertWasNotRequested();
}

ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierFromMono() {
return ImmutableSet.of(
Mono.just(1).as(StepVerifier::create), Mono.just(2).as(StepVerifier::create));
Expand Down

0 comments on commit 49f718c

Please sign in to comment.