Home » Java » How do I use Reactor's StepVerifier to verify a Mono is empty?

How do I use Reactor's StepVerifier to verify a Mono is empty?

Posted by: admin July 23, 2018 Leave a comment

Questions:

I am using StepVerifier to test values:

@Test
public void testStuff() {
    Thing thing = new Thing();
    Mono<Thing> result = Mono.just(thing);
    StepVerifier.create(result).consumeNextWith(r -> {
        assertEquals(thing, r);
    }).verifyComplete();
}

What I’d like to do now is test for the absence of an item in the Mono. Like this:

@Test
public void testNoStuff() {
    Mono<Thing> result = Mono.empty();
    StepVerifier.create(result)... // what goes here?
}

I want to test that the Mono is in fact empty. How do I do that?

Answers: