Skip to content

Commit 5a73924

Browse files
author
Joachim Hofer
committed
added tests against multiple subscriptions, just to be on the safe side
1 parent 0da6fc3 commit 5a73924

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public void call() {
206206
public static class UnitTest {
207207
@Mock
208208
Observer<? super String> w;
209+
@Mock
210+
Observer<? super String> w2;
209211

210212
// nulls lead to exceptions
211213
final Func1<String, String> TO_UPPER_WITH_EXCEPTION = new Func1<String, String>() {
@@ -310,6 +312,31 @@ public void testDistinctOfNormalSourceWithKeySelectorAndComparator() {
310312
verify(w, never()).onError(any(Throwable.class));
311313
}
312314

315+
@Test
316+
public void testDistinctOfNormalSourceWithKeySelectorAndComparatorAndTwoSubscriptions() {
317+
Observable<String> src = from("a", "x", "ab", "abc", "cba", "de", "x", "a", "abcd");
318+
create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w);
319+
320+
InOrder inOrder = inOrder(w);
321+
inOrder.verify(w, times(1)).onNext("a");
322+
inOrder.verify(w, times(1)).onNext("x");
323+
create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w2);
324+
inOrder.verify(w, times(1)).onNext("abc");
325+
inOrder.verify(w, times(1)).onNext("abcd");
326+
inOrder.verify(w, times(1)).onCompleted();
327+
inOrder.verify(w, never()).onNext(anyString());
328+
verify(w, never()).onError(any(Throwable.class));
329+
330+
InOrder inOrder2 = inOrder(w2);
331+
inOrder2.verify(w2, times(1)).onNext("a");
332+
inOrder2.verify(w2, times(1)).onNext("x");
333+
inOrder2.verify(w2, times(1)).onNext("abc");
334+
inOrder2.verify(w2, times(1)).onNext("abcd");
335+
inOrder2.verify(w2, times(1)).onCompleted();
336+
inOrder2.verify(w2, never()).onNext(anyString());
337+
verify(w2, never()).onError(any(Throwable.class));
338+
}
339+
313340
@Test
314341
public void testDistinctOfSourceWithNulls() {
315342
Observable<String> src = from(null, "a", "a", null, null, "b", null);

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public void call() {
161161
public static class UnitTest {
162162
@Mock
163163
Observer<? super String> w;
164+
@Mock
165+
Observer<? super String> w2;
164166

165167
// nulls lead to exceptions
166168
final Func1<String, String> TO_UPPER_WITH_EXCEPTION = new Func1<String, String>() {
@@ -295,5 +297,29 @@ public void testDistinctUntilChangedWithComparatorAndKeySelector() {
295297
inOrder.verify(w, never()).onNext(anyString());
296298
verify(w, never()).onError(any(Throwable.class));
297299
}
300+
301+
@Test
302+
public void testDistinctUntilChangedWithComparatorAndKeySelectorandTwoSubscriptions() {
303+
Observable<String> src = from("a", "b", "x", "aa", "bb", "c", "ddd");
304+
create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w);
305+
InOrder inOrder = inOrder(w);
306+
inOrder.verify(w, times(1)).onNext("a");
307+
inOrder.verify(w, times(1)).onNext("x");
308+
create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w2);
309+
inOrder.verify(w, times(1)).onNext("c");
310+
inOrder.verify(w, times(1)).onNext("ddd");
311+
inOrder.verify(w, times(1)).onCompleted();
312+
inOrder.verify(w, never()).onNext(anyString());
313+
verify(w, never()).onError(any(Throwable.class));
314+
315+
InOrder inOrder2 = inOrder(w2);
316+
inOrder2.verify(w2, times(1)).onNext("a");
317+
inOrder2.verify(w2, times(1)).onNext("x");
318+
inOrder2.verify(w2, times(1)).onNext("c");
319+
inOrder2.verify(w2, times(1)).onNext("ddd");
320+
inOrder2.verify(w2, times(1)).onCompleted();
321+
inOrder2.verify(w2, never()).onNext(anyString());
322+
verify(w2, never()).onError(any(Throwable.class));
323+
}
298324
}
299325
}

0 commit comments

Comments
 (0)