Skip to content

Commit

Permalink
1.x: Change Completable.subscribe(error, completed) to (completed, er…
Browse files Browse the repository at this point in the history
…ror)
  • Loading branch information
artem-zinnatullin committed Jun 27, 2016
1 parent 5c74757 commit 8912d87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
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() {
@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

0 comments on commit 8912d87

Please sign in to comment.