Add blockingHelloWorld()
@@ -12,13 +12,13 @@ import static org.junit.Assert.assertEquals;
public class MonoUnitTest {
@Test
public void whenMonoProducesString_thenBlockAndConsume() {
- String expected = "hello world!";
- String result1 = Mono.just(expected).block();
- assertEquals(expected, result1);
+ String result1 = blockingHelloWorld().block();
+ assertEquals("Hello world!", result1);
- String result2 = Mono.just(expected).block(Duration.of(1000, ChronoUnit.MILLIS));
- assertEquals(expected, result2);
+ String result2 = blockingHelloWorld()
+ .block(Duration.of(1000, ChronoUnit.MILLIS));
+ assertEquals("Hello world!", result2);
Optional<String> result3 = Mono.<String>empty().blockOptional();
assertEquals(Optional.empty(), result3);
@@ -26,14 +26,18 @@ public class MonoUnitTest {
@Test
public void whenMonoProducesString_thenConsumeNonBlocking() {
- String expected = "hello world!";
- Mono.just(expected)
- .doOnNext(result -> assertEquals(expected, result))
+ blockingHelloWorld()
+ .doOnNext(result -> assertEquals("Hello world!", result))
.subscribe();
- Mono.just(expected)
- .subscribe(result -> assertEquals(expected, result));
+ blockingHelloWorld()
+ .subscribe(result -> assertEquals("Hello world!", result));
}
+
+ private Mono<String> blockingHelloWorld() {
+ // blocking
+ return Mono.just("Hello world!");
+ }
}
