diff --git a/reactor-core/src/test/java/com/baeldung/reactor/core/FluxVsMonoUnitTest.java b/reactor-core/src/test/java/com/baeldung/reactor/core/FluxVsMonoUnitTest.java new file mode 100644 index 0000000000..a6a4110b3c --- /dev/null +++ b/reactor-core/src/test/java/com/baeldung/reactor/core/FluxVsMonoUnitTest.java @@ -0,0 +1,45 @@ +package com.baeldung.reactor.core; + +import org.junit.jupiter.api.Test; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +public class FluxVsMonoUnitTest { + + @Test + public void givenMonoPublisher_whenSubscribeThenReturnSingleValue() { + Mono helloMono = Mono.just("Hello"); + StepVerifier.create(helloMono) + .expectNext("Hello") + .expectComplete() + .verify(); + } + + @Test + public void givenFluxPublisher_whenSubscribeThenReturnMultipleValues() { + Flux stringFlux = Flux.just("Hello", "Baeldung"); + StepVerifier.create(stringFlux) + .expectNext("Hello") + .expectNext("Baeldung") + .expectComplete() + .verify(); + } + + @Test + public void givenFluxPublisher_whenSubscribeThenReturnMultipleValuesWithError() { + Flux stringFlux = Flux.just("Hello", "Baeldung", "Error") + .map(str -> { + if (str.equals("Error")) + throw new RuntimeException("Throwing Error"); + return str; + }); + StepVerifier.create(stringFlux) + .expectNext("Hello") + .expectNext("Baeldung") + .expectError() + .verify(); + } + +}