Skip to content

Commit 20df6fd

Browse files
committed
Failing test case to show Observable.toList breaks with multiple observers due to sharing of the buffer list
1 parent 178e90a commit 20df6fd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,28 @@ public void testList() {
9494
verify(aObserver, Mockito.never()).onError(any(Exception.class));
9595
verify(aObserver, times(1)).onCompleted();
9696
}
97+
98+
@Test
99+
public void testListMultipleObservers() {
100+
Observable<String> w = Observable.toObservable("one", "two", "three");
101+
Observable<List<String>> observable = Observable.create(toObservableList(w));
102+
103+
@SuppressWarnings("unchecked")
104+
Observer<List<String>> o1 = mock(Observer.class);
105+
observable.subscribe(o1);
106+
107+
Observer<List<String>> o2 = mock(Observer.class);
108+
observable.subscribe(o2);
109+
110+
List<String> expected = Arrays.asList("one", "two", "three");
111+
112+
verify(o1, times(1)).onNext(expected);
113+
verify(o1, Mockito.never()).onError(any(Exception.class));
114+
verify(o1, times(1)).onCompleted();
115+
116+
verify(o2, times(1)).onNext(expected);
117+
verify(o2, Mockito.never()).onError(any(Exception.class));
118+
verify(o2, times(1)).onCompleted();
119+
}
97120
}
98121
}

0 commit comments

Comments
 (0)