From c5fadb51916d2890ad6fd5d25a0ddbd4484f2f42 Mon Sep 17 00:00:00 2001 From: bahti Date: Sat, 10 Mar 2018 19:00:14 +0300 Subject: [PATCH] RxJava Maybe samples added. (#3646) * RxJava Maybe samples added. * update rxjava maybe test * Update rxjava maybe tests --- .../java/com/baeldung/rxjava/MaybeTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 rxjava/src/test/java/com/baeldung/rxjava/MaybeTest.java diff --git a/rxjava/src/test/java/com/baeldung/rxjava/MaybeTest.java b/rxjava/src/test/java/com/baeldung/rxjava/MaybeTest.java new file mode 100644 index 0000000000..501ee1f196 --- /dev/null +++ b/rxjava/src/test/java/com/baeldung/rxjava/MaybeTest.java @@ -0,0 +1,40 @@ +package com.baeldung.rxjava; + +import org.junit.Test; + +import io.reactivex.Flowable; +import io.reactivex.Maybe; + +public class MaybeTest { + @Test + public void whenEmitsSingleValue_thenItIsObserved() { + Maybe maybe = Flowable.just(1, 2, 3, 4, 5) + .firstElement(); + + maybe.map(x -> x + 7) + .filter(x -> x > 0) + .test() + .assertResult(8) + .assertComplete(); + } + + @Test + public void whenEmitsNoValue_thenSignalsCompletionAndNoValueObserved() { + Maybe maybe = Flowable.just(1, 2, 3, 4, 5) + .skip(5) + .firstElement(); + + maybe.test() + .assertComplete() + .assertNoValues(); + } + + @Test + public void whenThrowsError_thenErrorIsRaised() { + Maybe maybe = Flowable. error(new Exception("msg")) + .firstElement(); + + maybe.test() + .assertErrorMessage("msg"); + } +}