Skip to content

Commit d172fd9

Browse files
committed
Failing test case to show bug in takeWhile
1 parent f4968d6 commit d172fd9

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import rx.util.AtomicObservableSubscription;
3030
import rx.util.functions.Func1;
3131
import rx.util.functions.Func2;
32-
32+
import rx.subjects.Subject;
3333
/**
3434
* Returns a specified number of contiguous values from the start of an observable sequence.
3535
*/
@@ -178,6 +178,37 @@ public Boolean call(Integer input) {
178178
verify(aObserver, times(1)).onCompleted();
179179
}
180180

181+
@Test
182+
public void testTakeWhileOnSubject1() {
183+
Subject<Integer> s = Subject.create();
184+
Observable<Integer> w = (Observable<Integer>)s;
185+
Observable<Integer> take = Observable.create(takeWhile(w, new Func1<Integer, Boolean>() {
186+
@Override
187+
public Boolean call(Integer input) {
188+
return input < 3;
189+
}
190+
}));
191+
192+
@SuppressWarnings("unchecked")
193+
Observer<Integer> aObserver = mock(Observer.class);
194+
take.subscribe(aObserver);
195+
196+
s.onNext(1);
197+
s.onNext(2);
198+
s.onNext(3);
199+
s.onNext(4);
200+
s.onNext(5);
201+
s.onCompleted();
202+
203+
verify(aObserver, times(1)).onNext(1);
204+
verify(aObserver, times(1)).onNext(2);
205+
verify(aObserver, never()).onNext(3);
206+
verify(aObserver, never()).onNext(4);
207+
verify(aObserver, never()).onNext(5);
208+
verify(aObserver, never()).onError(any(Exception.class));
209+
verify(aObserver, times(1)).onCompleted();
210+
}
211+
181212
@Test
182213
public void testTakeWhile2() {
183214
Observable<String> w = Observable.toObservable("one", "two", "three");

0 commit comments

Comments
 (0)