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

1.x: Change Completable.subscribe(onError, onComplete) to (onComplete, onError) #4140

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/main/java/rx/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1933,14 +1933,14 @@ public void onSubscribe(Subscription d) {
/**
* Subscribes to this Completable and calls back either the onError or onComplete functions.
*
* @param onError the consumer that is called if this Completable emits an error
* @param onComplete the runnable that is called if the Completable completes normally
* @param onError the consumer that is called if this Completable emits an error
* @return the Subscription that can be used for cancelling the subscription asynchronously
* @throws NullPointerException if either callback is null
*/
public final Subscription subscribe(final Action1<? super Throwable> onError, final Action0 onComplete) {
requireNonNull(onError);
public final Subscription subscribe(final Action0 onComplete, final Action1<? super Throwable> onError) {
requireNonNull(onComplete);
requireNonNull(onError);

final MultipleAssignmentSubscription mad = new MultipleAssignmentSubscription();
unsafeSubscribe(new CompletableSubscriber() {
Expand Down
98 changes: 49 additions & 49 deletions src/test/java/rx/CompletableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2567,16 +2567,16 @@ public void call() {
public void subscribeTwoCallbacksNormal() {
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
final AtomicBoolean complete = new AtomicBoolean();
normal.completable.subscribe(new Action1<Throwable>() {
@Override
public void call(Throwable e) {
err.set(e);
}
}, new Action0() {
normal.completable.subscribe(new Action0() {
@Override
public void call() {
complete.set(true);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
err.set(e);
}
});

Assert.assertNull(err.get());
Expand All @@ -2587,16 +2587,16 @@ public void call() {
public void subscribeTwoCallbacksError() {
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
final AtomicBoolean complete = new AtomicBoolean();
error.completable.subscribe(new Action1<Throwable>() {
@Override
public void call(Throwable e) {
err.set(e);
}
}, new Action0() {
error.completable.subscribe(new Action0() {
@Override
public void call() {
complete.set(true);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
err.set(e);
}
});

Assert.assertTrue(err.get() instanceof TestException);
Expand All @@ -2605,44 +2605,44 @@ public void call() {

@Test(expected = NullPointerException.class)
public void subscribeTwoCallbacksFirstNull() {
normal.completable.subscribe(null, new Action0() {
normal.completable.subscribe(null, new Action1<Throwable>() {
@Override
public void call() { }
public void call(Throwable throwable) {}
});
}

@Test(expected = NullPointerException.class)
public void subscribeTwoCallbacksSecondNull() {
normal.completable.subscribe(null, new Action0() {
normal.completable.subscribe(new Action0() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't catch that on initial PR, test was obviously copied from subscribeTwoCallbacksFirstNull and wasn't changed, second parameter should have been null.

@Override
public void call() { }
});
}, null);
}

@Test(timeout = 5000)
public void subscribeTwoCallbacksCompleteThrows() {
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
normal.completable.subscribe(new Action1<Throwable>() {
normal.completable.subscribe(new Action0() {
@Override
public void call() { throw new TestException(); }
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
err.set(e);
}
}, new Action0() {
@Override
public void call() { throw new TestException(); }
});

Assert.assertTrue(String.valueOf(err.get()), err.get() instanceof TestException);
}

@Test(timeout = 5000)
public void subscribeTwoCallbacksOnErrorThrows() {
error.completable.subscribe(new Action1<Throwable>() {
@Override
public void call(Throwable e) { throw new TestException(); }
}, new Action0() {
error.completable.subscribe(new Action0() {
@Override
public void call() { }
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) { throw new TestException(); }
});
}

Expand Down Expand Up @@ -2800,14 +2800,14 @@ public void subscribeTwoActionsThrowFromOnError() {
expectUncaughtTestException(new Action0() {
@Override
public void call() {
error.completable.subscribe(new Action1<Throwable>() {
error.completable.subscribe(new Action0() {
@Override
public void call(Throwable throwable) {
throw new TestException();
public void call() {
}
}, new Action0() {
}, new Action1<Throwable>() {
@Override
public void call() {
public void call(Throwable throwable) {
throw new TestException();
}
});
}
Expand Down Expand Up @@ -3132,14 +3132,14 @@ public void ambArrayOneFiresError() {

final AtomicReference<Throwable> complete = new AtomicReference<Throwable>();

c.subscribe(new Action1<Throwable>() {
c.subscribe(new Action0() {
@Override
public void call() { }
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
complete.set(e);
}
}, new Action0() {
@Override
public void call() { }
});

Assert.assertTrue("First subject no subscribers", ps1.hasObservers());
Expand Down Expand Up @@ -3197,14 +3197,14 @@ public void ambArraySecondFiresError() {

final AtomicReference<Throwable> complete = new AtomicReference<Throwable>();

c.subscribe(new Action1<Throwable>() {
c.subscribe(new Action0() {
@Override
public void call() { }
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
complete.set(e);
}
}, new Action0() {
@Override
public void call() { }
});

Assert.assertTrue("First subject no subscribers", ps1.hasObservers());
Expand Down Expand Up @@ -3363,14 +3363,14 @@ public void ambWithArrayOneFiresError() {

final AtomicReference<Throwable> complete = new AtomicReference<Throwable>();

c.subscribe(new Action1<Throwable>() {
c.subscribe(new Action0() {
@Override
public void call() { }
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
complete.set(e);
}
}, new Action0() {
@Override
public void call() { }
});

Assert.assertTrue("First subject no subscribers", ps1.hasObservers());
Expand Down Expand Up @@ -3428,14 +3428,14 @@ public void ambWithArraySecondFiresError() {

final AtomicReference<Throwable> complete = new AtomicReference<Throwable>();

c.subscribe(new Action1<Throwable>() {
c.subscribe(new Action0() {
@Override
public void call() { }
}, new Action1<Throwable>() {
@Override
public void call(Throwable e) {
complete.set(e);
}
}, new Action0() {
@Override
public void call() { }
});

Assert.assertTrue("First subject no subscribers", ps1.hasObservers());
Expand Down Expand Up @@ -3841,14 +3841,14 @@ public void subscribeAction2ReportsUnsubscribedAfter() {
Completable completable = stringSubject.toCompletable();

final AtomicReference<Subscription> subscriptionRef = new AtomicReference<Subscription>();
Subscription completableSubscription = completable.subscribe(Actions.empty(), new Action0() {
Subscription completableSubscription = completable.subscribe(new Action0() {
@Override
public void call() {
if (subscriptionRef.get().isUnsubscribed()) {
subscriptionRef.set(null);
}
}
});
}, Actions.empty());
subscriptionRef.set(completableSubscription);

stringSubject.onCompleted();
Expand All @@ -3863,14 +3863,14 @@ public void subscribeAction2ReportsUnsubscribedOnErrorAfter() {
Completable completable = stringSubject.toCompletable();

final AtomicReference<Subscription> subscriptionRef = new AtomicReference<Subscription>();
Subscription completableSubscription = completable.subscribe(new Action1<Throwable>() {
Subscription completableSubscription = completable.subscribe(Actions.empty(), new Action1<Throwable>() {
@Override
public void call(Throwable e) {
if (subscriptionRef.get().isUnsubscribed()) {
subscriptionRef.set(null);
}
}
}, Actions.empty());
});
subscriptionRef.set(completableSubscription);

stringSubject.onError(new TestException());
Expand Down