OperationConditionals { public static <T> OnSubscribeFunc<T> whileDo(Observable<? extends T> source, Func0<Boolean> preCondition) { return new WhileDoWhile<T>(source, preCondition, preCondition); } 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 testWhileDo() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.whileDo(source1, countdown(2)); observe(result, 1, 2, 3, 1, 2, 3); }
@Test public void testWhileDoOnce() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.whileDo(source1, countdown(1)); observe(result, 1, 2, 3); }
@Test public void testWhileDoZeroTimes() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.whileDo(source1, countdown(0)); observe(result); }
@Test public void testWhileDoManyTimes() { Observable<Integer> source1 = Observable.from(1, 2, 3).subscribeOn(Schedulers.currentThread()); List<Integer> expected = new ArrayList<Integer>(numRecursion * 3); for (int i = 0; i < numRecursion; i++) { expected.add(1); expected.add(2); expected.add(3); } Observable<Integer> result = Statement.whileDo(source1, countdown(numRecursion)); observeSequence(result, expected); }
@Test public void testWhileDoConditionThrows() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.whileDo(source1, conditionError); observeError(result, RuntimeException.class, 1, 2, 3); }
@Test public void testWhileDoConditionThrowsImmediately() { Observable<Integer> source1 = Observable.from(1, 2, 3); conditionError.call(); Observable<Integer> result = Statement.whileDo(source1, conditionError); observeError(result, RuntimeException.class); }
@Test public void testWhileDoSourceThrows() { Observable<Integer> source1 = Observable.concat(Observable.from(1, 2, 3), Observable.<Integer> error(new RuntimeException("Forced failure!"))); Observable<Integer> result = Statement.whileDo(source1, condition); observeError(result, RuntimeException.class, 1, 2, 3); }