OperationMinMax { public static <T extends Comparable<? super T>> Observable<T> min( Observable<T> source) { return minMax(source, -1L); }  static Observable<T> min(
            Observable<T> source); static Observable<T> min(Observable<T> source,
            final Comparator<? super T> comparator); static Observable<List<T>> minBy(
            Observable<T> source, final Func1<T, R> selector); static Observable<List<T>> minBy(Observable<T> source,
            final Func1<T, R> selector, final Comparator<? super R> comparator); static Observable<T> max(
            Observable<T> source); static Observable<T> max(Observable<T> source,
            final Comparator<? super T> comparator); static Observable<List<T>> maxBy(
            Observable<T> source, final Func1<T, R> selector); static Observable<List<T>> maxBy(Observable<T> source,
            final Func1<T, R> selector, final Comparator<? super R> comparator);  }
@Test public void testMin() { Observable<Integer> observable = min(Observable.from(2, 3, 1, 4)); @SuppressWarnings("unchecked") Observer<Integer> observer = (Observer<Integer>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testMinWithEmpty() { Observable<Integer> observable = min(Observable.<Integer> empty()); @SuppressWarnings("unchecked") Observer<Integer> observer = (Observer<Integer>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); }
@Test public void testMinWithComparator() { Observable<Integer> observable = min(Observable.from(2, 3, 1, 4), new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2 - o1; } }); @SuppressWarnings("unchecked") Observer<Integer> observer = (Observer<Integer>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(4); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testMinWithComparatorAndEmpty() { Observable<Integer> observable = min(Observable.<Integer> empty(), new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2 - o1; } }); @SuppressWarnings("unchecked") Observer<Integer> observer = (Observer<Integer>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); }