Skip to content

Commit 881f84d

Browse files
authored
4.x: Unit test lambdaification 1 of N (ReactiveX#8137)
1 parent 58c9ed7 commit 881f84d

7 files changed

Lines changed: 225 additions & 686 deletions

File tree

docs/Plugins.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,7 @@ For example, this will call the hook:
126126
```java
127127
RxJavaPlugins.getInstance().reset();
128128

129-
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
130-
@Override
131-
public void handleError(Throwable e) {
132-
e.printStackTrace();
133-
}
134-
});
129+
RxJavaPlugins.getInstance().registerErrorHandler(Throwable::printStackTrace);
135130

136131
Observable.error(new IOException())
137132
.subscribe(System.out::println, e -> { });

src/jmh/java/io/reactivex/rxjava4/core/TakeUntilPerf.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ public Object call() {
6969
public void flowable() {
7070
final CountDownLatch cdl = new CountDownLatch(1);
7171

72-
flowable.subscribe(this, Functions.emptyConsumer(), new Action() {
73-
@Override
74-
public void run() {
75-
cdl.countDown();
76-
}
77-
});
72+
flowable.subscribe(this, Functions.emptyConsumer(), () -> cdl.countDown());
7873

7974
while (cdl.getCount() != 0) { }
8075
}
@@ -83,12 +78,7 @@ public void run() {
8378
public void observable() {
8479
final CountDownLatch cdl = new CountDownLatch(1);
8580

86-
observable.subscribe(this, Functions.emptyConsumer(), new Action() {
87-
@Override
88-
public void run() {
89-
cdl.countDown();
90-
}
91-
});
81+
observable.subscribe(this, Functions.emptyConsumer(), () -> cdl.countDown());
9282

9383
while (cdl.getCount() != 0) { }
9484
}

src/test/java/io/reactivex/rxjava4/completable/CompletableIsolatedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void repeatNormal() {
4040
return null;
4141
}).repeat();
4242

43-
c.subscribe(new CompletableObserver() {
43+
c.subscribe(new CompletableObserver() /* NFI */ {
4444
@Override
4545
public void onSubscribe(final Disposable d) {
4646
Schedulers.single().scheduleDirect(() -> d.dispose(), 1100, TimeUnit.MILLISECONDS);

src/test/java/io/reactivex/rxjava4/completable/CompletableRetryTest.java

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,22 @@ public void retryTimesPredicateWithMatchingPredicate() {
3030
final AtomicInteger atomicInteger = new AtomicInteger(3);
3131
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
3232

33-
Completable.fromAction(new Action() {
34-
@Override public void run() throws Exception {
35-
numberOfSubscribeCalls.incrementAndGet();
33+
Completable.fromAction(() -> {
34+
numberOfSubscribeCalls.incrementAndGet();
3635

37-
if (atomicInteger.decrementAndGet() != 0) {
38-
throw new RuntimeException();
39-
}
36+
if (atomicInteger.decrementAndGet() != 0) {
37+
throw new RuntimeException();
38+
}
4039

41-
throw new IllegalArgumentException();
40+
throw new IllegalArgumentException();
41+
})
42+
.retry(Integer.MAX_VALUE, new Predicate<Throwable>() {
43+
@Override public boolean test(final Throwable throwable) throws Exception {
44+
return !(throwable instanceof IllegalArgumentException);
4245
}
4346
})
44-
.retry(Integer.MAX_VALUE, new Predicate<Throwable>() {
45-
@Override public boolean test(final Throwable throwable) throws Exception {
46-
return !(throwable instanceof IllegalArgumentException);
47-
}
48-
})
49-
.test()
50-
.assertFailure(IllegalArgumentException.class);
47+
.test()
48+
.assertFailure(IllegalArgumentException.class);
5149

5250
assertEquals(3, numberOfSubscribeCalls.get());
5351
}
@@ -57,18 +55,16 @@ public void retryTimesPredicateWithMatchingRetryAmount() {
5755
final AtomicInteger atomicInteger = new AtomicInteger(3);
5856
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
5957

60-
Completable.fromAction(new Action() {
61-
@Override public void run() throws Exception {
62-
numberOfSubscribeCalls.incrementAndGet();
58+
Completable.fromAction(() -> {
59+
numberOfSubscribeCalls.incrementAndGet();
6360

64-
if (atomicInteger.decrementAndGet() != 0) {
65-
throw new RuntimeException();
66-
}
61+
if (atomicInteger.decrementAndGet() != 0) {
62+
throw new RuntimeException();
6763
}
6864
})
69-
.retry(2, Functions.alwaysTrue())
70-
.test()
71-
.assertResult();
65+
.retry(2, Functions.alwaysTrue())
66+
.test()
67+
.assertResult();
7268

7369
assertEquals(3, numberOfSubscribeCalls.get());
7470
}
@@ -78,18 +74,16 @@ public void retryTimesPredicateWithNotMatchingRetryAmount() {
7874
final AtomicInteger atomicInteger = new AtomicInteger(3);
7975
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
8076

81-
Completable.fromAction(new Action() {
82-
@Override public void run() throws Exception {
83-
numberOfSubscribeCalls.incrementAndGet();
77+
Completable.fromAction(() -> {
78+
numberOfSubscribeCalls.incrementAndGet();
8479

85-
if (atomicInteger.decrementAndGet() != 0) {
86-
throw new RuntimeException();
87-
}
80+
if (atomicInteger.decrementAndGet() != 0) {
81+
throw new RuntimeException();
8882
}
8983
})
90-
.retry(1, Functions.alwaysTrue())
91-
.test()
92-
.assertFailure(RuntimeException.class);
84+
.retry(1, Functions.alwaysTrue())
85+
.test()
86+
.assertFailure(RuntimeException.class);
9387

9488
assertEquals(2, numberOfSubscribeCalls.get());
9589
}
@@ -99,18 +93,16 @@ public void retryTimesPredicateWithZeroRetries() {
9993
final AtomicInteger atomicInteger = new AtomicInteger(2);
10094
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
10195

102-
Completable.fromAction(new Action() {
103-
@Override public void run() throws Exception {
104-
numberOfSubscribeCalls.incrementAndGet();
96+
Completable.fromAction(() -> {
97+
numberOfSubscribeCalls.incrementAndGet();
10598

106-
if (atomicInteger.decrementAndGet() != 0) {
107-
throw new RuntimeException();
108-
}
99+
if (atomicInteger.decrementAndGet() != 0) {
100+
throw new RuntimeException();
109101
}
110102
})
111-
.retry(0, Functions.alwaysTrue())
112-
.test()
113-
.assertFailure(RuntimeException.class);
103+
.retry(0, Functions.alwaysTrue())
104+
.test()
105+
.assertFailure(RuntimeException.class);
114106

115107
assertEquals(1, numberOfSubscribeCalls.get());
116108
}

0 commit comments

Comments
 (0)