Skip to content

Commit

Permalink
GroupBy Unit Test from ReactiveX#900
Browse files Browse the repository at this point in the history
  • Loading branch information
benjchristensen committed Feb 19, 2014
1 parent 9b190ae commit 459be62
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions rxjava-core/src/test/java/rx/operators/OperatorGroupByTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package rx.operators;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -29,6 +30,7 @@
import java.util.concurrent.atomic.AtomicReference;

import org.junit.Test;
import org.mockito.Matchers;

import rx.Observable;
import rx.Observable.OnSubscribe;
Expand Down Expand Up @@ -932,4 +934,36 @@ public void call(final Subscriber<? super Event> op) {
});
};

@Test
public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws InterruptedException {

// choose an asynchronous source
Observable<Long> source = Observable.interval(10, TimeUnit.MILLISECONDS).take(1);

// apply groupBy to the source
Observable<GroupedObservable<Boolean, Long>> stream = source.groupBy(IS_EVEN);

// create two observers
@SuppressWarnings("unchecked")
Observer<GroupedObservable<Boolean, Long>> o1 = mock(Observer.class);
@SuppressWarnings("unchecked")
Observer<GroupedObservable<Boolean, Long>> o2 = mock(Observer.class);

// subscribe with the observers
stream.subscribe(o1);
stream.subscribe(o2);

// check that subscriptions were successful
verify(o1, never()).onError(Matchers.<Throwable> any());
verify(o2, never()).onError(Matchers.<Throwable> any());
}

private static Func1<Long, Boolean> IS_EVEN = new Func1<Long, Boolean>() {

@Override
public Boolean call(Long n) {
return n % 2 == 0;
}
};

}

0 comments on commit 459be62

Please sign in to comment.