Skip to content

Commit d231a3a

Browse files
committed
4.x: Unit test lambdaification 10 of N
1 parent ff3ccd6 commit d231a3a

19 files changed

Lines changed: 626 additions & 2226 deletions

src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableDelayTest.java

Lines changed: 42 additions & 189 deletions
Large diffs are not rendered by default.

src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableDematerializeTest.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ public void simpleSelector() {
5050
public void selectorCrash() {
5151
Flowable.just(1, 2)
5252
.materialize()
53-
.dematerialize(new Function<Notification<Integer>, Notification<Object>>() {
54-
@Override
55-
public Notification<Object> apply(Notification<Integer> v) throws Exception {
56-
throw new TestException();
57-
}
53+
.dematerialize(_ -> {
54+
throw new TestException();
5855
})
5956
.test()
6057
.assertFailure(TestException.class);
@@ -64,12 +61,7 @@ public Notification<Object> apply(Notification<Integer> v) throws Exception {
6461
public void selectorNull() {
6562
Flowable.just(1, 2)
6663
.materialize()
67-
.dematerialize(new Function<Notification<Integer>, Notification<Object>>() {
68-
@Override
69-
public Notification<Object> apply(Notification<Integer> v) throws Exception {
70-
return null;
71-
}
72-
})
64+
.dematerialize(_ -> null)
7365
.test()
7466
.assertFailure(NullPointerException.class);
7567
}
@@ -189,19 +181,15 @@ public void dispose() {
189181

190182
@Test
191183
public void doubleOnSubscribe() {
192-
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Notification<Object>>, Flowable<Object>>() {
193-
@Override
194-
public Flowable<Object> apply(Flowable<Notification<Object>> f) throws Exception {
195-
return f.dematerialize(Functions.<Notification<Object>>identity());
196-
}
197-
});
184+
TestHelper.checkDoubleOnSubscribeFlowable((Function<Flowable<Notification<Object>>, Flowable<Object>>) f ->
185+
f.dematerialize(Functions.<Notification<Object>>identity()));
198186
}
199187

200188
@Test
201189
public void eventsAfterDematerializedTerminal() {
202190
List<Throwable> errors = TestHelper.trackPluginErrors();
203191
try {
204-
new Flowable<Notification<Object>>() {
192+
new Flowable<Notification<Object>>() /* NFI */ {
205193
@Override
206194
protected void subscribeActual(Subscriber<? super Notification<Object>> subscriber) {
207195
subscriber.onSubscribe(new BooleanSubscription());
@@ -224,7 +212,7 @@ protected void subscribeActual(Subscriber<? super Notification<Object>> subscrib
224212

225213
@Test
226214
public void notificationInstanceAfterDispose() {
227-
new Flowable<Notification<Object>>() {
215+
new Flowable<Notification<Object>>() /* NFI */ {
228216
@Override
229217
protected void subscribeActual(Subscriber<? super Notification<Object>> subscriber) {
230218
subscriber.onSubscribe(new BooleanSubscription());
@@ -240,7 +228,7 @@ protected void subscribeActual(Subscriber<? super Notification<Object>> subscrib
240228
@Test
241229
@SuppressWarnings("unchecked")
242230
public void nonNotificationInstanceAfterDispose() {
243-
new Flowable<Object>() {
231+
new Flowable<Object>() /* NFI */ {
244232
@Override
245233
protected void subscribeActual(Subscriber<? super Object> subscriber) {
246234
subscriber.onSubscribe(new BooleanSubscription());

src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableDetachTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ public void deferredUpstreamProducer() {
137137

138138
TestSubscriber<Object> ts = new TestSubscriber<>(0);
139139

140-
Flowable.unsafeCreate(new Publisher<Object>() {
141-
@Override
142-
public void subscribe(Subscriber<? super Object> t) {
143-
subscriber.set(t);
144-
}
145-
}).onTerminateDetach().subscribe(ts);
140+
Flowable.unsafeCreate(t -> subscriber.set(t)).onTerminateDetach().subscribe(ts);
146141

147142
ts.request(2);
148143

@@ -164,11 +159,6 @@ public void dispose() {
164159

165160
@Test
166161
public void doubleOnSubscribe() {
167-
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() {
168-
@Override
169-
public Flowable<Object> apply(Flowable<Object> f) throws Exception {
170-
return f.onTerminateDetach();
171-
}
172-
});
162+
TestHelper.checkDoubleOnSubscribeFlowable((Function<Flowable<Object>, Flowable<Object>>) Flowable::onTerminateDetach);
173163
}
174164
}

src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableDistinctTest.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,11 @@ public class FlowableDistinctTest extends RxJavaTest {
4040
Subscriber<String> w;
4141

4242
// nulls lead to exceptions
43-
final Function<String, String> TO_UPPER_WITH_EXCEPTION = new Function<String, String>() {
44-
@Override
45-
public String apply(String s) {
46-
if (s.equals("x")) {
47-
return "XX";
48-
}
49-
return s.toUpperCase();
43+
final Function<String, String> TO_UPPER_WITH_EXCEPTION = s -> {
44+
if (s.equals("x")) {
45+
return "XX";
5046
}
47+
return s.toUpperCase();
5148
};
5249

5350
@Before
@@ -145,7 +142,7 @@ public void fusedAsync() {
145142
public void fusedClear() {
146143
Flowable.just(1, 1, 2, 1, 3, 2, 4, 5, 4)
147144
.distinct()
148-
.subscribe(new FlowableSubscriber<Integer>() {
145+
.subscribe(new FlowableSubscriber<Integer>() /* NFI */ {
149146
@Override
150147
public void onSubscribe(Subscription s) {
151148
QueueSubscription<?> qs = (QueueSubscription<?>)s;
@@ -174,11 +171,8 @@ public void onComplete() {
174171
@Test
175172
public void collectionSupplierThrows() {
176173
Flowable.just(1)
177-
.distinct(Functions.identity(), new Supplier<Collection<Object>>() {
178-
@Override
179-
public Collection<Object> get() throws Exception {
180-
throw new TestException();
181-
}
174+
.distinct(Functions.identity(), (Supplier<Collection<Object>>) () -> {
175+
throw new TestException();
182176
})
183177
.test()
184178
.assertFailure(TestException.class);
@@ -187,12 +181,7 @@ public Collection<Object> get() throws Exception {
187181
@Test
188182
public void collectionSupplierIsNull() {
189183
Flowable.just(1)
190-
.distinct(Functions.identity(), new Supplier<Collection<Object>>() {
191-
@Override
192-
public Collection<Object> get() throws Exception {
193-
return null;
194-
}
195-
})
184+
.distinct(Functions.identity(), (Supplier<Collection<Object>>) () -> null)
196185
.to(TestHelper.<Integer>testConsumer())
197186
.assertFailure(NullPointerException.class)
198187
.assertErrorMessage(ExceptionHelper.nullWarning("The collectionSupplier returned a null Collection."));
@@ -202,7 +191,7 @@ public Collection<Object> get() throws Exception {
202191
public void badSource() {
203192
List<Throwable> errors = TestHelper.trackPluginErrors();
204193
try {
205-
new Flowable<Integer>() {
194+
new Flowable<Integer>() /* NFI */ {
206195
@Override
207196
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
208197
subscriber.onSubscribe(new BooleanSubscription());

0 commit comments

Comments
 (0)