Skip to content

Add extra Maybe iterable Amb tests for overlapped emissions #4567

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

Merged
merged 1 commit into from
Sep 20, 2016
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
47 changes: 47 additions & 0 deletions src/test/java/io/reactivex/maybe/MaybeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,30 @@ public void ambIterable2SignalsSuccess() {
ts.assertResult(2);
}

@SuppressWarnings("unchecked")
@Test
public void ambIterable2SignalsSuccessWithOverlap() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestSubscriber<Integer> ts = Maybe.amb(Arrays.asList(pp1.toMaybe(), pp2.toMaybe()))
.test();

ts.assertEmpty();

assertTrue(pp1.hasSubscribers());
assertTrue(pp2.hasSubscribers());

pp2.onNext(2);
pp1.onNext(1);
pp2.onComplete();

assertFalse(pp1.hasSubscribers());
assertFalse(pp2.hasSubscribers());

ts.assertResult(2);
}

@SuppressWarnings("unchecked")
@Test
public void ambIterable1SignalsError() {
Expand Down Expand Up @@ -1744,6 +1768,29 @@ public void ambIterable2SignalsError() {
ts.assertFailure(TestException.class);
}

@SuppressWarnings("unchecked")
@Test
public void ambIterable2SignalsErrorWithOverlap() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestSubscriber<Integer> ts = Maybe.amb(Arrays.asList(pp1.toMaybe(), pp2.toMaybe()))
.test();

ts.assertEmpty();

assertTrue(pp1.hasSubscribers());
assertTrue(pp2.hasSubscribers());

pp2.onError(new TestException("2"));
pp1.onError(new TestException("1"));

assertFalse(pp1.hasSubscribers());
assertFalse(pp2.hasSubscribers());

ts.assertFailureAndMessage(TestException.class, "2");
}

@SuppressWarnings("unchecked")
@Test
public void ambIterable1SignalsComplete() {
Expand Down