OperationMinMax { public static <T, R extends Comparable<? super R>> Observable<List<T>> minBy( Observable<T> source, final Func1<T, R> selector) { return minMaxBy(source, selector, -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 testMinBy() { Observable<List<String>> observable = minBy( Observable.from("1", "2", "3", "4", "5", "6"), new Func1<String, Integer>() { @Override public Integer call(String t1) { return Integer.parseInt(t1) % 2; } }); @SuppressWarnings("unchecked") Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(Arrays.asList("2", "4", "6")); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testMinByWithEmpty() { Observable<List<String>> observable = minBy( Observable.<String> empty(), new Func1<String, Integer>() { @Override public Integer call(String t1) { return Integer.parseInt(t1) % 2; } }); @SuppressWarnings("unchecked") Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(new ArrayList<String>()); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testMinByWithComparator() { Observable<List<String>> observable = minBy( Observable.from("1", "2", "3", "4", "5", "6"), new Func1<String, Integer>() { @Override public Integer call(String t1) { return Integer.parseInt(t1) % 2; } }, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2 - o1; } }); @SuppressWarnings("unchecked") Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(Arrays.asList("1", "3", "5")); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testMinByWithComparatorAndEmpty() { Observable<List<String>> observable = minBy( Observable.<String> empty(), new Func1<String, Integer>() { @Override public Integer call(String t1) { return Integer.parseInt(t1) % 2; } }, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2 - o1; } }); @SuppressWarnings("unchecked") Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(new ArrayList<String>()); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }