Creating a Mono is very simple. The following Mono emits one element after a delay of 5 seconds.
Mono<String> stubMonoWithADelay = Mono.just("Ranga").delayElement(Duration.ofSeconds(5));
We want to listen to the events from Mono and log them to the console. We can do that using the statement specified here:
stubMonoWithADelay.subscribe(System.out::println);
However, if you run the program with the two preceding statements in a Test annotation as shown in the following code, you would see that nothing is printed to the console:
@Test public void monoExample() throws InterruptedException { Mono<String> stubMonoWithADelay = Mono.just("Ranga").delayElement(Duration.ofSeconds(5)); stubMonoWithADelay.subscribe(System.out::println); } ...