Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupBy Unit Test from #900 #901

Merged
merged 1 commit into from
Feb 19, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
};

}