OperationConditionals { public static <R> OnSubscribeFunc<R> ifThen( Func0<Boolean> condition, Observable<? extends R> then, Observable<? extends R> orElse) { return new IfThen<R>(condition, then, orElse); } private  OperationConditionals(); static OnSubscribeFunc<R> switchCase(
            Func0<? extends K> caseSelector,
            Map<? super K, ? extends Observable<? extends R>> mapOfCases,
            Observable<? extends R> defaultCase); static OnSubscribeFunc<R> ifThen(
            Func0<Boolean> condition,
            Observable<? extends R> then,
            Observable<? extends R> orElse); static OnSubscribeFunc<T> doWhile(Observable<? extends T> source, Func0<Boolean> postCondition); static OnSubscribeFunc<T> whileDo(Observable<? extends T> source, Func0<Boolean> preCondition);  }
@Test public void testIfThenObservableThrows() { Observable<Integer> source1 = Observable.error(new RuntimeException("Forced failure!")); Observable<Integer> result = Statement.ifThen(condition, source1); observeError(result, RuntimeException.class); observe(result); observeError(result, RuntimeException.class); observe(result); }
@Test public void testIfThenElseObservableThrows() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> source2 = Observable.error(new RuntimeException("Forced failure!")); Observable<Integer> result = Statement.ifThen(condition, source1, source2); observe(result, 1, 2, 3); observeError(result, RuntimeException.class); observe(result, 1, 2, 3); observeError(result, RuntimeException.class); }
@Test public void testIfThen() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.ifThen(condition, source1); observe(result, 1, 2, 3); observe(result); observe(result, 1, 2, 3); observe(result); }
@Test public void testIfThenElse() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> source2 = Observable.from(4, 5, 6); Observable<Integer> result = Statement.ifThen(condition, source1, source2); observe(result, 1, 2, 3); observe(result, 4, 5, 6); observe(result, 1, 2, 3); observe(result, 4, 5, 6); }
@Test public void testIfThenConditonThrows() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.ifThen(conditionError, source1); observe(result, 1, 2, 3); observeError(result, RuntimeException.class); observe(result, 1, 2, 3); observeError(result, RuntimeException.class); }