Reactor test Step Verifier - check that every next event matches predicate

Viewed 401

I would like to verify that every onNext emission matches the given predicate.

I tried expectNextMatches:

StepVerifier.create(...)
    .expectNextMatches { it.status != "SUCCESS" }
    .expectComplete()
    .verify()

However, it matches only one emission, not every single one.

1 Answers

There's an operator for that:

StepVerifier.create(...)
    .thenConsumeWhile(it -> it.status != "SUCCESS")
    .expectComplete()
    .verify();

If there is any element in the sequence that doesn't match, the StepVerifier will error.

Related