diff --git a/src/main/java/rx/Completable.java b/src/main/java/rx/Completable.java index c4560cbede..8532bb8e44 100644 --- a/src/main/java/rx/Completable.java +++ b/src/main/java/rx/Completable.java @@ -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 onError, final Action0 onComplete) { - requireNonNull(onError); + public final Subscription subscribe(final Action0 onComplete, final Action1 onError) { requireNonNull(onComplete); + requireNonNull(onError); final MultipleAssignmentSubscription mad = new MultipleAssignmentSubscription(); unsafeSubscribe(new CompletableSubscriber() { diff --git a/src/test/java/rx/CompletableTest.java b/src/test/java/rx/CompletableTest.java index 0d495cec67..6545cafeef 100644 --- a/src/test/java/rx/CompletableTest.java +++ b/src/test/java/rx/CompletableTest.java @@ -2567,16 +2567,16 @@ public void call() { public void subscribeTwoCallbacksNormal() { final AtomicReference err = new AtomicReference(); final AtomicBoolean complete = new AtomicBoolean(); - normal.completable.subscribe(new Action1() { - @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() { + @Override + public void call(Throwable e) { + err.set(e); + } }); Assert.assertNull(err.get()); @@ -2587,16 +2587,16 @@ public void call() { public void subscribeTwoCallbacksError() { final AtomicReference err = new AtomicReference(); final AtomicBoolean complete = new AtomicBoolean(); - error.completable.subscribe(new Action1() { - @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() { + @Override + public void call(Throwable e) { + err.set(e); + } }); Assert.assertTrue(err.get() instanceof TestException); @@ -2605,31 +2605,31 @@ public void call() { @Test(expected = NullPointerException.class) public void subscribeTwoCallbacksFirstNull() { - normal.completable.subscribe(null, new Action0() { + normal.completable.subscribe(null, new Action1() { @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() { @Override public void call() { } - }); + }, null); } @Test(timeout = 5000) public void subscribeTwoCallbacksCompleteThrows() { final AtomicReference err = new AtomicReference(); - normal.completable.subscribe(new Action1() { + normal.completable.subscribe(new Action0() { + @Override + public void call() { throw new TestException(); } + }, new Action1() { @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); @@ -2637,12 +2637,12 @@ public void call(Throwable e) { @Test(timeout = 5000) public void subscribeTwoCallbacksOnErrorThrows() { - error.completable.subscribe(new Action1() { - @Override - public void call(Throwable e) { throw new TestException(); } - }, new Action0() { + error.completable.subscribe(new Action0() { @Override public void call() { } + }, new Action1() { + @Override + public void call(Throwable e) { throw new TestException(); } }); } @@ -2800,14 +2800,14 @@ public void subscribeTwoActionsThrowFromOnError() { expectUncaughtTestException(new Action0() { @Override public void call() { - error.completable.subscribe(new Action1() { + error.completable.subscribe(new Action0() { @Override - public void call(Throwable throwable) { - throw new TestException(); + public void call() { } - }, new Action0() { + }, new Action1() { @Override - public void call() { + public void call(Throwable throwable) { + throw new TestException(); } }); } @@ -3132,14 +3132,14 @@ public void ambArrayOneFiresError() { final AtomicReference complete = new AtomicReference(); - c.subscribe(new Action1() { + c.subscribe(new Action0() { + @Override + public void call() { } + }, new Action1() { @Override public void call(Throwable e) { complete.set(e); } - }, new Action0() { - @Override - public void call() { } }); Assert.assertTrue("First subject no subscribers", ps1.hasObservers()); @@ -3197,14 +3197,14 @@ public void ambArraySecondFiresError() { final AtomicReference complete = new AtomicReference(); - c.subscribe(new Action1() { + c.subscribe(new Action0() { + @Override + public void call() { } + }, new Action1() { @Override public void call(Throwable e) { complete.set(e); } - }, new Action0() { - @Override - public void call() { } }); Assert.assertTrue("First subject no subscribers", ps1.hasObservers()); @@ -3363,14 +3363,14 @@ public void ambWithArrayOneFiresError() { final AtomicReference complete = new AtomicReference(); - c.subscribe(new Action1() { + c.subscribe(new Action0() { + @Override + public void call() { } + }, new Action1() { @Override public void call(Throwable e) { complete.set(e); } - }, new Action0() { - @Override - public void call() { } }); Assert.assertTrue("First subject no subscribers", ps1.hasObservers()); @@ -3428,14 +3428,14 @@ public void ambWithArraySecondFiresError() { final AtomicReference complete = new AtomicReference(); - c.subscribe(new Action1() { + c.subscribe(new Action0() { + @Override + public void call() { } + }, new Action1() { @Override public void call(Throwable e) { complete.set(e); } - }, new Action0() { - @Override - public void call() { } }); Assert.assertTrue("First subject no subscribers", ps1.hasObservers()); @@ -3841,14 +3841,14 @@ public void subscribeAction2ReportsUnsubscribedAfter() { Completable completable = stringSubject.toCompletable(); final AtomicReference subscriptionRef = new AtomicReference(); - 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(); @@ -3863,14 +3863,14 @@ public void subscribeAction2ReportsUnsubscribedOnErrorAfter() { Completable completable = stringSubject.toCompletable(); final AtomicReference subscriptionRef = new AtomicReference(); - Subscription completableSubscription = completable.subscribe(new Action1() { + Subscription completableSubscription = completable.subscribe(Actions.empty(), new Action1() { @Override public void call(Throwable e) { if (subscriptionRef.get().isUnsubscribed()) { subscriptionRef.set(null); } } - }, Actions.empty()); + }); subscriptionRef.set(completableSubscription); stringSubject.onError(new TestException());