Skip to content

Commit 75b2ddd

Browse files
committed
Separating unit tests out and update the comments
1 parent 976ef36 commit 75b2ddd

File tree

5 files changed

+377
-358
lines changed

5 files changed

+377
-358
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22+
import java.util.Comparator;
2223
import java.util.List;
2324
import java.util.concurrent.ConcurrentHashMap;
2425
import java.util.concurrent.Future;
@@ -3635,11 +3636,13 @@ public static Observable<Double> averageDoubles(Observable<Double> source) {
36353636

36363637
/**
36373638
* Returns the minimum element in an observable sequence.
3638-
* For an empty source, it causes an {@link UnsupportedOperationException}.
3639+
* For an empty source, it causes an {@link IllegalArgumentException}.
36393640
*
36403641
* @param source
36413642
* an observable sequence to determine the minimum element of.
36423643
* @return an observable emitting the minimum element.
3644+
* @throws IllegalArgumentException
3645+
* if the source is empty
36433646
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229715(v=vs.103).aspx">MSDN: Observable.Min</a>
36443647
*/
36453648
public static <T extends Comparable<T>> Observable<T> min(Observable<T> source) {
@@ -3648,11 +3651,13 @@ public static <T extends Comparable<T>> Observable<T> min(Observable<T> source)
36483651

36493652
/**
36503653
* Returns the minimum element in an observable sequence according to the specified comparator.
3651-
* For an empty source, it causes an {@link UnsupportedOperationException}.
3654+
* For an empty source, it causes an {@link IllegalArgumentException}.
36523655
*
36533656
* @param comparator
36543657
* the comparer used to compare elements.
36553658
* @return an observable emitting the minimum value according to the specified comparator.
3659+
* @throws IllegalArgumentException
3660+
* if the source is empty
36563661
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229095(v=vs.103).aspx">MSDN: Observable.Min</a>
36573662
*/
36583663
public Observable<T> min(Comparator<T> comparator) {
@@ -3689,11 +3694,13 @@ public <R> Observable<List<T>> minBy(Func1<T, R> selector, Comparator<R> compara
36893694

36903695
/**
36913696
* Returns the maximum element in an observable sequence.
3692-
* For an empty source, it causes an {@link UnsupportedOperationException}.
3697+
* For an empty source, it causes an {@link IllegalArgumentException}.
36933698
*
36943699
* @param source
36953700
* an observable sequence to determine the maximum element of.
36963701
* @return an observable emitting the maximum element.
3702+
* @throws IllegalArgumentException
3703+
* if the source is empty.
36973704
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211837(v=vs.103).aspx">MSDN: Observable.Max</a>
36983705
*/
36993706
public static <T extends Comparable<T>> Observable<T> max(Observable<T> source) {
@@ -3702,11 +3709,13 @@ public static <T extends Comparable<T>> Observable<T> max(Observable<T> source)
37023709

37033710
/**
37043711
* Returns the maximum element in an observable sequence according to the specified comparator.
3705-
* For an empty source, it causes an {@link UnsupportedOperationException}.
3712+
* For an empty source, it causes an {@link IllegalArgumentException}.
37063713
*
37073714
* @param comparator
37083715
* the comparer used to compare elements.
37093716
* @return an observable emitting the maximum value according to the specified comparator.
3717+
* @throws IllegalArgumentException
3718+
* if the source is empty.
37103719
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211635(v=vs.103).aspx">MSDN: Observable.Max</a>
37113720
*/
37123721
public Observable<T> max(Comparator<T> comparator) {

rxjava-core/src/main/java/rx/operators/OperationMax.java

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,11 @@
1515
*/
1616
package rx.operators;
1717

18-
import static org.mockito.Matchers.any;
19-
import static org.mockito.Mockito.inOrder;
20-
import static org.mockito.Mockito.mock;
21-
import static org.mockito.Mockito.times;
22-
2318
import java.util.ArrayList;
24-
import java.util.Arrays;
2519
import java.util.Comparator;
2620
import java.util.List;
2721

28-
import org.junit.Test;
29-
import org.mockito.InOrder;
30-
3122
import rx.Observable;
32-
import rx.Observer;
3323
import rx.util.functions.Func1;
3424
import rx.util.functions.Func2;
3525

@@ -113,171 +103,4 @@ public List<T> call(List<T> acc, T value) {
113103
});
114104
}
115105

116-
public static class UnitTest {
117-
118-
@Test
119-
public void testMax() {
120-
Observable<Integer> observable = OperationMax.max(Observable.from(
121-
2, 3, 1, 4));
122-
123-
@SuppressWarnings("unchecked")
124-
Observer<Integer> observer = (Observer<Integer>) mock(Observer.class);
125-
126-
observable.subscribe(observer);
127-
InOrder inOrder = inOrder(observer);
128-
inOrder.verify(observer, times(1)).onNext(4);
129-
inOrder.verify(observer, times(1)).onCompleted();
130-
inOrder.verifyNoMoreInteractions();
131-
}
132-
133-
@Test
134-
public void testMaxWithEmpty() {
135-
Observable<Integer> observable = OperationMax.max(Observable
136-
.<Integer> empty());
137-
138-
@SuppressWarnings("unchecked")
139-
Observer<Integer> observer = (Observer<Integer>) mock(Observer.class);
140-
141-
observable.subscribe(observer);
142-
InOrder inOrder = inOrder(observer);
143-
inOrder.verify(observer, times(1)).onError(
144-
any(UnsupportedOperationException.class));
145-
inOrder.verifyNoMoreInteractions();
146-
}
147-
148-
@Test
149-
public void testMaxWithComparator() {
150-
Observable<Integer> observable = OperationMax.max(
151-
Observable.from(2, 3, 1, 4), new Comparator<Integer>() {
152-
@Override
153-
public int compare(Integer o1, Integer o2) {
154-
return o2 - o1;
155-
}
156-
});
157-
158-
@SuppressWarnings("unchecked")
159-
Observer<Integer> observer = (Observer<Integer>) mock(Observer.class);
160-
161-
observable.subscribe(observer);
162-
InOrder inOrder = inOrder(observer);
163-
inOrder.verify(observer, times(1)).onNext(1);
164-
inOrder.verify(observer, times(1)).onCompleted();
165-
inOrder.verifyNoMoreInteractions();
166-
}
167-
168-
@Test
169-
public void testMaxWithComparatorAndEmpty() {
170-
Observable<Integer> observable = OperationMax.max(
171-
Observable.<Integer> empty(), new Comparator<Integer>() {
172-
@Override
173-
public int compare(Integer o1, Integer o2) {
174-
return o2 - o1;
175-
}
176-
});
177-
178-
@SuppressWarnings("unchecked")
179-
Observer<Integer> observer = (Observer<Integer>) mock(Observer.class);
180-
181-
observable.subscribe(observer);
182-
InOrder inOrder = inOrder(observer);
183-
inOrder.verify(observer, times(1)).onError(
184-
any(UnsupportedOperationException.class));
185-
inOrder.verifyNoMoreInteractions();
186-
}
187-
188-
@Test
189-
public void testMaxBy() {
190-
Observable<List<String>> observable = OperationMax.maxBy(
191-
Observable.from("1", "2", "3", "4", "5", "6"),
192-
new Func1<String, Integer>() {
193-
@Override
194-
public Integer call(String t1) {
195-
return Integer.parseInt(t1) % 2;
196-
}
197-
});
198-
199-
@SuppressWarnings("unchecked")
200-
Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class);
201-
202-
observable.subscribe(observer);
203-
InOrder inOrder = inOrder(observer);
204-
inOrder.verify(observer, times(1)).onNext(
205-
Arrays.asList("1", "3", "5"));
206-
inOrder.verify(observer, times(1)).onCompleted();
207-
inOrder.verifyNoMoreInteractions();
208-
}
209-
210-
@Test
211-
public void testMaxByWithEmpty() {
212-
Observable<List<String>> observable = OperationMax.maxBy(
213-
Observable.<String> empty(), new Func1<String, Integer>() {
214-
@Override
215-
public Integer call(String t1) {
216-
return Integer.parseInt(t1) % 2;
217-
}
218-
});
219-
220-
@SuppressWarnings("unchecked")
221-
Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class);
222-
223-
observable.subscribe(observer);
224-
InOrder inOrder = inOrder(observer);
225-
inOrder.verify(observer, times(1)).onNext(new ArrayList<String>());
226-
inOrder.verify(observer, times(1)).onCompleted();
227-
inOrder.verifyNoMoreInteractions();
228-
}
229-
230-
@Test
231-
public void testMaxByWithComparator() {
232-
Observable<List<String>> observable = OperationMax.maxBy(
233-
Observable.from("1", "2", "3", "4", "5", "6"),
234-
new Func1<String, Integer>() {
235-
@Override
236-
public Integer call(String t1) {
237-
return Integer.parseInt(t1) % 2;
238-
}
239-
}, new Comparator<Integer>() {
240-
@Override
241-
public int compare(Integer o1, Integer o2) {
242-
return o2 - o1;
243-
}
244-
});
245-
246-
@SuppressWarnings("unchecked")
247-
Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class);
248-
249-
observable.subscribe(observer);
250-
InOrder inOrder = inOrder(observer);
251-
inOrder.verify(observer, times(1)).onNext(
252-
Arrays.asList("2", "4", "6"));
253-
inOrder.verify(observer, times(1)).onCompleted();
254-
inOrder.verifyNoMoreInteractions();
255-
}
256-
257-
@Test
258-
public void testMaxByWithComparatorAndEmpty() {
259-
Observable<List<String>> observable = OperationMax.maxBy(
260-
Observable.<String> empty(), new Func1<String, Integer>() {
261-
@Override
262-
public Integer call(String t1) {
263-
return Integer.parseInt(t1) % 2;
264-
}
265-
}, new Comparator<Integer>() {
266-
@Override
267-
public int compare(Integer o1, Integer o2) {
268-
return o2 - o1;
269-
}
270-
});
271-
272-
@SuppressWarnings("unchecked")
273-
Observer<List<String>> observer = (Observer<List<String>>) mock(Observer.class);
274-
275-
observable.subscribe(observer);
276-
InOrder inOrder = inOrder(observer);
277-
inOrder.verify(observer, times(1)).onNext(new ArrayList<String>());
278-
inOrder.verify(observer, times(1)).onCompleted();
279-
inOrder.verifyNoMoreInteractions();
280-
}
281-
}
282-
283106
}

0 commit comments

Comments
 (0)