OperationConditionals { public static <T> OnSubscribeFunc<T> doWhile(Observable<? extends T> source, Func0<Boolean> postCondition) { return new WhileDoWhile<T>(source, TRUE, postCondition); } 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 testDoWhile() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.doWhile(source1, condition); observe(result, 1, 2, 3, 1, 2, 3); }
@Test public void testDoWhileOnce() { Observable<Integer> source1 = Observable.from(1, 2, 3); condition.call(); Observable<Integer> result = Statement.doWhile(source1, condition); observe(result, 1, 2, 3); }
@Test public void testDoWhileConditionThrows() { Observable<Integer> source1 = Observable.from(1, 2, 3); Observable<Integer> result = Statement.doWhile(source1, conditionError); observeError(result, RuntimeException.class, 1, 2, 3); }
@Test public void testDoWhileSourceThrows() { Observable<Integer> source1 = Observable.concat(Observable.from(1, 2, 3), Observable.<Integer> error(new RuntimeException("Forced failure!"))); Observable<Integer> result = Statement.doWhile(source1, condition); observeError(result, RuntimeException.class, 1, 2, 3); }
@Test public void testDoWhileManyTimes() { 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.doWhile(source1, countdown(numRecursion)); observeSequence(result, expected); }