Add blockingHelloWorld()

This commit is contained in:
gindex 2020-04-10 13:36:51 +02:00
parent ba65e09989
commit 5a1f7ffea8
1 changed files with 14 additions and 10 deletions

View File

@ -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!");
}
}