diff --git a/src/main/java/rx/Completable.java b/src/main/java/rx/Completable.java index 8a2a4121d2..4f2eda83df 100644 --- a/src/main/java/rx/Completable.java +++ b/src/main/java/rx/Completable.java @@ -1132,6 +1132,19 @@ public final Single andThen(Single next) { requireNonNull(next); return next.delaySubscription(toObservable()); } + + /** + * Returns a completable that first runs this Completable + * and then the other completable. + *

+ * This is an alias for {@link #concatWith(Completable)}. + * @param next the other Completable, not null + * @return the new Completable instance + * @throws NullPointerException if other is null + */ + public final Completable andThen(Completable next) { + return concatWith(next); + } /** * Concatenates this Completable with another Completable. @@ -1396,9 +1409,11 @@ public void call(Throwable e) { * @param other the other Completable, not null * @return the new Completable instance * @throws NullPointerException if other is null + * @deprecated Use {@link #andThen(rx.Completable)} instead. */ + @Deprecated public final Completable endWith(Completable other) { - return concatWith(other); + return andThen(other); } /** @@ -1406,10 +1421,11 @@ public final Completable endWith(Completable other) { * resumes with the given next Observable. * @param next the next Observable to continue * @return the new Observable instance - * @throws NullPointerException if next is null + * @deprecated Use {@link #andThen(rx.Observable)} instead. */ + @Deprecated public final Observable endWith(Observable next) { - return next.startWith(this.toObservable()); + return andThen(next); } /** diff --git a/src/test/java/rx/CompletableTest.java b/src/test/java/rx/CompletableTest.java index 8ee2f747d3..4f7ce67985 100644 --- a/src/test/java/rx/CompletableTest.java +++ b/src/test/java/rx/CompletableTest.java @@ -3530,20 +3530,20 @@ public void startWithFlowableNull() { } @Test(expected = NullPointerException.class) - public void endWithCompletableNull() { - normal.completable.endWith((Completable)null); + public void andThenCompletableNull() { + normal.completable.andThen((Completable)null); } @Test(expected = NullPointerException.class) - public void endWithFlowableNull() { - normal.completable.endWith((Observable)null); + public void andThenFlowableNull() { + normal.completable.andThen((Observable)null); } @Test(timeout = 1000) - public void endWithCompletableNormal() { + public void andThenCompletableNormal() { final AtomicBoolean run = new AtomicBoolean(); Completable c = normal.completable - .endWith(Completable.fromCallable(new Callable() { + .andThen(Completable.fromCallable(new Callable() { @Override public Object call() throws Exception { run.set(normal.get() == 0); @@ -3558,8 +3558,8 @@ public Object call() throws Exception { } @Test(timeout = 1000) - public void endWithCompletableError() { - Completable c = normal.completable.endWith(error.completable); + public void andThenCompletableError() { + Completable c = normal.completable.andThen(error.completable); try { c.await(); @@ -3571,10 +3571,10 @@ public void endWithCompletableError() { } @Test(timeout = 1000) - public void endWithFlowableNormal() { + public void andThenFlowableNormal() { final AtomicBoolean run = new AtomicBoolean(); Observable c = normal.completable - .endWith(Observable.fromCallable(new Callable() { + .andThen(Observable.fromCallable(new Callable() { @Override public Object call() throws Exception { run.set(normal.get() == 0); @@ -3595,9 +3595,9 @@ public Object call() throws Exception { } @Test(timeout = 1000) - public void endWithFlowableError() { + public void andThenFlowableError() { Observable c = normal.completable - .endWith(Observable.error(new TestException())); + .andThen(Observable.error(new TestException())); TestSubscriber ts = new TestSubscriber();