Skip to content

Commit 1ac89df

Browse files
Merge pull request #901 from benjchristensen/groupBy-unit-test
GroupBy Unit Test from #900
2 parents 9b190ae + 459be62 commit 1ac89df

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

rxjava-core/src/test/java/rx/operators/OperatorGroupByTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package rx.operators;
1717

1818
import static org.junit.Assert.*;
19+
import static org.mockito.Mockito.*;
1920

2021
import java.util.ArrayList;
2122
import java.util.Arrays;
@@ -29,6 +30,7 @@
2930
import java.util.concurrent.atomic.AtomicReference;
3031

3132
import org.junit.Test;
33+
import org.mockito.Matchers;
3234

3335
import rx.Observable;
3436
import rx.Observable.OnSubscribe;
@@ -932,4 +934,36 @@ public void call(final Subscriber<? super Event> op) {
932934
});
933935
};
934936

937+
@Test
938+
public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws InterruptedException {
939+
940+
// choose an asynchronous source
941+
Observable<Long> source = Observable.interval(10, TimeUnit.MILLISECONDS).take(1);
942+
943+
// apply groupBy to the source
944+
Observable<GroupedObservable<Boolean, Long>> stream = source.groupBy(IS_EVEN);
945+
946+
// create two observers
947+
@SuppressWarnings("unchecked")
948+
Observer<GroupedObservable<Boolean, Long>> o1 = mock(Observer.class);
949+
@SuppressWarnings("unchecked")
950+
Observer<GroupedObservable<Boolean, Long>> o2 = mock(Observer.class);
951+
952+
// subscribe with the observers
953+
stream.subscribe(o1);
954+
stream.subscribe(o2);
955+
956+
// check that subscriptions were successful
957+
verify(o1, never()).onError(Matchers.<Throwable> any());
958+
verify(o2, never()).onError(Matchers.<Throwable> any());
959+
}
960+
961+
private static Func1<Long, Boolean> IS_EVEN = new Func1<Long, Boolean>() {
962+
963+
@Override
964+
public Boolean call(Long n) {
965+
return n % 2 == 0;
966+
}
967+
};
968+
935969
}

0 commit comments

Comments
 (0)