Skip to content

jacek-rzrz/assertj-reactor

Repository files navigation

assertj-reactor

AssertJ extensions for Mono and Flux.

Maven Central

Getting started

Assertions extend from AssertJ core so a single import statement is enough to get both standard AssertJ methods as well as the reactive additions:

import static pl.rzrz.assertj.reactor.Assertions.assertThat;

Check for an error signal

Mono<Void> mono = Mono.error(new Exception());

assertThat(mono).sendsError();

Inspect the exception:

Mono<Void> mono = Mono.error(new RuntimeException("oops"));

assertThat(mono).sendsError(error -> {
    assertThat(error).isInstanceOf(RuntimeException.class);
    assertThat(error).hasMessage("oops");
});

Check successful completion

Mono<Void> mono = Mono.just("this");

assertThat(mono).completes();

Count items

Flux<String> flux = Flux.just("one", "two", "three");

assertThat(flux).emitsCount(3);

Check item emitted

Flux<String> flux = Flux.just("one", "two", "three");

assertThat(flux).emits("two");

Check exactly some items emitted

Flux<String> flux = Flux.just("one", "two", "three");

assertThat(flux).emitsExactly("one", "two", "three");