Skip to content

Commit d66d931

Browse files
artem-zinnatullinzsxwing
authored andcommitted
1.x: Change Completable.subscribe(onError, onComplete) to (onComplete, onError) (#4140)
1 parent 5439901 commit d66d931

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

src/main/java/rx/Completable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,14 +1933,14 @@ public void onSubscribe(Subscription d) {
19331933
/**
19341934
* Subscribes to this Completable and calls back either the onError or onComplete functions.
19351935
*
1936-
* @param onError the consumer that is called if this Completable emits an error
19371936
* @param onComplete the runnable that is called if the Completable completes normally
1937+
* @param onError the consumer that is called if this Completable emits an error
19381938
* @return the Subscription that can be used for cancelling the subscription asynchronously
19391939
* @throws NullPointerException if either callback is null
19401940
*/
1941-
public final Subscription subscribe(final Action1<? super Throwable> onError, final Action0 onComplete) {
1942-
requireNonNull(onError);
1941+
public final Subscription subscribe(final Action0 onComplete, final Action1<? super Throwable> onError) {
19431942
requireNonNull(onComplete);
1943+
requireNonNull(onError);
19441944

19451945
final MultipleAssignmentSubscription mad = new MultipleAssignmentSubscription();
19461946
unsafeSubscribe(new CompletableSubscriber() {

src/test/java/rx/CompletableTest.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,16 +2567,16 @@ public void call() {
25672567
public void subscribeTwoCallbacksNormal() {
25682568
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
25692569
final AtomicBoolean complete = new AtomicBoolean();
2570-
normal.completable.subscribe(new Action1<Throwable>() {
2571-
@Override
2572-
public void call(Throwable e) {
2573-
err.set(e);
2574-
}
2575-
}, new Action0() {
2570+
normal.completable.subscribe(new Action0() {
25762571
@Override
25772572
public void call() {
25782573
complete.set(true);
25792574
}
2575+
}, new Action1<Throwable>() {
2576+
@Override
2577+
public void call(Throwable e) {
2578+
err.set(e);
2579+
}
25802580
});
25812581

25822582
Assert.assertNull(err.get());
@@ -2587,16 +2587,16 @@ public void call() {
25872587
public void subscribeTwoCallbacksError() {
25882588
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
25892589
final AtomicBoolean complete = new AtomicBoolean();
2590-
error.completable.subscribe(new Action1<Throwable>() {
2591-
@Override
2592-
public void call(Throwable e) {
2593-
err.set(e);
2594-
}
2595-
}, new Action0() {
2590+
error.completable.subscribe(new Action0() {
25962591
@Override
25972592
public void call() {
25982593
complete.set(true);
25992594
}
2595+
}, new Action1<Throwable>() {
2596+
@Override
2597+
public void call(Throwable e) {
2598+
err.set(e);
2599+
}
26002600
});
26012601

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

26062606
@Test(expected = NullPointerException.class)
26072607
public void subscribeTwoCallbacksFirstNull() {
2608-
normal.completable.subscribe(null, new Action0() {
2608+
normal.completable.subscribe(null, new Action1<Throwable>() {
26092609
@Override
2610-
public void call() { }
2610+
public void call(Throwable throwable) {}
26112611
});
26122612
}
26132613

26142614
@Test(expected = NullPointerException.class)
26152615
public void subscribeTwoCallbacksSecondNull() {
2616-
normal.completable.subscribe(null, new Action0() {
2616+
normal.completable.subscribe(new Action0() {
26172617
@Override
26182618
public void call() { }
2619-
});
2619+
}, null);
26202620
}
26212621

26222622
@Test(timeout = 5000)
26232623
public void subscribeTwoCallbacksCompleteThrows() {
26242624
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
2625-
normal.completable.subscribe(new Action1<Throwable>() {
2625+
normal.completable.subscribe(new Action0() {
2626+
@Override
2627+
public void call() { throw new TestException(); }
2628+
}, new Action1<Throwable>() {
26262629
@Override
26272630
public void call(Throwable e) {
26282631
err.set(e);
26292632
}
2630-
}, new Action0() {
2631-
@Override
2632-
public void call() { throw new TestException(); }
26332633
});
26342634

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

26382638
@Test(timeout = 5000)
26392639
public void subscribeTwoCallbacksOnErrorThrows() {
2640-
error.completable.subscribe(new Action1<Throwable>() {
2641-
@Override
2642-
public void call(Throwable e) { throw new TestException(); }
2643-
}, new Action0() {
2640+
error.completable.subscribe(new Action0() {
26442641
@Override
26452642
public void call() { }
2643+
}, new Action1<Throwable>() {
2644+
@Override
2645+
public void call(Throwable e) { throw new TestException(); }
26462646
});
26472647
}
26482648

@@ -2800,14 +2800,14 @@ public void subscribeTwoActionsThrowFromOnError() {
28002800
expectUncaughtTestException(new Action0() {
28012801
@Override
28022802
public void call() {
2803-
error.completable.subscribe(new Action1<Throwable>() {
2803+
error.completable.subscribe(new Action0() {
28042804
@Override
2805-
public void call(Throwable throwable) {
2806-
throw new TestException();
2805+
public void call() {
28072806
}
2808-
}, new Action0() {
2807+
}, new Action1<Throwable>() {
28092808
@Override
2810-
public void call() {
2809+
public void call(Throwable throwable) {
2810+
throw new TestException();
28112811
}
28122812
});
28132813
}
@@ -3132,14 +3132,14 @@ public void ambArrayOneFiresError() {
31323132

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

3135-
c.subscribe(new Action1<Throwable>() {
3135+
c.subscribe(new Action0() {
3136+
@Override
3137+
public void call() { }
3138+
}, new Action1<Throwable>() {
31363139
@Override
31373140
public void call(Throwable e) {
31383141
complete.set(e);
31393142
}
3140-
}, new Action0() {
3141-
@Override
3142-
public void call() { }
31433143
});
31443144

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

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

3200-
c.subscribe(new Action1<Throwable>() {
3200+
c.subscribe(new Action0() {
3201+
@Override
3202+
public void call() { }
3203+
}, new Action1<Throwable>() {
32013204
@Override
32023205
public void call(Throwable e) {
32033206
complete.set(e);
32043207
}
3205-
}, new Action0() {
3206-
@Override
3207-
public void call() { }
32083208
});
32093209

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

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

3366-
c.subscribe(new Action1<Throwable>() {
3366+
c.subscribe(new Action0() {
3367+
@Override
3368+
public void call() { }
3369+
}, new Action1<Throwable>() {
33673370
@Override
33683371
public void call(Throwable e) {
33693372
complete.set(e);
33703373
}
3371-
}, new Action0() {
3372-
@Override
3373-
public void call() { }
33743374
});
33753375

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

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

3431-
c.subscribe(new Action1<Throwable>() {
3431+
c.subscribe(new Action0() {
3432+
@Override
3433+
public void call() { }
3434+
}, new Action1<Throwable>() {
34323435
@Override
34333436
public void call(Throwable e) {
34343437
complete.set(e);
34353438
}
3436-
}, new Action0() {
3437-
@Override
3438-
public void call() { }
34393439
});
34403440

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

38433843
final AtomicReference<Subscription> subscriptionRef = new AtomicReference<Subscription>();
3844-
Subscription completableSubscription = completable.subscribe(Actions.empty(), new Action0() {
3844+
Subscription completableSubscription = completable.subscribe(new Action0() {
38453845
@Override
38463846
public void call() {
38473847
if (subscriptionRef.get().isUnsubscribed()) {
38483848
subscriptionRef.set(null);
38493849
}
38503850
}
3851-
});
3851+
}, Actions.empty());
38523852
subscriptionRef.set(completableSubscription);
38533853

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

38653865
final AtomicReference<Subscription> subscriptionRef = new AtomicReference<Subscription>();
3866-
Subscription completableSubscription = completable.subscribe(new Action1<Throwable>() {
3866+
Subscription completableSubscription = completable.subscribe(Actions.empty(), new Action1<Throwable>() {
38673867
@Override
38683868
public void call(Throwable e) {
38693869
if (subscriptionRef.get().isUnsubscribed()) {
38703870
subscriptionRef.set(null);
38713871
}
38723872
}
3873-
}, Actions.empty());
3873+
});
38743874
subscriptionRef.set(completableSubscription);
38753875

38763876
stringSubject.onError(new TestException());

0 commit comments

Comments
 (0)