|
15 | 15 | */ |
16 | 16 | package rx.operators; |
17 | 17 |
|
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 | | - |
23 | 18 | import java.util.ArrayList; |
24 | | -import java.util.Arrays; |
25 | 19 | import java.util.Comparator; |
26 | 20 | import java.util.List; |
27 | 21 |
|
28 | | -import org.junit.Test; |
29 | | -import org.mockito.InOrder; |
30 | | - |
31 | 22 | import rx.Observable; |
32 | | -import rx.Observer; |
33 | 23 | import rx.util.functions.Func1; |
34 | 24 | import rx.util.functions.Func2; |
35 | 25 |
|
@@ -113,171 +103,4 @@ public List<T> call(List<T> acc, T value) { |
113 | 103 | }); |
114 | 104 | } |
115 | 105 |
|
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 | | - |
283 | 106 | } |
0 commit comments