diff --git a/src/test/java/io/reactivex/rxjava4/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/rxjava4/flowable/FlowableNullTests.java index e9c7e17d59..d750fbaf44 100644 --- a/src/test/java/io/reactivex/rxjava4/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/rxjava4/flowable/FlowableNullTests.java @@ -71,7 +71,7 @@ public void combineLatestIterableOneIsNull() { @Test(expected = NullPointerException.class) public void combineLatestIterableFunctionReturnsNull() { - Flowable.combineLatestDelayError(Arrays.asList(just1), _ -> null).blockingLast(); + Flowable.combineLatestDelayError(Collections.singletonList(just1), _ -> null).blockingLast(); } @Test(expected = NullPointerException.class) @@ -387,7 +387,7 @@ public void flatMapIterableMapperIterableOneNull() { @Test(expected = NullPointerException.class) public void flatMapIterableCombinerReturnsNull() { - just1.flatMapIterable((Function>) _ -> Arrays.asList(1), + just1.flatMapIterable((Function>) _ -> List.of(1), (_, _) -> null).blockingSubscribe(); } @@ -633,7 +633,7 @@ public void zipWithIterableNull() { @Test(expected = NullPointerException.class) public void zipWithIterableCombinerReturnsNull() { - just1.zipWith(Arrays.asList(1), (_, _) -> null) + just1.zipWith(List.of(1), (_, _) -> null) .blockingSubscribe(); } @@ -735,7 +735,7 @@ public void serializedSubjectOnErrorNull() { @Test(expected = NullPointerException.class) public void combineLatestDelayErrorIterableFunctionReturnsNull() { - Flowable.combineLatestDelayError(Arrays.asList(just1), _ -> null, 128).blockingLast(); + Flowable.combineLatestDelayError(Collections.singletonList(just1), _ -> null, 128).blockingLast(); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/rxjava4/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/rxjava4/flowable/FlowableSubscriberTest.java index dd42979b94..f8dc04b568 100644 --- a/src/test/java/io/reactivex/rxjava4/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/rxjava4/flowable/FlowableSubscriberTest.java @@ -617,7 +617,7 @@ public void subscribeConsumerConsumerWithError() { Flowable.error(new TestException()).subscribe(v -> list.add(v), _ -> list.add(100)); - assertEquals(Arrays.asList(100), list); + assertEquals(List.of(100), list); } @Test @@ -652,7 +652,7 @@ public void subscribeConsumerConsumer() { Flowable.just(1).subscribe(v -> list.add(v), _ -> list.add(100)); - assertEquals(Arrays.asList(1), list); + assertEquals(List.of(1), list); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/observers/CompletableConsumersTest.java b/src/test/java/io/reactivex/rxjava4/internal/observers/CompletableConsumersTest.java index 963968ef3d..5d4c827034 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/observers/CompletableConsumersTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/observers/CompletableConsumersTest.java @@ -76,7 +76,7 @@ public void onErrorNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList("OnComplete"), events); + assertEquals(List.of("OnComplete"), events); } @@ -111,7 +111,7 @@ public void onCompleteNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList("OnComplete"), events); + assertEquals(List.of("OnComplete"), events); } @@ -208,7 +208,7 @@ protected void subscribeActual( } }.subscribe(this, this, composite); - assertEquals(Arrays.asList("OnComplete"), events); + assertEquals(List.of("OnComplete"), events); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { diff --git a/src/test/java/io/reactivex/rxjava4/internal/observers/MaybeConsumersTest.java b/src/test/java/io/reactivex/rxjava4/internal/observers/MaybeConsumersTest.java index f0bd7ada35..c909b1d0b5 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/observers/MaybeConsumersTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/observers/MaybeConsumersTest.java @@ -84,7 +84,7 @@ public void onSuccessNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); } @@ -101,7 +101,7 @@ public void onErrorNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); } @@ -136,7 +136,7 @@ public void onCompleteNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList("OnComplete"), events); + assertEquals(List.of("OnComplete"), events); } @@ -254,7 +254,7 @@ protected void subscribeActual( }, composite, this, this, this ); - assertEquals(Arrays.asList("OnComplete"), events); + assertEquals(List.of("OnComplete"), events); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { diff --git a/src/test/java/io/reactivex/rxjava4/internal/observers/ObservableConsumersTest.java b/src/test/java/io/reactivex/rxjava4/internal/observers/ObservableConsumersTest.java index 015d5e565f..5ece289cb4 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/observers/ObservableConsumersTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/observers/ObservableConsumersTest.java @@ -85,11 +85,11 @@ public void onNextNormal() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onComplete(); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); assertEquals(0, composite.size()); } @@ -107,11 +107,11 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onComplete(); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); assertEquals(0, composite.size()); } @@ -131,7 +131,7 @@ public void onErrorError() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onError(new IOException()); @@ -154,7 +154,7 @@ public void onCompleteNormal() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onComplete(); @@ -176,7 +176,7 @@ public void onCompleteError() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onError(new IOException()); @@ -276,7 +276,7 @@ public void onCompleteCrash() { processor.onNext(1); processor.onComplete(); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { diff --git a/src/test/java/io/reactivex/rxjava4/internal/observers/SingleConsumersTest.java b/src/test/java/io/reactivex/rxjava4/internal/observers/SingleConsumersTest.java index f2f53bac7f..aa0e43c783 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/observers/SingleConsumersTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/observers/SingleConsumersTest.java @@ -79,7 +79,7 @@ public void onSuccessNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); } @@ -96,7 +96,7 @@ public void onErrorNormal() { assertEquals(0, composite.size()); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); } @@ -176,7 +176,7 @@ protected void subscribeActual( }, composite, this, this ); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableMergeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableMergeTest.java index 6d7283affb..66d6bdb685 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableMergeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableMergeTest.java @@ -446,7 +446,7 @@ public void mergeArrayInnerErrorRace() { @Test public void delayErrorIterableCancel() { - Completable.mergeDelayError(Arrays.asList(Completable.complete())) + Completable.mergeDelayError(Collections.singletonList(Completable.complete())) .test(true) .assertEmpty(); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableBufferTest.java index 565333ac24..469a81ec8e 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableBufferTest.java @@ -280,7 +280,7 @@ public void bufferStopsWhenUnsubscribed1() { scheduler.advanceTimeBy(1001, TimeUnit.MILLISECONDS); - inOrder.verify(subscriber, times(5)).onNext(Arrays. asList()); + inOrder.verify(subscriber, times(5)).onNext(List.of()); ts.cancel(); @@ -317,7 +317,7 @@ public void bufferWithBONormal1() { source.onNext(6); boundary.onComplete(); - inOrder.verify(subscriber, times(1)).onNext(Arrays.asList(6)); + inOrder.verify(subscriber, times(1)).onNext(List.of(6)); inOrder.verify(subscriber).onComplete(); @@ -336,7 +336,7 @@ public void bufferWithBOEmptyLastViaBoundary() { boundary.onComplete(); - inOrder.verify(subscriber, times(1)).onNext(Arrays.asList()); + inOrder.verify(subscriber, times(1)).onNext(List.of()); inOrder.verify(subscriber).onComplete(); @@ -355,7 +355,7 @@ public void bufferWithBOEmptyLastViaSource() { source.onComplete(); - inOrder.verify(subscriber, times(1)).onNext(Arrays.asList()); + inOrder.verify(subscriber, times(1)).onNext(List.of()); inOrder.verify(subscriber).onComplete(); @@ -375,7 +375,7 @@ public void bufferWithBOEmptyLastViaBoth() { source.onComplete(); boundary.onComplete(); - inOrder.verify(subscriber, times(1)).onNext(Arrays.asList()); + inOrder.verify(subscriber, times(1)).onNext(List.of()); inOrder.verify(subscriber).onComplete(); @@ -495,8 +495,8 @@ public void bufferWithBoundaryTake2() { scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - inOrder.verify(subscriber).onNext(Arrays.asList(0L)); - inOrder.verify(subscriber).onNext(Arrays.asList(1L)); + inOrder.verify(subscriber).onNext(List.of(0L)); + inOrder.verify(subscriber).onNext(List.of(1L)); inOrder.verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); @@ -546,7 +546,7 @@ public void bufferWithSizeThrows() { inOrder.verify(subscriber).onNext(Arrays.asList(1, 2)); inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(subscriber, never()).onNext(Arrays.asList(3)); + verify(subscriber, never()).onNext(List.of(3)); verify(subscriber, never()).onComplete(); } @@ -572,7 +572,7 @@ public void bufferWithTimeThrows() { inOrder.verify(subscriber).onNext(Arrays.asList(1, 2)); inOrder.verify(subscriber).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(subscriber, never()).onNext(Arrays.asList(3)); + verify(subscriber, never()).onNext(List.of(3)); verify(subscriber, never()).onComplete(); } @@ -591,7 +591,7 @@ public void bufferWithTimeAndSize() { scheduler.advanceTimeBy(5, TimeUnit.SECONDS); inOrder.verify(subscriber).onNext(Arrays.asList(0L, 1L)); - inOrder.verify(subscriber).onNext(Arrays.asList(2L)); + inOrder.verify(subscriber).onNext(List.of(2L)); inOrder.verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); } @@ -872,7 +872,7 @@ public void onComplete() { cdl.await(); - verify(subscriber).onNext(Arrays.asList(1)); + verify(subscriber).onNext(List.of(1)); verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); @@ -948,7 +948,7 @@ public void postCompleteBackpressure() { Arrays.asList(7, 8, 9), Arrays.asList(8, 9, 10), Arrays.asList(9, 10), - Arrays.asList(10) + List.of(10) ); ts.assertComplete(); ts.assertNoErrors(); @@ -985,7 +985,7 @@ public void timeAndSkipOverlap() { Arrays.asList(1, 2), Arrays.asList(2, 3), Arrays.asList(3, 4), - Arrays.asList(4), + List.of(4), Collections.emptyList() ); @@ -1022,7 +1022,7 @@ public void timeAndSkipSkip() { ts.assertValues( Arrays.asList(1, 2), - Arrays.asList(4) + List.of(4) ); ts.assertNoErrors(); @@ -1063,7 +1063,7 @@ public void timeAndSkipOverlapScheduler() { Arrays.asList(1, 2), Arrays.asList(2, 3), Arrays.asList(3, 4), - Arrays.asList(4), + List.of(4), Collections.emptyList() ); @@ -1106,7 +1106,7 @@ public void timeAndSkipSkipDefaultScheduler() { ts.assertValues( Arrays.asList(1, 2), - Arrays.asList(4) + List.of(4) ); ts.assertNoErrors(); @@ -1324,7 +1324,7 @@ public void restartTimer() { Flowable.range(1, 5) .buffer(1, TimeUnit.DAYS, Schedulers.single(), 2, Functions.createArrayList(16), true) .test() - .assertResult(Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5)); + .assertResult(Arrays.asList(1, 2), Arrays.asList(3, 4), List.of(5)); } @Test @@ -1349,7 +1349,7 @@ public List get() throws Exception { } }) .test() - .assertFailure(TestException.class, Arrays.asList(1)); + .assertFailure(TestException.class, List.of(1)); } @Test @@ -1396,7 +1396,7 @@ public void bufferSkipOverlap() { Arrays.asList(2, 3, 4, 5), Arrays.asList(3, 4, 5), Arrays.asList(4, 5), - Arrays.asList(5) + List.of(5) ); } @@ -1475,7 +1475,7 @@ public List get() throws Exception { pp.onNext(2); ts - .assertFailure(TestException.class, Arrays.asList(1)); + .assertFailure(TestException.class, List.of(1)); } @Test @@ -1496,11 +1496,11 @@ public void bufferTimedExactBoundedError() { @Test public void badSource() { - TestHelper.checkBadSourceFlowable(f -> f.buffer(1), false, 1, 1, Arrays.asList(1)); + TestHelper.checkBadSourceFlowable(f -> f.buffer(1), false, 1, 1, List.of(1)); - TestHelper.checkBadSourceFlowable(f -> f.buffer(1, 2), false, 1, 1, Arrays.asList(1)); + TestHelper.checkBadSourceFlowable(f -> f.buffer(1, 2), false, 1, 1, List.of(1)); - TestHelper.checkBadSourceFlowable(f -> f.buffer(2, 1), false, 1, 1, Arrays.asList(1)); + TestHelper.checkBadSourceFlowable(f -> f.buffer(2, 1), false, 1, 1, List.of(1)); } @Test @@ -1534,7 +1534,7 @@ public void skipSingleResult() { Flowable.just(1) .buffer(2, 3) .test() - .assertResult(Arrays.asList(1)); + .assertResult(List.of(1)); } @Test @@ -1543,7 +1543,7 @@ public void skipBackpressure() { .buffer(2, 3) .rebatchRequests(1) .test() - .assertResult(Arrays.asList(1, 2), Arrays.asList(4, 5), Arrays.asList(7, 8), Arrays.asList(10)); + .assertResult(Arrays.asList(1, 2), Arrays.asList(4, 5), Arrays.asList(7, 8), List.of(10)); } @Test @@ -2205,7 +2205,7 @@ public void boundaryCloseCompleteRace() { () -> pp.onComplete() ); - ts.assertResult(Arrays.asList(1)); + ts.assertResult(List.of(1)); } } @@ -2225,7 +2225,7 @@ public void startEndCancelAfterOneBuffer() { .buffer(BehaviorProcessor.createDefault(2), _ -> Flowable.just(1)) .takeUntil(_ -> true) .test() - .assertResult(Arrays.asList()); + .assertResult(List.of()); } @Test @@ -2242,7 +2242,7 @@ public void startEndBackpressure() { BehaviorProcessor.createDefault(1) .buffer(BehaviorProcessor.createDefault(2), _ -> Flowable.just(1)) .test(1L) - .assertValuesOnly(Arrays.asList()); + .assertValuesOnly(List.of()); } @Test @@ -2265,6 +2265,6 @@ public void startEndBackpressureMoreWork() { bp.onNext(1); ts - .assertValuesOnly(Arrays.asList()); + .assertValuesOnly(List.of()); } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapEagerTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapEagerTest.java index 639f19d574..f01c6ff91f 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapEagerTest.java @@ -593,7 +593,7 @@ public void concatEagerZero() { @Test public void concatEagerOne() { - Flowable.concatEager(Arrays.asList(Flowable.just(1))) + Flowable.concatEager(Collections.singletonList(Flowable.just(1))) .test() .assertResult(1); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapSchedulerTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapSchedulerTest.java index 5cf8cb5515..64b2a803e9 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapSchedulerTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatMapSchedulerTest.java @@ -338,7 +338,7 @@ public void concatMapRangeAsyncLoopIssue2876() { } TestSubscriberEx ts = new TestSubscriberEx<>(); Flowable.range(0, 1000) - .concatMap(t -> Flowable.fromIterable(Arrays.asList(t)), 2, ImmediateThinScheduler.INSTANCE) + .concatMap(t -> Flowable.fromIterable(Collections.singletonList(t)), 2, ImmediateThinScheduler.INSTANCE) .observeOn(Schedulers.computation()).subscribe(ts); ts.awaitDone(2500, TimeUnit.MILLISECONDS); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatTest.java index 55843ae924..784527a776 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableConcatTest.java @@ -782,7 +782,7 @@ public void concatMapRangeAsyncLoopIssue2876() { } TestSubscriberEx ts = new TestSubscriberEx<>(); Flowable.range(0, 1000) - .concatMap(t -> Flowable.fromIterable(Arrays.asList(t))) + .concatMap(t -> Flowable.fromIterable(Collections.singletonList(t))) .observeOn(Schedulers.computation()).subscribe(ts); ts.awaitDone(2500, TimeUnit.MILLISECONDS); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableElementAtTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableElementAtTest.java index 81e4e4a373..3f4499b877 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableElementAtTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableElementAtTest.java @@ -78,7 +78,7 @@ public void elementAtConstrainsUpstreamRequests() { .elementAt(2) .blockingGet() .intValue(); - assertEquals(Arrays.asList(3L), requests); + assertEquals(List.of(3L), requests); } @Test @@ -89,7 +89,7 @@ public void elementAtWithDefaultConstrainsUpstreamRequests() { .elementAt(2, 100) .blockingGet() .intValue(); - assertEquals(Arrays.asList(3L), requests); + assertEquals(List.of(3L), requests); } @Test(expected = IndexOutOfBoundsException.class) diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlatMapTest.java index 8220f3e554..f06f8e77a7 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlatMapTest.java @@ -127,8 +127,8 @@ Supplier just0(final R value) { @Test public void flatMapTransformsNormal() { Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onComplete = Flowable.fromIterable(List.of(4)); + Flowable onError = Flowable.fromIterable(List.of(5)); Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); @@ -149,8 +149,8 @@ public void flatMapTransformsNormal() { @Test public void flatMapTransformsException() { Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onComplete = Flowable.fromIterable(List.of(4)); + Flowable onError = Flowable.fromIterable(List.of(5)); Flowable source = Flowable.concat( Flowable.fromIterable(Arrays.asList(10, 20, 30)), @@ -187,8 +187,8 @@ Function funcThrow(T t, R r) { public void flatMapTransformsOnNextFuncThrows() { List errors = TestHelper.trackPluginErrors(); try { - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onComplete = Flowable.fromIterable(List.of(4)); + Flowable onError = Flowable.fromIterable(List.of(5)); Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); @@ -209,8 +209,8 @@ public void flatMapTransformsOnNextFuncThrows() { @Test public void flatMapTransformsOnErrorFuncThrows() { Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onComplete = Flowable.fromIterable(List.of(4)); + Flowable onError = Flowable.fromIterable(List.of(5)); Flowable source = Flowable.error(new TestException()); @@ -226,10 +226,10 @@ public void flatMapTransformsOnErrorFuncThrows() { @Test public void flatMapTransformsOnCompletedFuncThrows() { Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onComplete = Flowable.fromIterable(List.of(4)); + Flowable onError = Flowable.fromIterable(List.of(5)); - Flowable source = Flowable.fromIterable(Arrays. asList()); + Flowable source = Flowable.fromIterable(List.of()); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -243,8 +243,8 @@ public void flatMapTransformsOnCompletedFuncThrows() { @Test public void flatMapTransformsMergeException() { Flowable onNext = Flowable.error(new TestException()); - Flowable onComplete = Flowable.fromIterable(Arrays.asList(4)); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onComplete = Flowable.fromIterable(List.of(4)); + Flowable onError = Flowable.fromIterable(List.of(5)); Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); @@ -338,10 +338,10 @@ public void flatMapTransformsMaxConcurrentNormal() { .subscribeOn(Schedulers.computation()) ; - Flowable onComplete = composer(Flowable.fromIterable(Arrays.asList(4)), subscriptionCount, m) + Flowable onComplete = composer(Flowable.fromIterable(List.of(4)), subscriptionCount, m) .subscribeOn(Schedulers.computation()); - Flowable onError = Flowable.fromIterable(Arrays.asList(5)); + Flowable onError = Flowable.fromIterable(List.of(5)); Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlattenIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlattenIterableTest.java index 19e6f5e2b6..ddcbe69734 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlattenIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFlattenIterableTest.java @@ -456,7 +456,7 @@ public void withResultSelectorMaxConcurrent() { @Test public void flatMapIterablePrefetch() { Flowable.just(1, 2) - .flatMapIterable((Function>) t -> Arrays.asList(t * 10), 1) + .flatMapIterable((Function>) t -> List.of(t * 10), 1) .test() .assertResult(10, 20); } @@ -599,7 +599,7 @@ public void fusedIsEmptyWithEmptySource() { if ((v & 1) == 0) { return Collections.emptyList(); } - return Arrays.asList(v); + return List.of(v); }) .subscribe(new FlowableSubscriber() /* NFI */ { @Override @@ -652,7 +652,7 @@ public void fusedSourceCrash() { @Test public void take() { Flowable.range(1, 3) - .flatMapIterable(Functions.justFunction(Arrays.asList(1)), 1) + .flatMapIterable(Functions.justFunction(List.of(1)), 1) .take(1) .test() .assertResult(1); @@ -669,7 +669,7 @@ protected void subscribeActual(Subscriber s) { s.onNext(3); } } - .flatMapIterable(Functions.justFunction(Arrays.asList(1)), 1) + .flatMapIterable(Functions.justFunction(List.of(1)), 1) .test(0L) .assertFailure(QueueOverflowException.class); } @@ -677,7 +677,7 @@ protected void subscribeActual(Subscriber s) { @Test public void oneByOne() { Flowable.range(1, 3).hide() - .flatMapIterable(Functions.justFunction(Arrays.asList(1)), 1) + .flatMapIterable(Functions.justFunction(List.of(1)), 1) .rebatchRequests(1) .test() .assertResult(1, 1, 1); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFromIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFromIterableTest.java index 105d8fe018..e463dbfb50 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFromIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableFromIterableTest.java @@ -992,7 +992,7 @@ public void remove() { public void fusedPoll() throws Throwable { AtomicReference> queue = new AtomicReference<>(); - Flowable.fromIterable(Arrays.asList(1)) + Flowable.fromIterable(List.of(1)) .subscribe(new FlowableSubscriber() /* NFI */ { @Override public void onSubscribe(@NonNull Subscription s) { diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableGroupByTest.java index bc7a2fbe83..e5ef513d9d 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableGroupByTest.java @@ -61,7 +61,7 @@ public void groupBy() { assertEquals(3, map.size()); assertArrayEquals(Arrays.asList("one", "two", "six").toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList("four", "five").toArray(), map.get(4).toArray()); - assertArrayEquals(Arrays.asList("three").toArray(), map.get(5).toArray()); + assertArrayEquals(List.of("three").toArray(), map.get(5).toArray()); } @Test @@ -74,7 +74,7 @@ public void groupByWithElementSelector() { assertEquals(3, map.size()); assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray()); - assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray()); + assertArrayEquals(List.of(5).toArray(), map.get(5).toArray()); } @Test @@ -87,7 +87,7 @@ public void groupByWithElementSelector2() { assertEquals(3, map.size()); assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray()); - assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray()); + assertArrayEquals(List.of(5).toArray(), map.get(5).toArray()); } @Test @@ -942,9 +942,9 @@ public void onNext(GroupedFlowable f) { subscriber.onError(e); } ).groupBy(i -> i % 2).subscribe(outer); - assertEquals(Arrays.asList(e), outer.errors()); - assertEquals(Arrays.asList(e), inner1.errors()); - assertEquals(Arrays.asList(e), inner2.errors()); + assertEquals(List.of(e), outer.errors()); + assertEquals(List.of(e), inner1.errors()); + assertEquals(List.of(e), inner2.errors()); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMaterializeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMaterializeTest.java index b5b58caddc..1f380be6da 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMaterializeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMaterializeTest.java @@ -160,7 +160,7 @@ public void backpressureWithError() { public void backpressureWithEmissionThenError() { TestSubscriber> ts = new TestSubscriber<>(0L); IllegalArgumentException ex = new IllegalArgumentException(); - Flowable.fromIterable(Arrays.asList(1)).concatWith(Flowable. error(ex)).materialize() + Flowable.fromIterable(List.of(1)).concatWith(Flowable. error(ex)).materialize() .subscribe(ts); ts.assertNoValues(); ts.request(1); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMergeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMergeTest.java index d7e65c234d..0339015d59 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMergeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableMergeTest.java @@ -13,7 +13,6 @@ package io.reactivex.rxjava4.internal.operators.flowable; -import static java.util.Arrays.asList; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -1005,7 +1004,7 @@ public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_No subscriber.request(3); // 1, 2, subscriber.assertValues(1, 2); subscriber.assertTerminated(); - assertEquals(asList(exception), subscriber.errors()); + assertEquals(List.of(exception), subscriber.errors()); } @Test @@ -1017,7 +1016,7 @@ public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_Fa subscriber.request(2); // 1, subscriber.assertValue(1); subscriber.assertTerminated(); - assertEquals(asList(exception), subscriber.errors()); + assertEquals(List.of(exception), subscriber.errors()); } @Test @@ -1041,7 +1040,7 @@ public void shouldNotReceivedDelayedErrorWhileThereAreStillScalarSynchronousEmis assertEquals(Collections.emptyList(), subscriber.errors()); subscriber.request(1); subscriber.assertValues(1, 2); - assertEquals(asList(exception), subscriber.errors()); + assertEquals(List.of(exception), subscriber.errors()); } @Test @@ -1055,7 +1054,7 @@ public void shouldNotReceivedDelayedErrorWhileThereAreStillNormalEmissionsInTheQ assertEquals(Collections.emptyList(), subscriber.errors()); subscriber.request(2); subscriber.assertValues(1, 2, 3, 4); - assertEquals(asList(exception), subscriber.errors()); + assertEquals(List.of(exception), subscriber.errors()); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableObserveOnTest.java index 482fd2cfcb..ff557e3a2d 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableObserveOnTest.java @@ -695,7 +695,7 @@ public void onNext(Integer t) { }); assertTrue(latch.await(10, TimeUnit.SECONDS)); // FIXME observeOn requests bufferSize at first always - assertEquals(Arrays.asList(128L), requests); + assertEquals(List.of(128L), requests); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayEagerTruncateTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayEagerTruncateTest.java index 2496e9f337..2bdf222d5e 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayEagerTruncateTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayEagerTruncateTest.java @@ -709,7 +709,7 @@ public void timedAndSizedTruncation() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -722,7 +722,7 @@ public void timedAndSizedTruncation() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); test.advanceTimeBy(2, TimeUnit.SECONDS); buf.complete(); @@ -1450,7 +1450,7 @@ public void timedAndSizedTruncationError() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -1463,7 +1463,7 @@ public void timedAndSizedTruncationError() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); Assert.assertFalse(buf.hasCompleted()); Assert.assertFalse(buf.hasError()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayTest.java index 123b7ea690..fc41a5bc46 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableReplayTest.java @@ -726,7 +726,7 @@ public void timedAndSizedTruncation() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -739,7 +739,7 @@ public void timedAndSizedTruncation() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); test.advanceTimeBy(2, TimeUnit.SECONDS); buf.complete(); @@ -1515,7 +1515,7 @@ public void timedAndSizedTruncationError() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -1528,7 +1528,7 @@ public void timedAndSizedTruncationError() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); Assert.assertFalse(buf.hasCompleted()); Assert.assertFalse(buf.hasError()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSingleTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSingleTest.java index e52d11441f..f2a37361bd 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSingleTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSingleTest.java @@ -105,7 +105,7 @@ public void onNext(Integer t) { } }); // FIXME single now triggers fast-path - assertEquals(Arrays.asList(Long.MAX_VALUE), requests); + assertEquals(List.of(Long.MAX_VALUE), requests); } @Test @@ -140,7 +140,7 @@ public void onNext(Integer t) { } }); // FIXME single now triggers fast-path - assertEquals(Arrays.asList(Long.MAX_VALUE), requests); + assertEquals(List.of(Long.MAX_VALUE), requests); } @Test @@ -175,7 +175,7 @@ public void onNext(Integer t) { } }); // FIXME single now triggers fast-path - assertEquals(Arrays.asList(Long.MAX_VALUE), requests); + assertEquals(List.of(Long.MAX_VALUE), requests); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index 2403bfb54b..9c0f16873c 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -16,6 +16,7 @@ import static org.junit.Assert.*; import java.util.Arrays; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -43,7 +44,7 @@ public void switchWhenNotEmpty() throws Exception { @Test public void switchWhenEmpty() throws Exception { final Flowable flowable = Flowable.empty() - .switchIfEmpty(Flowable.fromIterable(Arrays.asList(42))); + .switchIfEmpty(Flowable.fromIterable(List.of(42))); assertEquals(42, flowable.blockingSingle().intValue()); } @@ -124,7 +125,7 @@ public void switchRequestAlternativeObservableWithBackpressure() { Flowable.empty().switchIfEmpty(Flowable.just(1, 2, 3)).subscribe(ts); - assertEquals(Arrays.asList(1), ts.values()); + assertEquals(List.of(1), ts.values()); ts.assertNoErrors(); ts.request(1); ts.assertValueCount(2); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchTest.java index d25ed6a800..63c9c92685 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableSwitchTest.java @@ -52,21 +52,15 @@ public void before() { @Test public void switchWhenOuterCompleteBeforeInner() { - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 70, "one"); - publishNext(subscriber, 100, "two"); - publishCompleted(subscriber, 200); - } - })); - publishCompleted(subscriber, 60); - } + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 70, "one"); + publishNext(subscriber1, 100, "two"); + publishCompleted(subscriber1, 200); + })); + publishCompleted(subscriber, 60); }); Flowable sampled = Flowable.switchOnNext(source); @@ -81,31 +75,22 @@ public void subscribe(Subscriber subscriber) { @Test public void switchWhenInnerCompleteBeforeOuter() { - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 10, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 0, "one"); - publishNext(subscriber, 10, "two"); - publishCompleted(subscriber, 20); - } - })); - - publishNext(subscriber, 100, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 0, "three"); - publishNext(subscriber, 10, "four"); - publishCompleted(subscriber, 20); - } - })); - publishCompleted(subscriber, 200); - } + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 10, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 0, "one"); + publishNext(subscriber1, 10, "two"); + publishCompleted(subscriber1, 20); + })); + + publishNext(subscriber, 100, Flowable.unsafeCreate(subscriber2 -> { + subscriber2.onSubscribe(new BooleanSubscription()); + publishNext(subscriber2, 0, "three"); + publishNext(subscriber2, 10, "four"); + publishCompleted(subscriber2, 20); + })); + publishCompleted(subscriber, 200); }); Flowable sampled = Flowable.switchOnNext(source); @@ -127,30 +112,21 @@ public void subscribe(Subscriber subscriber) { @Test public void switchWithComplete() { - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(final Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 60, "one"); - publishNext(subscriber, 100, "two"); - } - })); - - publishNext(subscriber, 200, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(final Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 0, "three"); - publishNext(subscriber, 100, "four"); - } - })); - - publishCompleted(subscriber, 250); - } + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 60, "one"); + publishNext(subscriber1, 100, "two"); + })); + + publishNext(subscriber, 200, Flowable.unsafeCreate(subscriber2 -> { + subscriber2.onSubscribe(new BooleanSubscription()); + publishNext(subscriber2, 0, "three"); + publishNext(subscriber2, 100, "four"); + })); + + publishCompleted(subscriber, 250); }); Flowable sampled = Flowable.switchOnNext(source); @@ -186,30 +162,21 @@ public void subscribe(final Subscriber subscriber) { @Test public void switchWithError() { - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(final Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, "one"); - publishNext(subscriber, 100, "two"); - } - })); - - publishNext(subscriber, 200, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 0, "three"); - publishNext(subscriber, 100, "four"); - } - })); - - publishError(subscriber, 250, new TestException()); - } + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 50, "one"); + publishNext(subscriber1, 100, "two"); + })); + + publishNext(subscriber, 200, Flowable.unsafeCreate(subscriber2 -> { + subscriber2.onSubscribe(new BooleanSubscription()); + publishNext(subscriber2, 0, "three"); + publishNext(subscriber2, 100, "four"); + })); + + publishError(subscriber, 250, new TestException()); }); Flowable sampled = Flowable.switchOnNext(source); @@ -245,35 +212,23 @@ public void subscribe(Subscriber subscriber) { @Test public void switchWithSubsequenceComplete() { - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, "one"); - publishNext(subscriber, 100, "two"); - } - })); - - publishNext(subscriber, 130, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishCompleted(subscriber, 0); - } - })); - - publishNext(subscriber, 150, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, "three"); - } - })); - } + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 50, "one"); + publishNext(subscriber1, 100, "two"); + })); + + publishNext(subscriber, 130, Flowable.unsafeCreate(subscriber2 -> { + subscriber2.onSubscribe(new BooleanSubscription()); + publishCompleted(subscriber2, 0); + })); + + publishNext(subscriber, 150, Flowable.unsafeCreate(subscriber3 -> { + subscriber3.onSubscribe(new BooleanSubscription()); + publishNext(subscriber3, 50, "three"); + })); }); Flowable sampled = Flowable.switchOnNext(source); @@ -299,36 +254,24 @@ public void subscribe(Subscriber subscriber) { @Test public void switchWithSubsequenceError() { - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, "one"); - publishNext(subscriber, 100, "two"); - } - })); + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 50, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 50, "one"); + publishNext(subscriber1, 100, "two"); + })); + + publishNext(subscriber, 130, Flowable.unsafeCreate(subscriber2 -> { + subscriber2.onSubscribe(new BooleanSubscription()); + publishError(subscriber2, 0, new TestException()); + })); + + publishNext(subscriber, 150, Flowable.unsafeCreate(subscriber3 -> { + subscriber3.onSubscribe(new BooleanSubscription()); + publishNext(subscriber3, 50, "three"); + })); - publishNext(subscriber, 130, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishError(subscriber, 0, new TestException()); - } - })); - - publishNext(subscriber, 150, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 50, "three"); - } - })); - - } }); Flowable sampled = Flowable.switchOnNext(source); @@ -353,62 +296,38 @@ public void subscribe(Subscriber subscriber) { } private void publishCompleted(final Subscriber subscriber, long delay) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onComplete(); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onComplete(), delay, TimeUnit.MILLISECONDS); } private void publishError(final Subscriber subscriber, long delay, final Throwable error) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onError(error); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onError(error), delay, TimeUnit.MILLISECONDS); } private void publishNext(final Subscriber subscriber, long delay, final T value) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onNext(value); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onNext(value), delay, TimeUnit.MILLISECONDS); } @Test public void switchIssue737() { // https://github.com/ReactiveX/RxJava/issues/737 - Flowable> source = Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(Subscriber> subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 0, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 10, "1-one"); - publishNext(subscriber, 20, "1-two"); - // The following events will be ignored - publishNext(subscriber, 30, "1-three"); - publishCompleted(subscriber, 40); - } - })); - publishNext(subscriber, 25, Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 10, "2-one"); - publishNext(subscriber, 20, "2-two"); - publishNext(subscriber, 30, "2-three"); - publishCompleted(subscriber, 40); - } - })); - publishCompleted(subscriber, 30); - } + Flowable> source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 0, Flowable.unsafeCreate(subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + publishNext(subscriber1, 10, "1-one"); + publishNext(subscriber1, 20, "1-two"); + // The following events will be ignored + publishNext(subscriber1, 30, "1-three"); + publishCompleted(subscriber1, 40); + })); + publishNext(subscriber, 25, Flowable.unsafeCreate(subscriber2 -> { + subscriber2.onSubscribe(new BooleanSubscription()); + publishNext(subscriber2, 10, "2-one"); + publishNext(subscriber2, 20, "2-two"); + publishNext(subscriber2, 30, "2-three"); + publishCompleted(subscriber2, 40); + })); + publishCompleted(subscriber, 30); }); Flowable sampled = Flowable.switchOnNext(source); @@ -492,14 +411,11 @@ public void onNext(String s) { public void unsubscribe() { final AtomicBoolean isUnsubscribed = new AtomicBoolean(); Flowable.switchOnNext( - Flowable.unsafeCreate(new Publisher>() { - @Override - public void subscribe(final Subscriber> subscriber) { - BooleanSubscription bs = new BooleanSubscription(); - subscriber.onSubscribe(bs); - subscriber.onNext(Flowable.just(1)); - isUnsubscribed.set(bs.isCancelled()); - } + Flowable.unsafeCreate((Publisher>) subscriber -> { + BooleanSubscription bs = new BooleanSubscription(); + subscriber.onSubscribe(bs); + subscriber.onNext(Flowable.just(1)); + isUnsubscribed.set(bs.isCancelled()); }) ).take(1).subscribe(); assertTrue("Switch doesn't propagate 'unsubscribe'", isUnsubscribed.get()); @@ -509,19 +425,9 @@ public void subscribe(final Subscriber> subscriber) { public void issue2654() { Flowable oneItem = Flowable.just("Hello").mergeWith(Flowable.never()); - Flowable src = oneItem.switchMap(new Function>() { - @Override - public Flowable apply(final String s) { - return Flowable.just(s) - .mergeWith(Flowable.interval(10, TimeUnit.MILLISECONDS) - .map(new Function() { - @Override - public String apply(Long i) { - return s + " " + i; - } - })).take(250); - } - }) + Flowable src = oneItem.switchMap((Function>) s -> Flowable.just(s) + .mergeWith(Flowable.interval(10, TimeUnit.MILLISECONDS) + .map(i -> s + " " + i)).take(250)) .share() ; @@ -553,12 +459,7 @@ public void initialRequestsAreAdditive() { Flowable.switchOnNext( Flowable.interval(100, TimeUnit.MILLISECONDS) .map( - new Function>() { - @Override - public Flowable apply(Long t) { - return Flowable.just(1L, 2L, 3L); - } - } + _ -> Flowable.just(1L, 2L, 3L) ).take(3)) .subscribe(ts); ts.request(Long.MAX_VALUE - 100); @@ -571,12 +472,7 @@ public void initialRequestsDontOverflow() { TestSubscriber ts = new TestSubscriber<>(0L); Flowable.switchOnNext( Flowable.interval(100, TimeUnit.MILLISECONDS) - .map(new Function>() { - @Override - public Flowable apply(Long t) { - return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)).hide(); - } - }).take(3)).subscribe(ts); + .map(_ -> Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)).hide()).take(3)).subscribe(ts); ts.request(Long.MAX_VALUE - 1); ts.request(2); ts.awaitDone(5, TimeUnit.SECONDS); @@ -588,12 +484,7 @@ public void secondaryRequestsDontOverflow() throws InterruptedException { TestSubscriber ts = new TestSubscriber<>(0L); Flowable.switchOnNext( Flowable.interval(100, TimeUnit.MILLISECONDS) - .map(new Function>() { - @Override - public Flowable apply(Long t) { - return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)).hide(); - } - }).take(3)).subscribe(ts); + .map(_ -> Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)).hide()).take(3)).subscribe(ts); ts.request(1); //we will miss two of the first observable Thread.sleep(250); @@ -641,12 +532,7 @@ public void delayErrors() { public void switchOnNextPrefetch() { final List list = new ArrayList<>(); - Flowable source = Flowable.range(1, 10).hide().doOnNext(new Consumer() { - @Override - public void accept(Integer v) throws Exception { - list.add(v); - } - }); + Flowable source = Flowable.range(1, 10).hide().doOnNext(v -> list.add(v)); Flowable.switchOnNext(Flowable.just(source).hide(), 2) .test(1); @@ -658,12 +544,7 @@ public void accept(Integer v) throws Exception { public void switchOnNextDelayError() { final List list = new ArrayList<>(); - Flowable source = Flowable.range(1, 10).hide().doOnNext(new Consumer() { - @Override - public void accept(Integer v) throws Exception { - list.add(v); - } - }); + Flowable source = Flowable.range(1, 10).hide().doOnNext(v -> list.add(v)); Flowable.switchOnNextDelayError(Flowable.just(source).hide()) .test(1); @@ -675,12 +556,7 @@ public void accept(Integer v) throws Exception { public void switchOnNextDelayErrorPrefetch() { final List list = new ArrayList<>(); - Flowable source = Flowable.range(1, 10).hide().doOnNext(new Consumer() { - @Override - public void accept(Integer v) throws Exception { - list.add(v); - } - }); + Flowable source = Flowable.range(1, 10).hide().doOnNext(v -> list.add(v)); Flowable.switchOnNextDelayError(Flowable.just(source).hide(), 2) .test(1); @@ -718,23 +594,13 @@ public void switchOnNextDelayErrorBufferSize() { @Test public void switchMapDelayErrorEmptySource() { assertSame(Flowable.empty(), Flowable.empty() - .switchMapDelayError(new Function>() { - @Override - public Publisher apply(Object v) throws Exception { - return Flowable.just(1); - } - }, 16)); + .switchMapDelayError((Function>) _ -> Flowable.just(1), 16)); } @Test public void switchMapDelayErrorJustSource() { Flowable.just(0) - .switchMapDelayError(new Function>() { - @Override - public Publisher apply(Object v) throws Exception { - return Flowable.just(1); - } - }, 16) + .switchMapDelayError((Function>) _ -> Flowable.just(1), 16) .test() .assertResult(1); @@ -743,23 +609,13 @@ public Publisher apply(Object v) throws Exception { @Test public void switchMapErrorEmptySource() { assertSame(Flowable.empty(), Flowable.empty() - .switchMap(new Function>() { - @Override - public Publisher apply(Object v) throws Exception { - return Flowable.just(1); - } - }, 16)); + .switchMap((Function>) _ -> Flowable.just(1), 16)); } @Test public void switchMapJustSource() { Flowable.just(0) - .switchMap(new Function>() { - @Override - public Publisher apply(Object v) throws Exception { - return Flowable.just(1); - } - }, 16) + .switchMap((Function>) _ -> Flowable.just(1), 16) .test() .assertResult(1); @@ -795,32 +651,19 @@ public void nextSourceErrorRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - pp1.switchMap(new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - if (v == 1) { - return pp2; - } - return Flowable.never(); + pp1.switchMap((Function>) v -> { + if (v == 1) { + return pp2; } + return Flowable.never(); }) .test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp1.onNext(2); - } - }; + Runnable r1 = () -> pp1.onNext(2); final TestException ex = new TestException(); - Runnable r2 = new Runnable() { - @Override - public void run() { - pp2.onError(ex); - } - }; + Runnable r2 = () -> pp2.onError(ex); TestHelper.race(r1, r2); @@ -842,34 +685,21 @@ public void outerInnerErrorRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - pp1.switchMap(new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - if (v == 1) { - return pp2; - } - return Flowable.never(); + pp1.switchMap((Function>) v -> { + if (v == 1) { + return pp2; } + return Flowable.never(); }) .test(); final TestException ex1 = new TestException(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp1.onError(ex1); - } - }; + Runnable r1 = () -> pp1.onError(ex1); final TestException ex2 = new TestException(); - Runnable r2 = new Runnable() { - @Override - public void run() { - pp2.onError(ex2); - } - }; + Runnable r2 = () -> pp2.onError(ex2); TestHelper.race(r1, r2); @@ -887,27 +717,12 @@ public void nextCancelRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final PublishProcessor pp1 = PublishProcessor.create(); - final TestSubscriber ts = pp1.switchMap(new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - return Flowable.never(); - } - }) + final TestSubscriber ts = pp1.switchMap((Function>) _ -> Flowable.never()) .test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp1.onNext(2); - } - }; + Runnable r1 = () -> pp1.onNext(2); - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r2 = () -> ts.cancel(); TestHelper.race(r1, r2); } @@ -916,11 +731,8 @@ public void run() { @Test public void mapperThrows() { Flowable.just(1).hide() - .switchMap(new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - throw new TestException(); - } + .switchMap((Function>) _ -> { + throw new TestException(); }) .test() .assertFailure(TestException.class); @@ -1055,12 +867,7 @@ public void scalarXMap() { @Test public void badSource() { - TestHelper.checkBadSourceFlowable(new Function, Object>() { - @Override - public Object apply(Flowable f) throws Exception { - return f.switchMap(Functions.justFunction(Flowable.just(1))); - } - }, false, 1, 1, 1); + TestHelper.checkBadSourceFlowable(f -> f.switchMap(Functions.justFunction(Flowable.just(1))), false, 1, 1, 1); } @Test @@ -1090,19 +897,9 @@ public void drainCancelRace() { .switchMap(Functions.justFunction(pp)) .subscribe(ts); - Runnable r1 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r1 = () -> ts.cancel(); - Runnable r2 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r2 = () -> pp.onNext(1); TestHelper.race(r1, r2); } @@ -1112,11 +909,8 @@ public void run() { public void fusedInnerCrash() { Flowable.just(1).hide() .switchMap(Functions.justFunction(Flowable.just(1) - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { - throw new TestException(); - } + .map(_ -> { + throw new TestException(); }) .compose(TestHelper.flowableStripBoundary()) ) @@ -1151,20 +945,11 @@ public void fusedBoundary() { String thread = Thread.currentThread().getName(); Flowable.range(1, 10000) - .switchMap(new Function>() { - @Override - public Flowable apply(Integer v) - throws Exception { - return Flowable.just(2).hide() - .observeOn(Schedulers.single()) - .map(new Function() { - @Override - public Object apply(Integer w) throws Exception { - return Thread.currentThread().getName(); - } - }); - } - }) + .switchMap((Function>) _ -> Flowable.just(2).hide() + .observeOn(Schedulers.single()) + .map((Function) _ -> { + return Thread.currentThread().getName(); + })) .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertNever(thread) @@ -1179,19 +964,11 @@ public void undeliverableUponCancel() { final TestSubscriberEx ts = new TestSubscriberEx<>(); Flowable.just(1) - .map(new Function() { - @Override - public Integer apply(Integer v) throws Throwable { - ts.cancel(); - throw new TestException(); - } - }) - .switchMap(new Function>() { - @Override - public Publisher apply(Integer v) throws Throwable { - return Flowable.just(v).hide(); - } + .map((Function) _ -> { + ts.cancel(); + throw new TestException(); }) + .switchMap((Function>) v -> Flowable.just(v).hide()) .subscribe(ts); ts.assertEmpty(); @@ -1205,13 +982,7 @@ public Publisher apply(Integer v) throws Throwable { @Test public void switchMapFusedIterable() { Flowable.range(1, 2) - .switchMap(new Function>() { - @Override - public Publisher apply(Integer v) - throws Throwable { - return Flowable.fromIterable(Arrays.asList(v * 10)); - } - }) + .switchMap((Function>) v -> Flowable.fromIterable(List.of(v * 10))) .test() .assertResult(10, 20); } @@ -1219,13 +990,7 @@ public Publisher apply(Integer v) @Test public void switchMapHiddenIterable() { Flowable.range(1, 2) - .switchMap(new Function>() { - @Override - public Publisher apply(Integer v) - throws Throwable { - return Flowable.fromIterable(Arrays.asList(v * 10)).hide(); - } - }) + .switchMap((Function>) v -> Flowable.fromIterable(List.of(v * 10)).hide()) .test() .assertResult(10, 20); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeTest.java index 58795329ff..e79416b247 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeTest.java @@ -70,23 +70,17 @@ public void take2() { @Test(expected = IllegalArgumentException.class) public void takeWithError() { Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1) - .map(new Function() { - @Override - public Integer apply(Integer t1) { - throw new IllegalArgumentException("some error"); - } + .map((Function) _ -> { + throw new IllegalArgumentException("some error"); }).blockingSingle(); } @Test public void takeWithErrorHappeningInOnNext() { Flowable w = Flowable.fromIterable(Arrays.asList(1, 2, 3)) - .take(2).map(new Function() { - @Override - public Integer apply(Integer t1) { - throw new IllegalArgumentException("some error"); - } - }); + .take(2).map(_ -> { + throw new IllegalArgumentException("some error"); + }); Subscriber subscriber = TestHelper.mockSubscriber(); w.subscribe(subscriber); @@ -98,11 +92,8 @@ public Integer apply(Integer t1) { @Test public void takeWithErrorHappeningInTheLastOnNext() { - Flowable w = Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1).map(new Function() { - @Override - public Integer apply(Integer t1) { - throw new IllegalArgumentException("some error"); - } + Flowable w = Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1).map(_ -> { + throw new IllegalArgumentException("some error"); }); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -117,13 +108,10 @@ public Integer apply(Integer t1) { public void takeDoesntLeakErrors() { List errors = TestHelper.trackPluginErrors(); try { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - subscriber.onNext("one"); - subscriber.onError(new Throwable("test failed")); - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new Throwable("test failed")); }); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -196,42 +184,22 @@ public void unsubscribeAfterTake() { @Test public void unsubscribeFromSynchronousInfiniteFlowable() { final AtomicLong count = new AtomicLong(); - INFINITE_OBSERVABLE.take(10).subscribe(new Consumer() { - - @Override - public void accept(Long l) { - count.set(l); - } - - }); + INFINITE_OBSERVABLE.take(10).subscribe(l -> count.set(l)); assertEquals(10, count.get()); } @Test public void multiTake() { final AtomicInteger count = new AtomicInteger(); - Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(Subscriber s) { - BooleanSubscription bs = new BooleanSubscription(); - s.onSubscribe(bs); - for (int i = 0; !bs.isCancelled(); i++) { - System.out.println("Emit: " + i); - count.incrementAndGet(); - s.onNext(i); - } - } - - }).take(100).take(1).blockingForEach(new Consumer() { - - @Override - public void accept(Integer t1) { - System.out.println("Receive: " + t1); - + Flowable.unsafeCreate((Publisher) s -> { + BooleanSubscription bs = new BooleanSubscription(); + s.onSubscribe(bs); + for (int i = 0; !bs.isCancelled(); i++) { + System.out.println("Emit: " + i); + count.incrementAndGet(); + s.onNext(i); } - - }); + }).take(100).take(1).blockingForEach(t1 -> System.out.println("Receive: " + t1)); assertEquals(1, count.get()); } @@ -249,22 +217,17 @@ static class TestFlowableFunc implements Publisher { public void subscribe(final Subscriber subscriber) { subscriber.onSubscribe(new BooleanSubscription()); System.out.println("TestFlowable subscribed to ..."); - t = new Thread(new Runnable() { - - @Override - public void run() { - try { - System.out.println("running TestFlowable thread"); - for (String s : values) { - System.out.println("TestFlowable onNext: " + s); - subscriber.onNext(s); - } - subscriber.onComplete(); - } catch (Throwable e) { - throw new RuntimeException(e); + t = new Thread(() -> { + try { + System.out.println("running TestFlowable thread"); + for (String s : values) { + System.out.println("TestFlowable onNext: " + s); + subscriber.onNext(s); } + subscriber.onComplete(); + } catch (Throwable e) { + throw new RuntimeException(e); } - }); System.out.println("starting TestFlowable thread"); t.start(); @@ -272,19 +235,14 @@ public void run() { } } - private static Flowable INFINITE_OBSERVABLE = Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(Subscriber op) { - BooleanSubscription bs = new BooleanSubscription(); - op.onSubscribe(bs); - long l = 1; - while (!bs.isCancelled()) { - op.onNext(l++); - } - op.onComplete(); + private static Flowable INFINITE_OBSERVABLE = Flowable.unsafeCreate(op -> { + BooleanSubscription bs = new BooleanSubscription(); + op.onSubscribe(bs); + long l = 1; + while (!bs.isCancelled()) { + op.onNext(l++); } - + op.onComplete(); }); @Test @@ -307,25 +265,18 @@ public void takeObserveOn() { public void producerRequestThroughTake() { TestSubscriber ts = new TestSubscriber<>(3); final AtomicLong requested = new AtomicLong(); - Flowable.unsafeCreate(new Publisher() { + Flowable.unsafeCreate((Publisher) s -> s.onSubscribe(new Subscription() { @Override - public void subscribe(Subscriber s) { - s.onSubscribe(new Subscription() { - - @Override - public void request(long n) { - requested.set(n); - } + public void request(long n) { + requested.set(n); + } - @Override - public void cancel() { + @Override + public void cancel() { - } - }); } - - }).take(3).subscribe(ts); + })).take(3).subscribe(ts); assertEquals(3, requested.get()); } @@ -333,25 +284,18 @@ public void cancel() { public void producerRequestThroughTakeIsModified() { TestSubscriber ts = new TestSubscriber<>(3); final AtomicLong requested = new AtomicLong(); - Flowable.unsafeCreate(new Publisher() { + Flowable.unsafeCreate((Publisher) s -> s.onSubscribe(new Subscription() { @Override - public void subscribe(Subscriber s) { - s.onSubscribe(new Subscription() { - - @Override - public void request(long n) { - requested.set(n); - } + public void request(long n) { + requested.set(n); + } - @Override - public void cancel() { + @Override + public void cancel() { - } - }); } - - }).take(1).subscribe(ts); + })).take(1).subscribe(ts); //FIXME take triggers fast path if downstream requests more than the limit assertEquals(1, requested.get()); } @@ -361,20 +305,15 @@ public void interrupt() throws InterruptedException { final AtomicReference exception = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); Flowable.just(1).subscribeOn(Schedulers.computation()).take(1) - .subscribe(new Consumer() { - - @Override - public void accept(Integer t1) { - try { - Thread.sleep(100); - } catch (Exception e) { - exception.set(e); - e.printStackTrace(); - } finally { - latch.countDown(); - } + .subscribe(_ -> { + try { + Thread.sleep(100); + } catch (Exception e) { + exception.set(e); + e.printStackTrace(); + } finally { + latch.countDown(); } - }); latch.await(); @@ -387,12 +326,10 @@ public void doesntRequestMoreThanNeededFromUpstream() throws InterruptedExceptio TestSubscriber ts = new TestSubscriber<>(0L); Flowable.interval(100, TimeUnit.MILLISECONDS) // - .doOnRequest(new LongConsumer() { - @Override - public void accept(long n) { - System.out.println(n); - requests.addAndGet(n); - }}) + .doOnRequest(n -> { + System.out.println(n); + requests.addAndGet(n); + }) // .take(2) // @@ -431,12 +368,7 @@ public void reentrantTake() { TestSubscriber ts = new TestSubscriber<>(); - source.take(1).doOnNext(new Consumer() { - @Override - public void accept(Integer v) { - source.onNext(2); - } - }).subscribe(ts); + source.take(1).doOnNext(_ -> source.onNext(2)).subscribe(ts); source.onNext(1); @@ -470,12 +402,7 @@ public void dispose() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { - @Override - public Flowable apply(Flowable f) throws Exception { - return f.take(2); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>) f -> f.take(2)); } @Test @@ -489,12 +416,7 @@ public void requestRace() { final TestSubscriber ts = Flowable.range(1, 2).take(2).test(0L); - Runnable r1 = new Runnable() { - @Override - public void run() { - ts.request(1); - } - }; + Runnable r1 = () -> ts.request(1); TestHelper.race(r1, r1); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeWhileTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeWhileTest.java index 93da4b6e58..c5a921883f 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeWhileTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTakeWhileTest.java @@ -37,12 +37,7 @@ public class FlowableTakeWhileTest extends RxJavaTest { @Test public void takeWhile1() { Flowable w = Flowable.just(1, 2, 3); - Flowable take = w.takeWhile(new Predicate() { - @Override - public boolean test(Integer input) { - return input < 3; - } - }); + Flowable take = w.takeWhile(input -> input < 3); Subscriber subscriber = TestHelper.mockSubscriber(); take.subscribe(subscriber); @@ -57,12 +52,7 @@ public boolean test(Integer input) { @Test public void takeWhileOnSubject1() { FlowableProcessor s = PublishProcessor.create(); - Flowable take = s.takeWhile(new Predicate() { - @Override - public boolean test(Integer input) { - return input < 3; - } - }); + Flowable take = s.takeWhile(input -> input < 3); Subscriber subscriber = TestHelper.mockSubscriber(); take.subscribe(subscriber); @@ -109,21 +99,13 @@ public boolean test(String input) { public void takeWhileDoesntLeakErrors() { List errors = TestHelper.trackPluginErrors(); try { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - subscriber.onNext("one"); - subscriber.onError(new TestException("test failed")); - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + subscriber.onNext("one"); + subscriber.onError(new TestException("test failed")); }); - source.takeWhile(new Predicate() { - @Override - public boolean test(String s) { - return false; - } - }).blockingLast(""); + source.takeWhile(_ -> false).blockingLast(""); TestHelper.assertUndeliverable(errors, 0, TestException.class, "test failed"); } finally { @@ -138,12 +120,9 @@ public void takeWhileProtectsPredicateCall() { Subscriber subscriber = TestHelper.mockSubscriber(); Flowable take = Flowable.unsafeCreate(source) - .takeWhile(new Predicate() { - @Override - public boolean test(String s) { - throw testException; - } - }); + .takeWhile(_ -> { + throw testException; + }); take.subscribe(subscriber); // wait for the Flowable to complete @@ -205,22 +184,17 @@ private static class TestFlowable implements Publisher { public void subscribe(final Subscriber subscriber) { System.out.println("TestFlowable subscribed to ..."); subscriber.onSubscribe(upstream); - t = new Thread(new Runnable() { - - @Override - public void run() { - try { - System.out.println("running TestFlowable thread"); - for (String s : values) { - System.out.println("TestFlowable onNext: " + s); - subscriber.onNext(s); - } - subscriber.onComplete(); - } catch (Throwable e) { - throw new RuntimeException(e); + t = new Thread(() -> { + try { + System.out.println("running TestFlowable thread"); + for (String s : values) { + System.out.println("TestFlowable onNext: " + s); + subscriber.onNext(s); } + subscriber.onComplete(); + } catch (Throwable e) { + throw new RuntimeException(e); } - }); System.out.println("starting TestFlowable thread"); t.start(); @@ -230,12 +204,7 @@ public void run() { @Test public void backpressure() { - Flowable source = Flowable.range(1, 1000).takeWhile(new Predicate() { - @Override - public boolean test(Integer t1) { - return t1 < 100; - } - }); + Flowable source = Flowable.range(1, 1000).takeWhile(t1 -> t1 < 100); TestSubscriber ts = new TestSubscriber<>(5L); source.subscribe(ts); @@ -251,12 +220,7 @@ public boolean test(Integer t1) { @Test public void noUnsubscribeDownstream() { - Flowable source = Flowable.range(1, 1000).takeWhile(new Predicate() { - @Override - public boolean test(Integer t1) { - return t1 < 2; - } - }); + Flowable source = Flowable.range(1, 1000).takeWhile(t1 -> t1 < 2); TestSubscriber ts = new TestSubscriber<>(); source.subscribe(ts); @@ -270,11 +234,8 @@ public boolean test(Integer t1) { @Test public void errorCauseIncludesLastValue() { TestSubscriberEx ts = new TestSubscriberEx<>(); - Flowable.just("abc").takeWhile(new Predicate() { - @Override - public boolean test(String t1) { - throw new TestException(); - } + Flowable.just("abc").takeWhile(_ -> { + throw new TestException(); }).subscribe(ts); ts.assertTerminated(); @@ -291,12 +252,7 @@ public void dispose() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { - @Override - public Flowable apply(Flowable f) throws Exception { - return f.takeWhile(Functions.alwaysTrue()); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>) f -> f.takeWhile(Functions.alwaysTrue())); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableThrottleFirstTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableThrottleFirstTest.java index a09549b32e..8b1a700e0c 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableThrottleFirstTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableThrottleFirstTest.java @@ -47,16 +47,13 @@ public void before() { @Test public void throttlingWithDropCallbackCrashes() throws Throwable { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 100, "one"); // publish as it's first - publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 - publishNext(subscriber, 900, "three"); // publish - publishNext(subscriber, 905, "four"); // skip - publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 100, "one"); // publish as it's first + publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 + publishNext(subscriber, 900, "three"); // publish + publishNext(subscriber, 905, "four"); // skip + publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. }); Action whenDisposed = mock(Action.class); @@ -85,16 +82,13 @@ public void subscribe(Subscriber subscriber) { @Test public void throttlingWithDropCallback() { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 100, "one"); // publish as it's first - publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 - publishNext(subscriber, 900, "three"); // publish - publishNext(subscriber, 905, "four"); // skip - publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 100, "one"); // publish as it's first + publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 + publishNext(subscriber, 900, "three"); // publish + publishNext(subscriber, 905, "four"); // skip + publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. }); Observer dropCallbackObserver = TestHelper.mockObserver(); @@ -118,16 +112,13 @@ public void subscribe(Subscriber subscriber) { @Test public void throttlingWithCompleted() { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - publishNext(subscriber, 100, "one"); // publish as it's first - publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 - publishNext(subscriber, 900, "three"); // publish - publishNext(subscriber, 905, "four"); // skip - publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + publishNext(subscriber, 100, "one"); // publish as it's first + publishNext(subscriber, 300, "two"); // skip as it's last within the first 400 + publishNext(subscriber, 900, "three"); // publish + publishNext(subscriber, 905, "four"); // skip + publishCompleted(subscriber, 1000); // Should be published as soon as the timeout expires. }); Flowable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); @@ -146,15 +137,12 @@ public void subscribe(Subscriber subscriber) { @Test public void throttlingWithError() { - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - Exception error = new TestException(); - publishNext(subscriber, 100, "one"); // Should be published since it is first - publishNext(subscriber, 200, "two"); // Should be skipped since onError will arrive before the timeout expires - publishError(subscriber, 300, error); // Should be published as soon as the timeout expires. - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + Exception error = new TestException(); + publishNext(subscriber, 100, "one"); // Should be published since it is first + publishNext(subscriber, 200, "two"); // Should be skipped since onError will arrive before the timeout expires + publishError(subscriber, 300, error); // Should be published as soon as the timeout expires. }); Flowable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); @@ -169,30 +157,15 @@ public void subscribe(Subscriber subscriber) { } private void publishCompleted(final Subscriber subscriber, long delay) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onComplete(); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onComplete(), delay, TimeUnit.MILLISECONDS); } private void publishError(final Subscriber subscriber, long delay, final Exception error) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onError(error); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onError(error), delay, TimeUnit.MILLISECONDS); } private void publishNext(final Subscriber subscriber, long delay, final T value) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onNext(value); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onNext(value), delay, TimeUnit.MILLISECONDS); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeIntervalTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeIntervalTest.java index 8dd9a359da..804901aced 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeIntervalTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeIntervalTest.java @@ -23,7 +23,6 @@ import io.reactivex.rxjava4.core.*; import io.reactivex.rxjava4.exceptions.TestException; -import io.reactivex.rxjava4.functions.Function; import io.reactivex.rxjava4.plugins.RxJavaPlugins; import io.reactivex.rxjava4.processors.PublishProcessor; import io.reactivex.rxjava4.schedulers.*; @@ -74,22 +73,12 @@ public void timeInterval() { public void timeIntervalDefault() { final TestScheduler scheduler = new TestScheduler(); - RxJavaPlugins.setComputationSchedulerHandler(new Function() { - @Override - public Scheduler apply(Scheduler v) throws Exception { - return scheduler; - } - }); + RxJavaPlugins.setComputationSchedulerHandler(_ -> scheduler); try { Flowable.range(1, 5) .timeInterval() - .map(new Function, Long>() { - @Override - public Long apply(Timed v) throws Exception { - return v.time(); - } - }) + .map(v -> v.time()) .test() .assertResult(0L, 0L, 0L, 0L, 0L); } finally { @@ -101,22 +90,12 @@ public Long apply(Timed v) throws Exception { public void timeIntervalDefaultSchedulerCustomUnit() { final TestScheduler scheduler = new TestScheduler(); - RxJavaPlugins.setComputationSchedulerHandler(new Function() { - @Override - public Scheduler apply(Scheduler v) throws Exception { - return scheduler; - } - }); + RxJavaPlugins.setComputationSchedulerHandler(_ -> scheduler); try { Flowable.range(1, 5) .timeInterval(TimeUnit.SECONDS) - .map(new Function, Long>() { - @Override - public Long apply(Timed v) throws Exception { - return v.time(); - } - }) + .map(v -> v.time()) .test() .assertResult(0L, 0L, 0L, 0L, 0L); } finally { @@ -139,12 +118,6 @@ public void error() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>>() { - @Override - public Publisher> apply(Flowable f) - throws Exception { - return f.timeInterval(); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable(f -> f.timeInterval()); } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutTests.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutTests.java index 44a3644467..f91c54a919 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutTests.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutTests.java @@ -236,29 +236,18 @@ public void shouldTimeoutIfSynchronizedFlowableEmitFirstOnNextNotWithinTimeout() final TestSubscriberEx subscriber = new TestSubscriberEx<>(); - new Thread(new Runnable() { - - @Override - public void run() { - Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - try { - timeoutSetuped.countDown(); - exit.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - subscriber.onNext("a"); - subscriber.onComplete(); - } - - }).timeout(1, TimeUnit.SECONDS, testScheduler) - .subscribe(subscriber); + new Thread(() -> Flowable.unsafeCreate((Publisher) subscriber1 -> { + subscriber1.onSubscribe(new BooleanSubscription()); + try { + timeoutSetuped.countDown(); + exit.await(); + } catch (InterruptedException e) { + e.printStackTrace(); } - }).start(); + subscriber1.onNext("a"); + subscriber1.onComplete(); + }).timeout(1, TimeUnit.SECONDS, testScheduler) + .subscribe(subscriber)).start(); timeoutSetuped.await(); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -273,12 +262,7 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws Interr // From https://github.com/ReactiveX/RxJava/pull/951 final Subscription s = mock(Subscription.class); - Flowable never = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(s); - } - }); + Flowable never = Flowable.unsafeCreate(subscriber -> subscriber.onSubscribe(s)); TestScheduler testScheduler = new TestScheduler(); Flowable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); @@ -460,19 +444,9 @@ public void onNextOnTimeoutRace() { TestSubscriberEx ts = pp.timeout(1, TimeUnit.SECONDS, sch).to(TestHelper.testConsumer()); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r1 = () -> pp.onNext(1); - Runnable r2 = new Runnable() { - @Override - public void run() { - sch.advanceTimeBy(1, TimeUnit.SECONDS); - } - }; + Runnable r2 = () -> sch.advanceTimeBy(1, TimeUnit.SECONDS); TestHelper.race(r1, r2); @@ -499,19 +473,9 @@ public void onNextOnTimeoutRaceFallback() { TestSubscriberEx ts = pp.timeout(1, TimeUnit.SECONDS, sch, Flowable.just(2)).to(TestHelper.testConsumer()); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r1 = () -> pp.onNext(1); - Runnable r2 = new Runnable() { - @Override - public void run() { - sch.advanceTimeBy(1, TimeUnit.SECONDS); - } - }; + Runnable r2 = () -> sch.advanceTimeBy(1, TimeUnit.SECONDS); TestHelper.race(r1, r2); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java index 64ff0101b3..65840c1f15 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.mockito.InOrder; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import static java.util.concurrent.Flow.*; @@ -46,14 +45,9 @@ public void timeoutSelectorNormal1() { PublishProcessor source = PublishProcessor.create(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return timeout; - } - }; + Function> timeoutFunc = _ -> timeout; - Flowable other = Flowable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(List.of(100)); Subscriber subscriber = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(subscriber); @@ -79,14 +73,9 @@ public void timeoutSelectorTimeoutFirst() throws InterruptedException { Flowable source = Flowable.never(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return timeout; - } - }; + Function> timeoutFunc = _ -> timeout; - Flowable other = Flowable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(List.of(100)); Subscriber subscriber = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(subscriber); @@ -106,21 +95,13 @@ public void timeoutSelectorFirstThrows() { Flowable source = Flowable.never(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return timeout; - } - }; + Function> timeoutFunc = _ -> timeout; - Supplier> firstTimeoutFunc = new Supplier>() { - @Override - public Flowable get() { - throw new TestException(); - } + Supplier> firstTimeoutFunc = () -> { + throw new TestException(); }; - Flowable other = Flowable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(List.of(100)); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -137,14 +118,11 @@ public void timeoutSelectorSubsequentThrows() { PublishProcessor source = PublishProcessor.create(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - throw new TestException(); - } + Function> timeoutFunc = _ -> { + throw new TestException(); }; - Flowable other = Flowable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(List.of(100)); Subscriber subscriber = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(subscriber); @@ -164,14 +142,9 @@ public void timeoutSelectorFirstFlowableThrows() { PublishProcessor source = PublishProcessor.create(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return timeout; - } - }; + Function> timeoutFunc = _ -> timeout; - Flowable other = Flowable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(List.of(100)); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -188,14 +161,9 @@ public void timeoutSelectorSubsequentFlowableThrows() { PublishProcessor source = PublishProcessor.create(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return Flowable. error(new TestException()); - } - }; + Function> timeoutFunc = _ -> Flowable. error(new TestException()); - Flowable other = Flowable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(List.of(100)); Subscriber subscriber = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(subscriber); @@ -215,12 +183,7 @@ public void timeoutSelectorWithFirstTimeoutFirstAndNoOtherFlowable() { PublishProcessor source = PublishProcessor.create(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return PublishProcessor.create(); - } - }; + Function> timeoutFunc = _ -> PublishProcessor.create(); Subscriber subscriber = TestHelper.mockSubscriber(); source.timeout(timeout, timeoutFunc).subscribe(subscriber); @@ -237,12 +200,7 @@ public void timeoutSelectorWithTimeoutFirstAndNoOtherFlowable() { PublishProcessor source = PublishProcessor.create(); final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - return timeout; - } - }; + Function> timeoutFunc = _ -> timeout; Subscriber subscriber = TestHelper.mockSubscriber(); source.timeout(PublishProcessor.create(), timeoutFunc).subscribe(subscriber); @@ -276,87 +234,66 @@ public void timeoutSelectorWithTimeoutAndOnNextRaceCondition() throws Interrupte final CountDownLatch enteredTimeoutOne = new CountDownLatch(1); final AtomicBoolean latchTimeout = new AtomicBoolean(false); - final Function> timeoutFunc = new Function>() { - @Override - public Flowable apply(Integer t1) { - if (t1 == 1) { - // Force "unsubscribe" run on another thread - return Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - enteredTimeoutOne.countDown(); - // force the timeout message be sent after observer.onNext(2) - while (true) { - try { - if (!observerReceivedTwo.await(30, TimeUnit.SECONDS)) { - // CountDownLatch timeout - // There should be something wrong - latchTimeout.set(true); - } - break; - } catch (InterruptedException e) { - // Since we just want to emulate a busy method, - // we ignore the interrupt signal from Scheduler. - } + final Function> timeoutFunc = t1 -> { + if (t1 == 1) { + // Force "unsubscribe" run on another thread + return Flowable.unsafeCreate((Publisher) subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + enteredTimeoutOne.countDown(); + // force the timeout message be sent after observer.onNext(2) + while (true) { + try { + if (!observerReceivedTwo.await(30, TimeUnit.SECONDS)) { + // CountDownLatch timeout + // There should be something wrong + latchTimeout.set(true); } - subscriber.onNext(1); - timeoutEmittedOne.countDown(); + break; + } catch (InterruptedException e) { + // Since we just want to emulate a busy method, + // we ignore the interrupt signal from Scheduler. } - }).subscribeOn(Schedulers.newThread()); - } else { - return PublishProcessor.create(); - } + } + subscriber.onNext(1); + timeoutEmittedOne.countDown(); + }).subscribeOn(Schedulers.newThread()); + } else { + return PublishProcessor.create(); } }; final Subscriber subscriber = TestHelper.mockSubscriber(); - doAnswer(new Answer() { - - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - observerReceivedTwo.countDown(); - return null; - } - + doAnswer((Answer) _ -> { + observerReceivedTwo.countDown(); + return null; }).when(subscriber).onNext(2); - doAnswer(new Answer() { - - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - observerCompleted.countDown(); - return null; - } - + doAnswer((Answer) _ -> { + observerCompleted.countDown(); + return null; }).when(subscriber).onComplete(); final TestSubscriber ts = new TestSubscriber<>(subscriber); - new Thread(new Runnable() { - - @Override - public void run() { - PublishProcessor source = PublishProcessor.create(); - source.timeout(timeoutFunc, Flowable.just(3)).subscribe(ts); - source.onNext(1); // start timeout - try { - if (!enteredTimeoutOne.await(30, TimeUnit.SECONDS)) { - latchTimeout.set(true); - } - } catch (InterruptedException e) { - e.printStackTrace(); + new Thread(() -> { + PublishProcessor source = PublishProcessor.create(); + source.timeout(timeoutFunc, Flowable.just(3)).subscribe(ts); + source.onNext(1); // start timeout + try { + if (!enteredTimeoutOne.await(30, TimeUnit.SECONDS)) { + latchTimeout.set(true); } - source.onNext(2); // disable timeout - try { - if (!timeoutEmittedOne.await(30, TimeUnit.SECONDS)) { - latchTimeout.set(true); - } - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + source.onNext(2); // disable timeout + try { + if (!timeoutEmittedOne.await(30, TimeUnit.SECONDS)) { + latchTimeout.set(true); } - source.onComplete(); + } catch (InterruptedException e) { + e.printStackTrace(); } - + source.onComplete(); }).start(); if (!observerCompleted.await(30, TimeUnit.SECONDS)) { @@ -383,19 +320,11 @@ public void dispose() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { - @Override - public Flowable apply(Flowable f) throws Exception { - return f.timeout(Functions.justFunction(Flowable.never())); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>) f -> + f.timeout(Functions.justFunction(Flowable.never()))); - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { - @Override - public Flowable apply(Flowable f) throws Exception { - return f.timeout(Functions.justFunction(Flowable.never()), Flowable.never()); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>) f -> + f.timeout(Functions.justFunction(Flowable.never()), Flowable.never())); } @Test @@ -582,21 +511,11 @@ protected void subscribeActual( pp.onNext(0); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r1 = () -> pp.onNext(1); final Throwable ex = new TestException(); - Runnable r2 = new Runnable() { - @Override - public void run() { - sub[0].onError(ex); - } - }; + Runnable r2 = () -> sub[0].onError(ex); TestHelper.race(r1, r2); @@ -637,21 +556,11 @@ protected void subscribeActual( pp.onNext(0); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r1 = () -> pp.onNext(1); final Throwable ex = new TestException(); - Runnable r2 = new Runnable() { - @Override - public void run() { - sub[0].onError(ex); - } - }; + Runnable r2 = () -> sub[0].onError(ex); TestHelper.race(r1, r2); @@ -694,19 +603,9 @@ protected void subscribeActual( final Throwable ex = new TestException(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onError(ex); - } - }; + Runnable r1 = () -> pp.onError(ex); - Runnable r2 = new Runnable() { - @Override - public void run() { - sub[0].onComplete(); - } - }; + Runnable r2 = () -> sub[0].onComplete(); TestHelper.race(r1, r2); @@ -747,19 +646,9 @@ protected void subscribeActual( pp.onNext(0); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onComplete(); - } - }; + Runnable r1 = () -> pp.onComplete(); - Runnable r2 = new Runnable() { - @Override - public void run() { - sub[0].onComplete(); - } - }; + Runnable r2 = () -> sub[0].onComplete(); TestHelper.race(r1, r2); @@ -800,19 +689,9 @@ protected void subscribeActual( pp.onNext(0); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onComplete(); - } - }; + Runnable r1 = () -> pp.onComplete(); - Runnable r2 = new Runnable() { - @Override - public void run() { - sub[0].onComplete(); - } - }; + Runnable r2 = () -> sub[0].onComplete(); TestHelper.race(r1, r2); @@ -832,12 +711,7 @@ public void disposedUpfront() { PublishProcessor pp = PublishProcessor.create(); final AtomicInteger counter = new AtomicInteger(); - Flowable timeoutAndFallback = Flowable.never().doOnSubscribe(new Consumer() { - @Override - public void accept(Subscription s) throws Exception { - counter.incrementAndGet(); - } - }); + Flowable timeoutAndFallback = Flowable.never().doOnSubscribe(_ -> counter.incrementAndGet()); pp .timeout(timeoutAndFallback, Functions.justFunction(timeoutAndFallback)) @@ -852,12 +726,7 @@ public void disposedUpfrontFallback() { PublishProcessor pp = PublishProcessor.create(); final AtomicInteger counter = new AtomicInteger(); - Flowable timeoutAndFallback = Flowable.never().doOnSubscribe(new Consumer() { - @Override - public void accept(Subscription s) throws Exception { - counter.incrementAndGet(); - } - }); + Flowable timeoutAndFallback = Flowable.never().doOnSubscribe(_ -> counter.incrementAndGet()); pp .timeout(timeoutAndFallback, Functions.justFunction(timeoutAndFallback), timeoutAndFallback) diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToListTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToListTest.java index 35360703e8..d260dce848 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToListTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToListTest.java @@ -216,11 +216,8 @@ public void errorSingle() { @Test public void collectionSupplierThrows() { Flowable.just(1) - .toList(new Supplier>() { - @Override - public Collection get() throws Exception { - throw new TestException(); - } + .toList((Supplier>) () -> { + throw new TestException(); }) .toFlowable() .test() @@ -230,12 +227,7 @@ public Collection get() throws Exception { @Test public void collectionSupplierReturnsNull() { Flowable.just(1) - .toList(new Supplier>() { - @Override - public Collection get() throws Exception { - return null; - } - }) + .toList((Supplier>) () -> null) .toFlowable() .to(TestHelper.>testConsumer()) .assertFailure(NullPointerException.class) @@ -245,11 +237,8 @@ public Collection get() throws Exception { @Test public void singleCollectionSupplierThrows() { Flowable.just(1) - .toList(new Supplier>() { - @Override - public Collection get() throws Exception { - throw new TestException(); - } + .toList((Supplier>) () -> { + throw new TestException(); }) .test() .assertFailure(TestException.class); @@ -258,12 +247,7 @@ public Collection get() throws Exception { @Test public void singleCollectionSupplierReturnsNull() { Flowable.just(1) - .toList(new Supplier>() { - @Override - public Collection get() throws Exception { - return null; - } - }) + .toList((Supplier>) () -> null) .to(TestHelper.>testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage(ExceptionHelper.nullWarning("The collectionSupplier returned a null Collection.")); @@ -275,18 +259,8 @@ public void onNextCancelRace() { final PublishProcessor pp = PublishProcessor.create(); final TestObserver> to = pp.toList().test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - to.dispose(); - } - }; + Runnable r1 = () -> pp.onNext(1); + Runnable r2 = () -> to.dispose(); TestHelper.race(r1, r2); } @@ -298,18 +272,8 @@ public void onNextCancelRaceFlowable() { final PublishProcessor pp = PublishProcessor.create(); final TestSubscriber> ts = pp.toList().toFlowable().test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r1 = () -> pp.onNext(1); + Runnable r2 = () -> ts.cancel(); TestHelper.race(r1, r2); } @@ -324,23 +288,13 @@ public void onCompleteCancelRaceFlowable() { pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onComplete(); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r1 = () -> pp.onComplete(); + Runnable r2 = () -> ts.cancel(); TestHelper.race(r1, r2); if (ts.values().size() != 0) { - ts.assertValue(Arrays.asList(1)) + ts.assertValue(List.of(1)) .assertNoErrors(); } } @@ -348,19 +302,9 @@ public void run() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { - @Override - public Flowable> apply(Flowable f) - throws Exception { - return f.toList().toFlowable(); - } - }); - TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function, Single>>() { - @Override - public Single> apply(Flowable f) - throws Exception { - return f.toList(); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>>) f -> + f.toList().toFlowable()); + TestHelper.checkDoubleOnSubscribeFlowableToSingle((Function, Single>>) f -> + f.toList()); } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMapTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMapTest.java index aa9a5f2a98..52a1580e39 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMapTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMapTest.java @@ -35,18 +35,8 @@ public void before() { singleObserver = TestHelper.mockSingleObserver(); } - Function lengthFunc = new Function() { - @Override - public Integer apply(String t1) { - return t1.length(); - } - }; - Function duplicate = new Function() { - @Override - public String apply(String t1) { - return t1 + t1; - } - }; + Function lengthFunc = t1 -> t1.length(); + Function duplicate = t1 -> t1 + t1; @Test public void toMapFlowable() { @@ -90,14 +80,11 @@ public void toMapWithValueSelectorFlowable() { public void toMapWithErrorFlowable() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Function lengthFuncErr = new Function() { - @Override - public Integer apply(String t1) { - if ("bb".equals(t1)) { - throw new RuntimeException("Forced Failure"); - } - return t1.length(); + Function lengthFuncErr = t1 -> { + if ("bb".equals(t1)) { + throw new RuntimeException("Forced Failure"); } + return t1.length(); }; Flowable> mapped = source.toMap(lengthFuncErr).toFlowable(); @@ -119,14 +106,11 @@ public Integer apply(String t1) { public void toMapWithErrorInValueSelectorFlowable() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Function duplicateErr = new Function() { - @Override - public String apply(String t1) { - if ("bb".equals(t1)) { - throw new RuntimeException("Forced failure"); - } - return t1 + t1; + Function duplicateErr = t1 -> { + if ("bb".equals(t1)) { + throw new RuntimeException("Forced failure"); } + return t1 + t1; }; Flowable> mapped = source.toMap(lengthFunc, duplicateErr).toFlowable(); @@ -149,33 +133,18 @@ public String apply(String t1) { public void toMapWithFactoryFlowable() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Supplier> mapFactory = new Supplier>() { - @Override - public Map get() { - return new LinkedHashMap() { - - private static final long serialVersionUID = -3296811238780863394L; + Supplier> mapFactory = () -> new LinkedHashMap() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 3; - } - }; - } - }; + private static final long serialVersionUID = -3296811238780863394L; - Function lengthFunc = new Function() { @Override - public Integer apply(String t1) { - return t1.length(); + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 3; } }; - Flowable> mapped = source.toMap(lengthFunc, new Function() { - @Override - public String apply(String v) { - return v; - } - }, mapFactory).toFlowable(); + + Function lengthFunc = t1 -> t1.length(); + Flowable> mapped = source.toMap(lengthFunc, v -> v, mapFactory).toFlowable(); Map expected = new LinkedHashMap<>(); expected.put(2, "bb"); @@ -193,25 +162,12 @@ public String apply(String v) { public void toMapWithErrorThrowingFactoryFlowable() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Supplier> mapFactory = new Supplier>() { - @Override - public Map get() { - throw new RuntimeException("Forced failure"); - } + Supplier> mapFactory = () -> { + throw new RuntimeException("Forced failure"); }; - Function lengthFunc = new Function() { - @Override - public Integer apply(String t1) { - return t1.length(); - } - }; - Flowable> mapped = source.toMap(lengthFunc, new Function() { - @Override - public String apply(String v) { - return v; - } - }, mapFactory).toFlowable(); + Function lengthFunc = t1 -> t1.length(); + Flowable> mapped = source.toMap(lengthFunc, v -> v, mapFactory).toFlowable(); Map expected = new LinkedHashMap<>(); expected.put(2, "bb"); @@ -265,14 +221,11 @@ public void toMapWithValueSelector() { public void toMapWithError() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Function lengthFuncErr = new Function() { - @Override - public Integer apply(String t1) { - if ("bb".equals(t1)) { - throw new RuntimeException("Forced Failure"); - } - return t1.length(); + Function lengthFuncErr = t1 -> { + if ("bb".equals(t1)) { + throw new RuntimeException("Forced Failure"); } + return t1.length(); }; Single> mapped = source.toMap(lengthFuncErr); @@ -293,14 +246,11 @@ public Integer apply(String t1) { public void toMapWithErrorInValueSelector() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Function duplicateErr = new Function() { - @Override - public String apply(String t1) { - if ("bb".equals(t1)) { - throw new RuntimeException("Forced failure"); - } - return t1 + t1; + Function duplicateErr = t1 -> { + if ("bb".equals(t1)) { + throw new RuntimeException("Forced failure"); } + return t1 + t1; }; Single> mapped = source.toMap(lengthFunc, duplicateErr); @@ -322,33 +272,18 @@ public String apply(String t1) { public void toMapWithFactory() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Supplier> mapFactory = new Supplier>() { - @Override - public Map get() { - return new LinkedHashMap() { + Supplier> mapFactory = () -> new LinkedHashMap() { - private static final long serialVersionUID = -3296811238780863394L; + private static final long serialVersionUID = -3296811238780863394L; - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 3; - } - }; - } - }; - - Function lengthFunc = new Function() { @Override - public Integer apply(String t1) { - return t1.length(); + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 3; } }; - Single> mapped = source.toMap(lengthFunc, new Function() { - @Override - public String apply(String v) { - return v; - } - }, mapFactory); + + Function lengthFunc = t1 -> t1.length(); + Single> mapped = source.toMap(lengthFunc, v -> v, mapFactory); Map expected = new LinkedHashMap<>(); expected.put(2, "bb"); @@ -365,25 +300,12 @@ public String apply(String v) { public void toMapWithErrorThrowingFactory() { Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Supplier> mapFactory = new Supplier>() { - @Override - public Map get() { - throw new RuntimeException("Forced failure"); - } + Supplier> mapFactory = () -> { + throw new RuntimeException("Forced failure"); }; - Function lengthFunc = new Function() { - @Override - public Integer apply(String t1) { - return t1.length(); - } - }; - Single> mapped = source.toMap(lengthFunc, new Function() { - @Override - public String apply(String v) { - return v; - } - }, mapFactory); + Function lengthFunc = t1 -> t1.length(); + Single> mapped = source.toMap(lengthFunc, v -> v, mapFactory); Map expected = new LinkedHashMap<>(); expected.put(2, "bb"); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMultimapTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMultimapTest.java index 6cbdf235e5..b20db2fb94 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMultimapTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToMultimapTest.java @@ -36,18 +36,8 @@ public void before() { singleObserver = TestHelper.mockSingleObserver(); } - Function lengthFunc = new Function() { - @Override - public Integer apply(String t1) { - return t1.length(); - } - }; - Function duplicate = new Function() { - @Override - public String apply(String t1) { - return t1 + t1; - } - }; + Function lengthFunc = t1 -> t1.length(); + Function duplicate = t1 -> t1 + t1; @Test public void toMultimapFlowable() { @@ -87,36 +77,21 @@ public void toMultimapWithValueSelectorFlowable() { public void toMultimapWithMapFactoryFlowable() { Flowable source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); - Supplier>> mapFactory = new Supplier>>() { - @Override - public Map> get() { - return new LinkedHashMap>() { - - private static final long serialVersionUID = -2084477070717362859L; + Supplier>> mapFactory = () -> new LinkedHashMap>() { - @Override - protected boolean removeEldestEntry(Map.Entry> eldest) { - return size() > 2; - } - }; - } - }; + private static final long serialVersionUID = -2084477070717362859L; - Function identity = new Function() { @Override - public String apply(String v) { - return v; + protected boolean removeEldestEntry(Map.Entry> eldest) { + return size() > 2; } }; + Function identity = v -> v; + Flowable>> mapped = source.toMultimap( lengthFunc, identity, - mapFactory, new Function>() { - @Override - public Collection apply(Integer e) { - return new ArrayList<>(); - } - }).toFlowable(); + mapFactory, (Function>) _ -> new ArrayList<>()).toFlowable(); Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); @@ -133,36 +108,23 @@ public Collection apply(Integer e) { public void toMultimapWithCollectionFactoryFlowable() { Flowable source = Flowable.just("cc", "dd", "eee", "eee"); - Function> collectionFactory = new Function>() { - @Override - public Collection apply(Integer t1) { - if (t1 == 2) { - return new ArrayList<>(); - } else { - return new HashSet<>(); - } + Function> collectionFactory = t1 -> { + if (t1 == 2) { + return new ArrayList<>(); + } else { + return new HashSet<>(); } }; - Function identity = new Function() { - @Override - public String apply(String v) { - return v; - } - }; - Supplier>> mapSupplier = new Supplier>>() { - @Override - public Map> get() { - return new HashMap<>(); - } - }; + Function identity = v -> v; + Supplier>> mapSupplier = () -> new HashMap<>(); Flowable>> mapped = source .toMultimap(lengthFunc, identity, mapSupplier, collectionFactory).toFlowable(); Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); - expected.put(3, new HashSet<>(Arrays.asList("eee"))); + expected.put(3, new HashSet<>(List.of("eee"))); mapped.subscribe(objectSubscriber); @@ -175,14 +137,11 @@ public Map> get() { public void toMultimapWithErrorFlowable() { Flowable source = Flowable.just("a", "b", "cc", "dd"); - Function lengthFuncErr = new Function() { - @Override - public Integer apply(String t1) { - if ("b".equals(t1)) { - throw new RuntimeException("Forced Failure"); - } - return t1.length(); + Function lengthFuncErr = t1 -> { + if ("b".equals(t1)) { + throw new RuntimeException("Forced Failure"); } + return t1.length(); }; Flowable>> mapped = source.toMultimap(lengthFuncErr).toFlowable(); @@ -202,14 +161,11 @@ public Integer apply(String t1) { public void toMultimapWithErrorInValueSelectorFlowable() { Flowable source = Flowable.just("a", "b", "cc", "dd"); - Function duplicateErr = new Function() { - @Override - public String apply(String t1) { - if ("b".equals(t1)) { - throw new RuntimeException("Forced failure"); - } - return t1 + t1; + Function duplicateErr = t1 -> { + if ("b".equals(t1)) { + throw new RuntimeException("Forced failure"); } + return t1 + t1; }; Flowable>> mapped = source.toMultimap(lengthFunc, duplicateErr).toFlowable(); @@ -229,20 +185,12 @@ public String apply(String t1) { public void toMultimapWithMapThrowingFactoryFlowable() { Flowable source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); - Supplier>> mapFactory = new Supplier>>() { - @Override - public Map> get() { - throw new RuntimeException("Forced failure"); - } + Supplier>> mapFactory = () -> { + throw new RuntimeException("Forced failure"); }; Flowable>> mapped = source - .toMultimap(lengthFunc, new Function() { - @Override - public String apply(String v) { - return v; - } - }, mapFactory).toFlowable(); + .toMultimap(lengthFunc, v -> v, mapFactory).toFlowable(); Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); @@ -259,29 +207,16 @@ public String apply(String v) { public void toMultimapWithThrowingCollectionFactoryFlowable() { Flowable source = Flowable.just("cc", "cc", "eee", "eee"); - Function> collectionFactory = new Function>() { - @Override - public Collection apply(Integer t1) { - if (t1 == 2) { - throw new RuntimeException("Forced failure"); - } else { - return new HashSet<>(); - } + Function> collectionFactory = t1 -> { + if (t1 == 2) { + throw new RuntimeException("Forced failure"); + } else { + return new HashSet<>(); } }; - Function identity = new Function() { - @Override - public String apply(String v) { - return v; - } - }; - Supplier>> mapSupplier = new Supplier>>() { - @Override - public Map> get() { - return new HashMap<>(); - } - }; + Function identity = v -> v; + Supplier>> mapSupplier = () -> new HashMap<>(); Flowable>> mapped = source.toMultimap(lengthFunc, identity, mapSupplier, collectionFactory).toFlowable(); @@ -333,36 +268,21 @@ public void toMultimapWithValueSelector() { public void toMultimapWithMapFactory() { Flowable source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); - Supplier>> mapFactory = new Supplier>>() { - @Override - public Map> get() { - return new LinkedHashMap>() { - - private static final long serialVersionUID = -2084477070717362859L; + Supplier>> mapFactory = () -> new LinkedHashMap>() { - @Override - protected boolean removeEldestEntry(Map.Entry> eldest) { - return size() > 2; - } - }; - } - }; + private static final long serialVersionUID = -2084477070717362859L; - Function identity = new Function() { @Override - public String apply(String v) { - return v; + protected boolean removeEldestEntry(Map.Entry> eldest) { + return size() > 2; } }; + Function identity = v -> v; + Single>> mapped = source.toMultimap( lengthFunc, identity, - mapFactory, new Function>() { - @Override - public Collection apply(Integer e) { - return new ArrayList<>(); - } - }); + mapFactory, (Function>) _ -> new ArrayList<>()); Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); @@ -378,36 +298,23 @@ public Collection apply(Integer e) { public void toMultimapWithCollectionFactory() { Flowable source = Flowable.just("cc", "dd", "eee", "eee"); - Function> collectionFactory = new Function>() { - @Override - public Collection apply(Integer t1) { - if (t1 == 2) { - return new ArrayList<>(); - } else { - return new HashSet<>(); - } + Function> collectionFactory = t1 -> { + if (t1 == 2) { + return new ArrayList<>(); + } else { + return new HashSet<>(); } }; - Function identity = new Function() { - @Override - public String apply(String v) { - return v; - } - }; - Supplier>> mapSupplier = new Supplier>>() { - @Override - public Map> get() { - return new HashMap<>(); - } - }; + Function identity = v -> v; + Supplier>> mapSupplier = () -> new HashMap<>(); Single>> mapped = source .toMultimap(lengthFunc, identity, mapSupplier, collectionFactory); Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); - expected.put(3, new HashSet<>(Arrays.asList("eee"))); + expected.put(3, new HashSet<>(List.of("eee"))); mapped.subscribe(singleObserver); @@ -419,14 +326,11 @@ public Map> get() { public void toMultimapWithError() { Flowable source = Flowable.just("a", "b", "cc", "dd"); - Function lengthFuncErr = new Function() { - @Override - public Integer apply(String t1) { - if ("b".equals(t1)) { - throw new RuntimeException("Forced Failure"); - } - return t1.length(); + Function lengthFuncErr = t1 -> { + if ("b".equals(t1)) { + throw new RuntimeException("Forced Failure"); } + return t1.length(); }; Single>> mapped = source.toMultimap(lengthFuncErr); @@ -445,14 +349,11 @@ public Integer apply(String t1) { public void toMultimapWithErrorInValueSelector() { Flowable source = Flowable.just("a", "b", "cc", "dd"); - Function duplicateErr = new Function() { - @Override - public String apply(String t1) { - if ("b".equals(t1)) { - throw new RuntimeException("Forced failure"); - } - return t1 + t1; + Function duplicateErr = t1 -> { + if ("b".equals(t1)) { + throw new RuntimeException("Forced failure"); } + return t1 + t1; }; Single>> mapped = source.toMultimap(lengthFunc, duplicateErr); @@ -471,20 +372,12 @@ public String apply(String t1) { public void toMultimapWithMapThrowingFactory() { Flowable source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); - Supplier>> mapFactory = new Supplier>>() { - @Override - public Map> get() { - throw new RuntimeException("Forced failure"); - } + Supplier>> mapFactory = () -> { + throw new RuntimeException("Forced failure"); }; Single>> mapped = source - .toMultimap(lengthFunc, new Function() { - @Override - public String apply(String v) { - return v; - } - }, mapFactory); + .toMultimap(lengthFunc, v -> v, mapFactory); Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); @@ -500,29 +393,16 @@ public String apply(String v) { public void toMultimapWithThrowingCollectionFactory() { Flowable source = Flowable.just("cc", "cc", "eee", "eee"); - Function> collectionFactory = new Function>() { - @Override - public Collection apply(Integer t1) { - if (t1 == 2) { - throw new RuntimeException("Forced failure"); - } else { - return new HashSet<>(); - } + Function> collectionFactory = t1 -> { + if (t1 == 2) { + throw new RuntimeException("Forced failure"); + } else { + return new HashSet<>(); } }; - Function identity = new Function() { - @Override - public String apply(String v) { - return v; - } - }; - Supplier>> mapSupplier = new Supplier>>() { - @Override - public Map> get() { - return new HashMap<>(); - } - }; + Function identity = v -> v; + Supplier>> mapSupplier = HashMap::new; Single>> mapped = source.toMultimap(lengthFunc, identity, mapSupplier, collectionFactory); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToSortedListTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToSortedListTest.java index 4e05efb097..c7427d53e7 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToSortedListTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableToSortedListTest.java @@ -46,14 +46,7 @@ public void sortedListFlowable() { @Test public void sortedListWithCustomFunctionFlowable() { Flowable w = Flowable.just(1, 3, 2, 5, 4); - Flowable> flowable = w.toSortedList(new Comparator() { - - @Override - public int compare(Integer t1, Integer t2) { - return t2 - t1; - } - - }).toFlowable(); + Flowable> flowable = w.toSortedList((t1, t2) -> t2 - t1).toFlowable(); Subscriber> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); @@ -102,12 +95,7 @@ public void sorted() { @Test public void sortedComparator() { - Flowable.just(5, 1, 2, 4, 3).sorted(new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return b - a; - } - }) + Flowable.just(5, 1, 2, 4, 3).sorted((a, b) -> b - a) .test() .assertResult(5, 4, 3, 2, 1); } @@ -121,12 +109,7 @@ public void toSortedListCapacityFlowable() { @Test public void toSortedListComparatorCapacityFlowable() { - Flowable.just(5, 1, 2, 4, 3).toSortedList(new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return b - a; - } - }, 4).toFlowable() + Flowable.just(5, 1, 2, 4, 3).toSortedList((a, b) -> b - a, 4).toFlowable() .test() .assertResult(Arrays.asList(5, 4, 3, 2, 1)); } @@ -145,14 +128,7 @@ public void sortedList() { @Test public void sortedListWithCustomFunction() { Flowable w = Flowable.just(1, 3, 2, 5, 4); - Single> single = w.toSortedList(new Comparator() { - - @Override - public int compare(Integer t1, Integer t2) { - return t2 - t1; - } - - }); + Single> single = w.toSortedList((t1, t2) -> t2 - t1); SingleObserver> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); @@ -185,12 +161,7 @@ public void toSortedListCapacity() { @Test public void toSortedListComparatorCapacity() { - Flowable.just(5, 1, 2, 4, 3).toSortedList(new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return b - a; - } - }, 4) + Flowable.just(5, 1, 2, 4, 3).toSortedList((a, b) -> b - a, 4) .test() .assertResult(Arrays.asList(5, 4, 3, 2, 1)); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUnsubscribeOnTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUnsubscribeOnTest.java index d7688fe505..ad5d1ff083 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUnsubscribeOnTest.java @@ -25,7 +25,6 @@ import io.reactivex.rxjava4.annotations.NonNull; import io.reactivex.rxjava4.core.*; import io.reactivex.rxjava4.exceptions.TestException; -import io.reactivex.rxjava4.functions.Action; import io.reactivex.rxjava4.internal.schedulers.ImmediateThinScheduler; import io.reactivex.rxjava4.internal.subscriptions.BooleanSubscription; import io.reactivex.rxjava4.plugins.RxJavaPlugins; @@ -40,19 +39,15 @@ public void unsubscribeWhenSubscribeOnAndUnsubscribeOnAreOnSameThread() throws I try { final ThreadSubscription subscription = new ThreadSubscription(); final AtomicReference subscribeThread = new AtomicReference<>(); - Flowable w = Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(Subscriber t1) { - subscribeThread.set(Thread.currentThread()); - t1.onSubscribe(subscription); - t1.onNext(1); - t1.onNext(2); - // observeOn will prevent canceling the upstream upon its termination now - // this call is racing for that state in this test - // not doing it will make sure the unsubscribeOn always gets through - // t1.onComplete(); - } + Flowable w = Flowable.unsafeCreate(t1 -> { + subscribeThread.set(Thread.currentThread()); + t1.onSubscribe(subscription); + t1.onNext(1); + t1.onNext(2); + // observeOn will prevent canceling the upstream upon its termination now + // this call is racing for that state in this test + // not doing it will make sure the unsubscribeOn always gets through + // t1.onComplete(); }); TestSubscriberEx ts = new TestSubscriberEx<>(); @@ -89,19 +84,15 @@ public void unsubscribeWhenSubscribeOnAndUnsubscribeOnAreOnDifferentThreads() th try { final ThreadSubscription subscription = new ThreadSubscription(); final AtomicReference subscribeThread = new AtomicReference<>(); - Flowable w = Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(Subscriber t1) { - subscribeThread.set(Thread.currentThread()); - t1.onSubscribe(subscription); - t1.onNext(1); - t1.onNext(2); - // observeOn will prevent canceling the upstream upon its termination now - // this call is racing for that state in this test - // not doing it will make sure the unsubscribeOn always gets through - // t1.onComplete(); - } + Flowable w = Flowable.unsafeCreate(t1 -> { + subscribeThread.set(Thread.currentThread()); + t1.onSubscribe(subscription); + t1.onNext(1); + t1.onNext(2); + // observeOn will prevent canceling the upstream upon its termination now + // this call is racing for that state in this test + // not doing it will make sure the unsubscribeOn always gets through + // t1.onComplete(); }); TestSubscriberEx ts = new TestSubscriberEx<>(); @@ -169,14 +160,9 @@ public UIEventLoopScheduler() { * DON'T DO THIS IN PRODUCTION CODE */ final CountDownLatch latch = new CountDownLatch(1); - eventLoop.scheduleDirect(new Runnable() { - - @Override - public void run() { - t = Thread.currentThread(); - latch.countDown(); - } - + eventLoop.scheduleDirect(() -> { + t = Thread.currentThread(); + latch.countDown(); }); try { latch.await(); @@ -220,12 +206,7 @@ public void normal() { final int[] calls = { 0 }; Flowable.just(1) - .doOnCancel(new Action() { - @Override - public void run() throws Exception { - calls[0]++; - } - }) + .doOnCancel(() -> calls[0]++) .unsubscribeOn(Schedulers.single()) .test() .assertResult(1); @@ -238,12 +219,7 @@ public void error() { final int[] calls = { 0 }; Flowable.error(new TestException()) - .doOnCancel(new Action() { - @Override - public void run() throws Exception { - calls[0]++; - } - }) + .doOnCancel(() -> calls[0]++) .unsubscribeOn(Schedulers.single()) .test() .assertFailure(TestException.class); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUsingTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUsingTest.java index 134854e10f..c4f6e38bcd 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUsingTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableUsingTest.java @@ -50,14 +50,7 @@ public void accept(Resource r) { } - private final Consumer disposeSubscription = new Consumer() { - - @Override - public void accept(Disposable d) { - d.dispose(); - } - - }; + private final Consumer disposeSubscription = d -> d.dispose(); @Test public void using() { @@ -73,19 +66,9 @@ private void performTestUsing(boolean disposeEagerly) { final Resource resource = mock(Resource.class); when(resource.getTextFromWeb()).thenReturn("Hello world!"); - Supplier resourceFactory = new Supplier() { - @Override - public Resource get() { - return resource; - } - }; + Supplier resourceFactory = () -> resource; - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Resource res) { - return Flowable.fromArray(res.getTextFromWeb().split(" ")); - } - }; + Function> observableFactory = res -> Flowable.fromArray(res.getTextFromWeb().split(" ")); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -115,38 +98,28 @@ public void usingWithSubscribingTwiceDisposeEagerly() { private void performTestUsingWithSubscribingTwice(boolean disposeEagerly) { // When subscribe is called, a new resource should be created. - Supplier resourceFactory = new Supplier() { + Supplier resourceFactory = () -> new Resource() { + + boolean first = true; + @Override - public Resource get() { - return new Resource() { - - boolean first = true; - - @Override - public String getTextFromWeb() { - if (first) { - first = false; - return "Hello world!"; - } - return "Nothing"; - } - - @Override - public void dispose() { - // do nothing - } - - }; + public String getTextFromWeb() { + if (first) { + first = false; + return "Hello world!"; + } + return "Nothing"; } - }; - Function> observableFactory = new Function>() { @Override - public Flowable apply(Resource res) { - return Flowable.fromArray(res.getTextFromWeb().split(" ")); + public void dispose() { + // do nothing } + }; + Function> observableFactory = res -> Flowable.fromArray(res.getTextFromWeb().split(" ")); + Subscriber subscriber = TestHelper.mockSubscriber(); Flowable flowable = Flowable.using(resourceFactory, observableFactory, @@ -177,19 +150,11 @@ public void usingWithResourceFactoryErrorDisposeEagerly() { } private void performTestUsingWithResourceFactoryError(boolean disposeEagerly) { - Supplier resourceFactory = new Supplier() { - @Override - public Disposable get() { - throw new TestException(); - } + Supplier resourceFactory = () -> { + throw new TestException(); }; - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Disposable d) { - return Flowable.empty(); - } - }; + Function> observableFactory = _ -> Flowable.empty(); Flowable.using(resourceFactory, observableFactory, disposeSubscription) .blockingLast(); @@ -207,18 +172,10 @@ public void usingWithFlowableFactoryErrorDisposeEagerly() { private void performTestUsingWithFlowableFactoryError(boolean disposeEagerly) { final Runnable unsubscribe = mock(Runnable.class); - Supplier resourceFactory = new Supplier() { - @Override - public Disposable get() { - return Disposable.fromRunnable(unsubscribe); - } - }; + Supplier resourceFactory = () -> Disposable.fromRunnable(unsubscribe); - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Disposable subscription) { - throw new TestException(); - } + Function> observableFactory = _ -> { + throw new TestException(); }; try { @@ -238,12 +195,7 @@ public void usingDisposesEagerlyBeforeCompletion() { final Action completion = createOnCompletedAction(events); final Action unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Resource resource) { - return Flowable.fromArray(resource.getTextFromWeb().split(" ")); - } - }; + Function> observableFactory = resource -> Flowable.fromArray(resource.getTextFromWeb().split(" ")); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -265,12 +217,7 @@ public void usingDoesNotDisposesEagerlyBeforeCompletion() { final Action completion = createOnCompletedAction(events); final Action unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Resource resource) { - return Flowable.fromArray(resource.getTextFromWeb().split(" ")); - } - }; + Function> observableFactory = resource -> Flowable.fromArray(resource.getTextFromWeb().split(" ")); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -292,13 +239,8 @@ public void usingDisposesEagerlyBeforeError() { final Consumer onError = createOnErrorAction(events); final Action unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Resource resource) { - return Flowable.fromArray(resource.getTextFromWeb().split(" ")) - .concatWith(Flowable.error(new RuntimeException())); - } - }; + Function> observableFactory = resource -> Flowable.fromArray(resource.getTextFromWeb().split(" ")) + .concatWith(Flowable.error(new RuntimeException())); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -320,13 +262,8 @@ public void usingDoesNotDisposesEagerlyBeforeError() { final Consumer onError = createOnErrorAction(events); final Action unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { - @Override - public Flowable apply(Resource resource) { - return Flowable.fromArray(resource.getTextFromWeb().split(" ")) - .concatWith(Flowable.error(new RuntimeException())); - } - }; + Function> observableFactory = resource -> Flowable.fromArray(resource.getTextFromWeb().split(" ")) + .concatWith(Flowable.error(new RuntimeException())); Subscriber subscriber = TestHelper.mockSubscriber(); @@ -341,52 +278,32 @@ public Flowable apply(Resource resource) { } private static Action createUnsubAction(final List events) { - return new Action() { - @Override - public void run() { - events.add("unsub"); - } - }; + return () -> events.add("unsub"); } private static Consumer createOnErrorAction(final List events) { - return new Consumer() { - @Override - public void accept(Throwable t) { - events.add("error"); - } - }; + return _ -> events.add("error"); } private static Supplier createResourceFactory(final List events) { - return new Supplier() { + return () -> new Resource() { + @Override - public Resource get() { - return new Resource() { - - @Override - public String getTextFromWeb() { - return "hello world"; - } - - @Override - public void dispose() { - events.add("disposed"); - } - }; + public String getTextFromWeb() { + return "hello world"; } - }; - } - private static Action createOnCompletedAction(final List events) { - return new Action() { @Override - public void run() { - events.add("completed"); + public void dispose() { + events.add("disposed"); } }; } + private static Action createOnCompletedAction(final List events) { + return () -> events.add("completed"); + } + @Test public void factoryThrows() { @@ -395,25 +312,12 @@ public void factoryThrows() { final AtomicInteger count = new AtomicInteger(); Flowable.using( - new Supplier() { - @Override - public Integer get() { - return 1; - } - }, - new Function>() { - @Override - public Flowable apply(Integer v) { - throw new TestException("forced failure"); - } - }, - new Consumer() { - @Override - public void accept(Integer c) { - count.incrementAndGet(); - } - } - ) + () -> 1, + (Function>) _ -> { + throw new TestException("forced failure"); + }, + _ -> count.incrementAndGet() + ) .subscribe(ts); ts.assertError(TestException.class); @@ -429,24 +333,9 @@ public void nonEagerTermination() { final AtomicInteger count = new AtomicInteger(); Flowable.using( - new Supplier() { - @Override - public Integer get() { - return 1; - } - }, - new Function>() { - @Override - public Flowable apply(Integer v) { - return Flowable.just(v); - } - }, - new Consumer() { - @Override - public void accept(Integer c) { - count.incrementAndGet(); - } - }, false + () -> 1, + (Function>) v -> Flowable.just(v), + _ -> count.incrementAndGet(), false ) .subscribe(ts); @@ -460,39 +349,19 @@ public void accept(Integer c) { @Test public void dispose() { TestHelper.checkDisposed(Flowable.using( - new Supplier() { - @Override - public Object get() throws Exception { - return 1; - } - }, - new Function>() { - @Override - public Flowable apply(Object v) throws Exception { - return Flowable.never(); - } - }, + (Supplier) () -> 1, + (Function>) _ -> Flowable.never(), Functions.emptyConsumer() )); } @Test public void supplierDisposerCrash() { - TestSubscriberEx ts = Flowable.using(new Supplier() { - @Override - public Object get() throws Exception { - return 1; - } - }, new Function>() { - @Override - public Flowable apply(Object v) throws Exception { - throw new TestException("First"); - } - }, new Consumer() { - @Override - public void accept(Object e) throws Exception { - throw new TestException("Second"); - } + TestSubscriberEx ts = Flowable.using((Supplier) () -> 1, + (Function>) _ -> { + throw new TestException("First"); + }, _ -> { + throw new TestException("Second"); }) .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); @@ -505,22 +374,11 @@ public void accept(Object e) throws Exception { @Test public void eagerOnErrorDisposerCrash() { - TestSubscriberEx ts = Flowable.using(new Supplier() { - @Override - public Object get() throws Exception { - return 1; - } - }, new Function>() { - @Override - public Flowable apply(Object v) throws Exception { - return Flowable.error(new TestException("First")); - } - }, new Consumer() { - @Override - public void accept(Object e) throws Exception { - throw new TestException("Second"); - } - }) + TestSubscriberEx ts = Flowable.using((Supplier) () -> 1, + (Function>) _ -> Flowable.error(new TestException("First")), + _ -> { + throw new TestException("Second"); + }) .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); @@ -532,22 +390,11 @@ public void accept(Object e) throws Exception { @Test public void eagerOnCompleteDisposerCrash() { - Flowable.using(new Supplier() { - @Override - public Object get() throws Exception { - return 1; - } - }, new Function>() { - @Override - public Flowable apply(Object v) throws Exception { - return Flowable.empty(); - } - }, new Consumer() { - @Override - public void accept(Object e) throws Exception { - throw new TestException("Second"); - } - }) + Flowable.using((Supplier) () -> 1, + (Function>) _ -> Flowable.empty(), + _ -> { + throw new TestException("Second"); + }) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Second"); } @@ -556,22 +403,11 @@ public void accept(Object e) throws Exception { public void nonEagerDisposerCrash() { List errors = TestHelper.trackPluginErrors(); try { - Flowable.using(new Supplier() { - @Override - public Object get() throws Exception { - return 1; - } - }, new Function>() { - @Override - public Flowable apply(Object v) throws Exception { - return Flowable.empty(); - } - }, new Consumer() { - @Override - public void accept(Object e) throws Exception { - throw new TestException("Second"); - } - }, false) + Flowable.using((Supplier) () -> 1, + (Function>) _ -> Flowable.empty(), + _ -> { + throw new TestException("Second"); + }, false) .test() .assertResult(); @@ -593,13 +429,8 @@ public void sourceSupplierReturnsNull() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { - @Override - public Flowable apply(Flowable f) - throws Exception { - return Flowable.using(Functions.justSupplier(1), Functions.justFunction(f), Functions.emptyConsumer()); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>) f -> + Flowable.using(Functions.justSupplier(1), Functions.justFunction(f), Functions.emptyConsumer())); } @Test @@ -637,24 +468,8 @@ public void eagerDisposeResourceThenDisposeUpstream() { final StringBuilder sb = new StringBuilder(); Flowable.using(Functions.justSupplier(1), - new Function>() { - @Override - public Flowable apply(Integer t) throws Throwable { - return Flowable.range(1, 2) - .doOnCancel(new Action() { - @Override - public void run() throws Throwable { - sb.append("Cancel"); - } - }) - ; - } - }, new Consumer() { - @Override - public void accept(Integer t) throws Throwable { - sb.append("Resource"); - } - }, true) + (Function>) _ -> Flowable.range(1, 2) + .doOnCancel(() -> sb.append("Cancel")), _ -> sb.append("Resource"), true) .take(1) .test() .assertResult(1); @@ -667,23 +482,8 @@ public void nonEagerDisposeUpstreamThenDisposeResource() { final StringBuilder sb = new StringBuilder(); Flowable.using(Functions.justSupplier(1), - new Function>() { - @Override - public Flowable apply(Integer t) throws Throwable { - return Flowable.range(1, 2) - .doOnCancel(new Action() { - @Override - public void run() throws Throwable { - sb.append("Cancel"); - } - }); - } - }, new Consumer() { - @Override - public void accept(Integer t) throws Throwable { - sb.append("Resource"); - } - }, false) + (Function>) _ -> Flowable.range(1, 2) + .doOnCancel(() -> sb.append("Cancel")), _ -> sb.append("Resource"), false) .take(1) .test() .assertResult(1); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithFlowableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithFlowableTest.java index 547e458ad8..028c180cad 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithFlowableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithFlowableTest.java @@ -270,17 +270,9 @@ public void boundaryOnError() { @Test public void innerBadSource() { - TestHelper.checkBadSourceFlowable(new Function, Object>() { - @Override - public Object apply(Flowable f) throws Exception { - return Flowable.just(1).window(f).flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }); - } - }, false, 1, 1, (Object[])null); + TestHelper.checkBadSourceFlowable(f -> Flowable.just(1).window(f) + .flatMap((Function, Flowable>) v -> v), + false, 1, 1, (Object[])null); } @Test @@ -299,12 +291,7 @@ public void onNext(Integer t) { }; ps.window(BehaviorProcessor.createDefault(1)) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }) + .flatMap((Function, Flowable>) v -> v) .subscribe(ts); ps.onNext(1); @@ -316,17 +303,9 @@ public Flowable apply(Flowable v) throws Exception { @Test public void badSource() { - TestHelper.checkBadSourceFlowable(new Function, Object>() { - @Override - public Object apply(Flowable f) throws Exception { - return f.window(Flowable.never()).flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }); - } - }, false, 1, 1, 1); + TestHelper.checkBadSourceFlowable((Function, Object>) f -> + f.window(Flowable.never()).flatMap((Function, Flowable>) v -> v), + false, 1, 1, 1); } @Test @@ -370,13 +349,7 @@ public void boundaryDirectSecondMissingBackpressure() { @Test public void boundaryDirectDoubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>>() { - @Override - public Publisher> apply(Flowable f) - throws Exception { - return f.window(Flowable.never()).takeLast(1); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable(f -> f.window(Flowable.never()).takeLast(1)); } @Test @@ -386,13 +359,7 @@ public void upstreamDisposedWhenOutputsDisposed() { TestSubscriber ts = source.window(boundary) .take(1) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply( - Flowable w) throws Exception { - return w.take(1); - } - }) + .flatMap((Function, Flowable>) w -> w.take(1)) .test(); source.onNext(1); @@ -417,11 +384,8 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } }) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment - } + .doOnNext(w -> { + w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment }) .to(TestHelper.>testConsumer()); @@ -465,18 +429,8 @@ protected void subscribeActual(Subscriber subscriber) { }) .to(TestHelper.>testConsumer()); - Runnable r1 = new Runnable() { - @Override - public void run() { - refMain.get().onComplete(); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - ref.get().onError(ex); - } - }; + Runnable r1 = () -> refMain.get().onComplete(); + Runnable r2 = () -> ref.get().onError(ex); TestHelper.race(r1, r2); @@ -515,18 +469,8 @@ protected void subscribeActual(Subscriber subscriber) { }) .test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - refMain.get().onNext(1); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - ref.get().onNext(1); - } - }; + Runnable r1 = () -> refMain.get().onNext(1); + Runnable r2 = () -> ref.get().onNext(1); TestHelper.race(r1, r2); @@ -604,19 +548,11 @@ public void request(long n) { }) .test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - Subscriber subscriber = ref.get(); - subscriber.onNext(1); - subscriber.onComplete(); - } + Runnable r1 = () -> ts.cancel(); + Runnable r2 = () -> { + Subscriber subscriber = ref.get(); + subscriber.onNext(1); + subscriber.onComplete(); }; TestHelper.race(r1, r2); @@ -662,19 +598,11 @@ public void request(long n) { }) .test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; - Runnable r2 = new Runnable() { - @Override - public void run() { - Subscriber subscriber = ref.get(); - subscriber.onNext(1); - subscriber.onError(ex); - } + Runnable r1 = () -> ts.cancel(); + Runnable r2 = () -> { + Subscriber subscriber = ref.get(); + subscriber.onNext(1); + subscriber.onError(ex); }; TestHelper.race(r1, r2); @@ -687,12 +615,7 @@ public void cancellingWindowCancelsUpstream() { TestSubscriber ts = pp.window(Flowable.just(1).concatWith(Flowable.never())) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -712,12 +635,7 @@ public void windowAbandonmentCancelsUpstream() { final AtomicReference> inner = new AtomicReference<>(); TestSubscriber> ts = pp.window(Flowable.never()) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(inner::set) .test(); assertTrue(pp.hasSubscribers()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithSizeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithSizeTest.java index 50e21e6823..e47f0a82c3 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithSizeTest.java @@ -38,12 +38,7 @@ public class FlowableWindowWithSizeTest extends RxJavaTest { private static List> toLists(Flowable> observables) { - return observables.flatMapSingle(new Function, SingleSource>>() { - @Override - public SingleSource> apply(Flowable w) throws Throwable { - return w.toList(); - } - }).toList().blockingGet(); + return observables.flatMapSingle((Function, SingleSource>>) w -> w.toList()).toList().blockingGet(); } @Test @@ -103,14 +98,7 @@ public void windowUnsubscribeNonOverlapping() { TestSubscriberEx ts = new TestSubscriberEx<>(); final AtomicInteger count = new AtomicInteger(); - Flowable.merge(Flowable.range(1, 10000).doOnNext(new Consumer() { - - @Override - public void accept(Integer t1) { - count.incrementAndGet(); - } - - }).window(5).take(2)) + Flowable.merge(Flowable.range(1, 10000).doOnNext(_ -> count.incrementAndGet()).window(5).take(2)) .subscribe(ts); ts.awaitDone(500, TimeUnit.MILLISECONDS); @@ -125,14 +113,7 @@ public void windowUnsubscribeNonOverlappingAsyncSource() { TestSubscriberEx ts = new TestSubscriberEx<>(); final AtomicInteger count = new AtomicInteger(); Flowable.merge(Flowable.range(1, 100000) - .doOnNext(new Consumer() { - - @Override - public void accept(Integer t1) { - count.incrementAndGet(); - } - - }) + .doOnNext(_ -> count.incrementAndGet()) .observeOn(Schedulers.computation()) .window(5) .take(2)) @@ -148,14 +129,7 @@ public void accept(Integer t1) { public void windowUnsubscribeOverlapping() { TestSubscriberEx ts = new TestSubscriberEx<>(); final AtomicInteger count = new AtomicInteger(); - Flowable.merge(Flowable.range(1, 10000).doOnNext(new Consumer() { - - @Override - public void accept(Integer t1) { - count.incrementAndGet(); - } - - }).window(5, 4).take(2)).subscribe(ts); + Flowable.merge(Flowable.range(1, 10000).doOnNext(_ -> count.incrementAndGet()).window(5, 4).take(2)).subscribe(ts); ts.awaitDone(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); // System.out.println(ts.getOnNextEvents()); @@ -168,14 +142,7 @@ public void windowUnsubscribeOverlappingAsyncSource() { TestSubscriberEx ts = new TestSubscriberEx<>(); final AtomicInteger count = new AtomicInteger(); Flowable.merge(Flowable.range(1, 100000) - .doOnNext(new Consumer() { - - @Override - public void accept(Integer t1) { - count.incrementAndGet(); - } - - }) + .doOnNext(_ -> count.incrementAndGet()) .observeOn(Schedulers.computation()) .window(5, 4) .take(2), 128) @@ -247,26 +214,23 @@ public void onComplete() { } public static Flowable hotStream() { - return Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber s) { - BooleanSubscription bs = new BooleanSubscription(); - s.onSubscribe(bs); - while (!bs.isCancelled()) { - // burst some number of items - for (int i = 0; i < Math.random() * 20; i++) { - s.onNext(i); - } - try { - // sleep for a random amount of time - // NOTE: Only using Thread.sleep here as an artificial demo. - Thread.sleep((long) (Math.random() * 200)); - } catch (Exception e) { - // do nothing - } + return Flowable.unsafeCreate((Publisher) s -> { + BooleanSubscription bs = new BooleanSubscription(); + s.onSubscribe(bs); + while (!bs.isCancelled()) { + // burst some number of items + for (int i = 0; i < Math.random() * 20; i++) { + s.onNext(i); + } + try { + // sleep for a random amount of time + // NOTE: Only using Thread.sleep here as an artificial demo. + Thread.sleep((long) (Math.random() * 200)); + } catch (Exception e) { + // do nothing } - System.out.println("Hot done."); } + System.out.println("Hot done."); }).subscribeOn(Schedulers.newThread()); // use newThread since we are using sleep to block } @@ -279,12 +243,7 @@ public void takeFlatMapCompletes() { hotStream() .window(10) .take(2) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable w) { - return w.startWithItem(indicator); - } - }).subscribe(ts); + .flatMap((Function, Flowable>) w -> w.startWithItem(indicator)).subscribe(ts); ts.awaitDone(2, TimeUnit.SECONDS); ts.assertComplete(); @@ -297,18 +256,8 @@ public void backpressureOuterInexact() { Flowable.range(1, 5) .window(2, 1) - .map(new Function, Flowable>>() { - @Override - public Flowable> apply(Flowable t) { - return t.toList().toFlowable(); - } - }) - .concatMapEager(new Function>, Publisher>>() { - @Override - public Publisher> apply(Flowable> v) { - return v; - } - }) + .map(t -> t.toList().toFlowable()) + .concatMapEager((Function>, Publisher>>) v -> v) .subscribe(ts); ts.assertNoErrors(); @@ -326,7 +275,7 @@ public Publisher> apply(Flowable> v) { System.out.println(ts.values()); ts.assertValues(Arrays.asList(1, 2), Arrays.asList(2, 3), - Arrays.asList(3, 4), Arrays.asList(4, 5), Arrays.asList(5)); + Arrays.asList(3, 4), Arrays.asList(4, 5), List.of(5)); ts.assertNoErrors(); ts.assertComplete(); } @@ -342,26 +291,11 @@ public void dispose() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { - @Override - public Flowable> apply(Flowable f) throws Exception { - return f.window(1); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>>) f -> f.window(1)); - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { - @Override - public Flowable> apply(Flowable f) throws Exception { - return f.window(2, 1); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>>) f -> f.window(2, 1)); - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>>() { - @Override - public Flowable> apply(Flowable f) throws Exception { - return f.window(1, 2); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>>) f -> f.window(1, 2)); } @Test @@ -395,12 +329,7 @@ public void errorExactInner() { final TestSubscriber[] to = { null }; Flowable.just(1).concatWith(Flowable.error(new TestException())) .window(2) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Exception { - to[0] = w.test(); - } - }) + .doOnNext(w -> to[0] = w.test()) .test() .assertError(TestException.class); @@ -414,12 +343,7 @@ public void errorSkipInner() { final TestSubscriber[] to = { null }; Flowable.just(1).concatWith(Flowable.error(new TestException())) .window(2, 3) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Exception { - to[0] = w.test(); - } - }) + .doOnNext(w -> to[0] = w.test()) .test() .assertError(TestException.class); @@ -433,12 +357,7 @@ public void errorOverlapInner() { final TestSubscriber[] to = { null }; Flowable.just(1).concatWith(Flowable.error(new TestException())) .window(3, 2) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Exception { - to[0] = w.test(); - } - }) + .doOnNext(w -> to[0] = w.test()) .test() .assertError(TestException.class); @@ -451,12 +370,7 @@ public void cancellingWindowCancelsUpstreamSize() { TestSubscriber ts = pp.window(10) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -477,12 +391,7 @@ public void windowAbandonmentCancelsUpstreamSize() { TestSubscriber> ts = pp.window(10) .take(1) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(v -> inner.set(v)) .test(); assertTrue(pp.hasSubscribers()); @@ -505,12 +414,7 @@ public void cancellingWindowCancelsUpstreamSkip() { TestSubscriber ts = pp.window(5, 10) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -531,12 +435,7 @@ public void windowAbandonmentCancelsUpstreamSkip() { TestSubscriber> ts = pp.window(5, 10) .take(1) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(v -> inner.set(v)) .test(); assertTrue(pp.hasSubscribers()); @@ -559,12 +458,7 @@ public void cancellingWindowCancelsUpstreamOverlap() { TestSubscriber ts = pp.window(5, 3) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -585,12 +479,7 @@ public void windowAbandonmentCancelsUpstreamOverlap() { TestSubscriber> ts = pp.window(5, 3) .take(1) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(inner::set) .test(); assertTrue(pp.hasSubscribers()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java index e25de68387..938001b16e 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java @@ -50,42 +50,28 @@ public void flowableBasedOpenerAndCloser() { final List list = new ArrayList<>(); final List> lists = new ArrayList<>(); - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - push(subscriber, "one", 10); - push(subscriber, "two", 60); - push(subscriber, "three", 110); - push(subscriber, "four", 160); - push(subscriber, "five", 210); - complete(subscriber, 500); - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 60); + push(subscriber, "three", 110); + push(subscriber, "four", 160); + push(subscriber, "five", 210); + complete(subscriber, 500); }); - Flowable openings = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - push(subscriber, new Object(), 50); - push(subscriber, new Object(), 200); - complete(subscriber, 250); - } + Flowable openings = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 50); + push(subscriber, new Object(), 200); + complete(subscriber, 250); }); - Function> closer = new Function>() { - @Override - public Flowable apply(Object opening) { - return Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - push(subscriber, new Object(), 100); - complete(subscriber, 101); - } - }); - } - }; + Function> closer = _ -> Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, new Object(), 100); + complete(subscriber, 101); + }); Flowable> windowed = source.window(openings, closer); windowed.subscribe(observeWindow(list, lists)); @@ -105,46 +91,31 @@ private List list(String... args) { } private void push(final Subscriber subscriber, final T value, int delay) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onNext(value); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onNext(value), delay, TimeUnit.MILLISECONDS); } private void complete(final Subscriber subscriber, int delay) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onComplete(); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onComplete(), delay, TimeUnit.MILLISECONDS); } private Consumer> observeWindow(final List list, final List> lists) { - return new Consumer>() { + return stringFlowable -> stringFlowable.subscribe(new DefaultSubscriber() { @Override - public void accept(Flowable stringFlowable) { - stringFlowable.subscribe(new DefaultSubscriber() { - @Override - public void onComplete() { - lists.add(new ArrayList<>(list)); - list.clear(); - } - - @Override - public void onError(Throwable e) { - fail(e.getMessage()); - } - - @Override - public void onNext(String args) { - list.add(args); - } - }); + public void onComplete() { + lists.add(new ArrayList<>(list)); + list.clear(); } - }; + + @Override + public void onError(Throwable e) { + fail(e.getMessage()); + } + + @Override + public void onNext(String args) { + list.add(args); + } + }); } @Test @@ -156,17 +127,9 @@ public void noUnsubscribeAndNoLeak() { TestSubscriber> ts = new TestSubscriber<>(); - source.window(open, new Function>() { - @Override - public Flowable apply(Integer t) { - return close; - } - }) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment - } + source.window(open, (Function>) _ -> close) + .doOnNext(w -> { + w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment }) .subscribe(ts); @@ -200,17 +163,9 @@ public void unsubscribeAll() { TestSubscriber> ts = new TestSubscriber<>(); - source.window(open, new Function>() { - @Override - public Flowable apply(Integer t) { - return close; - } - }) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment - } + source.window(open, (Function>) _ -> close) + .doOnNext(w -> { + w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment }) .subscribe(ts); @@ -248,12 +203,7 @@ public void onNext(Integer t) { }; pp.window(BehaviorProcessor.createDefault(1), Functions.justFunction(Flowable.never())) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }) + .flatMap((Function, Flowable>) v -> v) .subscribe(ts); pp.onNext(1); @@ -269,12 +219,7 @@ public void boundarySelectorNormal() { PublishProcessor start = PublishProcessor.create(); final PublishProcessor end = PublishProcessor.create(); - TestSubscriber ts = source.window(start, new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - return end; - } - }) + TestSubscriber ts = source.window(start, (Function>) _ -> end) .flatMap(Functions.>identity()) .test(); @@ -305,12 +250,7 @@ public void startError() { PublishProcessor start = PublishProcessor.create(); final PublishProcessor end = PublishProcessor.create(); - TestSubscriber ts = source.window(start, new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - return end; - } - }) + TestSubscriber ts = source.window(start, (Function>) _ -> end) .flatMap(Functions.>identity()) .test(); @@ -330,12 +270,7 @@ public void endError() { PublishProcessor start = PublishProcessor.create(); final PublishProcessor end = PublishProcessor.create(); - TestSubscriber ts = source.window(start, new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - return end; - } - }) + TestSubscriber ts = source.window(start, (Function>) _ -> end) .flatMap(Functions.>identity()) .test(); @@ -363,26 +298,18 @@ public void windowCloseIngoresCancel() { List errors = TestHelper.trackPluginErrors(); try { BehaviorProcessor.createDefault(1) - .window(BehaviorProcessor.createDefault(1), new Function>() { + .window(BehaviorProcessor.createDefault(1), _ -> new Flowable() { @Override - public Publisher apply(Integer f) throws Exception { - return new Flowable() { - @Override - protected void subscribeActual( - Subscriber s) { - s.onSubscribe(new BooleanSubscription()); - s.onNext(1); - s.onNext(2); - s.onError(new TestException()); - } - }; + protected void subscribeActual( + Subscriber s) { + s.onSubscribe(new BooleanSubscription()); + s.onNext(1); + s.onNext(2); + s.onError(new TestException()); } }) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment - } + .doOnNext(w -> { + w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment }) .test() .assertValueCount(1) @@ -397,12 +324,7 @@ public void accept(Flowable w) throws Throwable { static Flowable flowableDisposed(final AtomicBoolean ref) { return Flowable.just(1).concatWith(Flowable.never()) - .doOnCancel(new Action() { - @Override - public void run() throws Exception { - ref.set(true); - } - }); + .doOnCancel(() -> ref.set(true)); } @Test @@ -412,17 +334,9 @@ public void mainAndBoundaryDisposeOnNoWindows() { final AtomicBoolean closeDisposed = new AtomicBoolean(); flowableDisposed(mainDisposed) - .window(flowableDisposed(openDisposed), new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - return flowableDisposed(closeDisposed); - } - }) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment - } + .window(flowableDisposed(openDisposed), (Function>) _ -> flowableDisposed(closeDisposed)) + .doOnNext(w -> { + w.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()); // avoid abandonment }) .to(TestHelper.>testConsumer()) .assertSubscribed() @@ -460,12 +374,7 @@ public void cancellingWindowCancelsUpstream() { TestSubscriber ts = pp.window(Flowable.just(1).concatWith(Flowable.never()), Functions.justFunction(Flowable.never())) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -486,12 +395,7 @@ public void windowAbandonmentCancelsUpstream() { TestSubscriber> ts = pp.window(Flowable.just(1).concatWith(Flowable.never()), Functions.justFunction(Flowable.never())) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(v -> inner.set(v)) .test(); assertTrue(pp.hasSubscribers()); @@ -522,11 +426,8 @@ public void closingIndicatorFunctionCrash() { PublishProcessor source = PublishProcessor.create(); PublishProcessor boundary = PublishProcessor.create(); - TestSubscriber> ts = source.window(boundary, new Function>() { - @Override - public Publisher apply(Integer end) throws Throwable { - throw new TestException(); - } + TestSubscriber> ts = source.window(boundary, _ -> { + throw new TestException(); }) .test() ; diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithTimeTest.java index a432dcd99c..96147c991a 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -50,17 +50,14 @@ public void timedAndCount() { final List list = new ArrayList<>(); final List> lists = new ArrayList<>(); - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - push(subscriber, "one", 10); - push(subscriber, "two", 90); - push(subscriber, "three", 110); - push(subscriber, "four", 190); - push(subscriber, "five", 210); - complete(subscriber, 250); - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 10); + push(subscriber, "two", 90); + push(subscriber, "three", 110); + push(subscriber, "four", 190); + push(subscriber, "five", 210); + complete(subscriber, 250); }); Flowable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); @@ -86,17 +83,14 @@ public void timed() { final List list = new ArrayList<>(); final List> lists = new ArrayList<>(); - Flowable source = Flowable.unsafeCreate(new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(new BooleanSubscription()); - push(subscriber, "one", 98); - push(subscriber, "two", 99); - push(subscriber, "three", 99); // FIXME happens after the window is open - push(subscriber, "four", 101); - push(subscriber, "five", 102); - complete(subscriber, 150); - } + Flowable source = Flowable.unsafeCreate(subscriber -> { + subscriber.onSubscribe(new BooleanSubscription()); + push(subscriber, "one", 98); + push(subscriber, "two", 99); + push(subscriber, "three", 99); // FIXME happens after the window is open + push(subscriber, "four", 101); + push(subscriber, "five", 102); + complete(subscriber, 150); }); Flowable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler); @@ -120,46 +114,31 @@ private List list(String... args) { } private void push(final Subscriber subscriber, final T value, int delay) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onNext(value); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onNext(value), delay, TimeUnit.MILLISECONDS); } private void complete(final Subscriber subscriber, int delay) { - innerScheduler.schedule(new Runnable() { - @Override - public void run() { - subscriber.onComplete(); - } - }, delay, TimeUnit.MILLISECONDS); + innerScheduler.schedule(() -> subscriber.onComplete(), delay, TimeUnit.MILLISECONDS); } private Consumer> observeWindow(final List list, final List> lists) { - return new Consumer>() { + return stringFlowable -> stringFlowable.subscribe(new DefaultSubscriber() { @Override - public void accept(Flowable stringFlowable) { - stringFlowable.subscribe(new DefaultSubscriber() { - @Override - public void onComplete() { - lists.add(new ArrayList<>(list)); - list.clear(); - } + public void onComplete() { + lists.add(new ArrayList<>(list)); + list.clear(); + } - @Override - public void onError(Throwable e) { - Assert.fail(e.getMessage()); - } + @Override + public void onError(Throwable e) { + Assert.fail(e.getMessage()); + } - @Override - public void onNext(T args) { - list.add(args); - } - }); + @Override + public void onNext(T args) { + list.add(args); } - }; + }); } @Test @@ -180,7 +159,7 @@ public void exactWindowSize() { assertEquals(3, lists.get(2).size()); assertEquals(Arrays.asList(7, 8, 9), lists.get(2)); assertEquals(1, lists.get(3).size()); - assertEquals(Arrays.asList(10), lists.get(3)); + assertEquals(List.of(10), lists.get(3)); } @Test @@ -194,31 +173,10 @@ public void takeFlatMapCompletes() { FlowableWindowWithSizeTest.hotStream() .window(300, TimeUnit.MILLISECONDS) .take(10) - .doOnComplete(new Action() { - @Override - public void run() { - System.out.println("Main done!"); - } - }) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable w) { - return w.startWithItem(indicator) - .doOnComplete(new Action() { - @Override - public void run() { - System.out.println("inner done: " + wip.incrementAndGet()); - } - }) - ; - } - }) - .doOnNext(new Consumer() { - @Override - public void accept(Integer pv) { - System.out.println(pv); - } - }) + .doOnComplete(() -> System.out.println("Main done!")) + .flatMap((Function, Flowable>) w -> w.startWithItem(indicator) + .doOnComplete(() -> System.out.println("inner done: " + wip.incrementAndGet()))) + .doOnNext(pv -> System.out.println(pv)) .subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); @@ -515,12 +473,7 @@ public void overlapBackpressure2() { final TestSubscriber tsInner = new TestSubscriber<>(); TestSubscriber> ts = pp.window(2, 1, TimeUnit.SECONDS, scheduler) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(tsInner); - } - }) // avoid abandonment + .doOnNext(w -> w.subscribe(tsInner)) // avoid abandonment .test(1L); scheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -571,12 +524,7 @@ public void exactBoundaryError() { public void restartTimerMany() throws Exception { final AtomicBoolean cancel1 = new AtomicBoolean(); Flowable.intervalRange(1, 1000, 1, 1, TimeUnit.MILLISECONDS) - .doOnCancel(new Action() { - @Override - public void run() throws Exception { - cancel1.set(true); - } - }) + .doOnCancel(() -> cancel1.set(true)) .window(1, TimeUnit.MILLISECONDS, Schedulers.single(), 2, true) .flatMap(Functions.>identity()) .take(500) @@ -613,12 +561,7 @@ public void onNext(Integer t) { }; ps.window(1, TimeUnit.MILLISECONDS, scheduler) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }) + .flatMap((Function, Flowable>) v -> v) .subscribe(ts); ps.onNext(1); @@ -646,12 +589,7 @@ public void onNext(Integer t) { }; ps.window(1, TimeUnit.MILLISECONDS, scheduler, 10, true) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }) + .flatMap((Function, Flowable>) v -> v) .subscribe(ts); ps.onNext(1); @@ -679,12 +617,7 @@ public void onNext(Integer t) { }; ps.window(1, TimeUnit.MILLISECONDS, scheduler, 2, true) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }) + .flatMap((Function, Flowable>) v -> v) .subscribe(ts); ps.onNext(1); @@ -712,12 +645,7 @@ public void onNext(Integer t) { }; ps.window(1, 2, TimeUnit.MILLISECONDS, scheduler) - .flatMap(new Function, Flowable>() { - @Override - public Flowable apply(Flowable v) throws Exception { - return v; - } - }) + .flatMap((Function, Flowable>) v -> v) .subscribe(ts); ps.onNext(1); @@ -829,12 +757,7 @@ public void countRestartsOnTimeTick() { FlowableProcessor ps = PublishProcessor.create(); TestSubscriber> ts = ps.window(5, TimeUnit.MILLISECONDS, scheduler, 5, true) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable w) throws Throwable { - w.subscribe(); - } - }) // avoid abandonment + .doOnNext(w -> w.subscribe()) // avoid abandonment .test(); // window #1 @@ -856,13 +779,7 @@ public void accept(Flowable w) throws Throwable { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>>() { - @Override - public Publisher> apply(Flowable f) - throws Exception { - return f.window(1, TimeUnit.SECONDS, 1).takeLast(0); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable(f -> f.window(1, TimeUnit.SECONDS, 1).takeLast(0)); } @Test @@ -1183,12 +1100,7 @@ public void cancellingWindowCancelsUpstreamExactTime() { TestSubscriber ts = pp.window(10, TimeUnit.MINUTES) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -1209,12 +1121,7 @@ public void windowAbandonmentCancelsUpstreamExactTime() { TestSubscriber> ts = pp.window(10, TimeUnit.MINUTES) .take(1) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(v -> inner.set(v)) .test(); assertFalse("Processor still has subscribers!", pp.hasSubscribers()); @@ -1233,12 +1140,7 @@ public void cancellingWindowCancelsUpstreamExactTimeAndSize() { TestSubscriber ts = pp.window(10, TimeUnit.MINUTES, 100) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -1259,12 +1161,7 @@ public void windowAbandonmentCancelsUpstreamExactTimeAndSize() { TestSubscriber> ts = pp.window(10, TimeUnit.MINUTES, 100) .take(1) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(v -> inner.set(v)) .test(); assertFalse("Processor still has subscribers!", pp.hasSubscribers()); @@ -1283,12 +1180,7 @@ public void cancellingWindowCancelsUpstreamExactTimeSkip() { TestSubscriber ts = pp.window(10, 15, TimeUnit.MINUTES) .take(1) - .flatMap(new Function, Publisher>() { - @Override - public Publisher apply(Flowable w) throws Throwable { - return w.take(1); - } - }) + .flatMap((Function, Publisher>) w -> w.take(1)) .test(); assertTrue(pp.hasSubscribers()); @@ -1309,12 +1201,7 @@ public void windowAbandonmentCancelsUpstreamExactTimeSkip() { TestSubscriber> ts = pp.window(10, 15, TimeUnit.MINUTES) .take(1) - .doOnNext(new Consumer>() { - @Override - public void accept(Flowable v) throws Throwable { - inner.set(v); - } - }) + .doOnNext(inner::set) .test(); assertFalse("Processor still has subscribers!", pp.hasSubscribers()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWithLatestFromTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWithLatestFromTest.java index a4e2ea454d..c7a415f5bf 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableWithLatestFromTest.java @@ -35,17 +35,9 @@ import io.reactivex.rxjava4.testsupport.*; public class FlowableWithLatestFromTest extends RxJavaTest { - static final BiFunction COMBINER = new BiFunction() { - @Override - public Integer apply(Integer t1, Integer t2) { - return (t1 << 8) + t2; - } - }; - static final BiFunction COMBINER_ERROR = new BiFunction() { - @Override - public Integer apply(Integer t1, Integer t2) { - throw new TestException("Forced failure"); - } + static final BiFunction COMBINER = (t1, t2) -> (t1 << 8) + t2; + static final BiFunction COMBINER_ERROR = (_, _) -> { + throw new TestException("Forced failure"); }; @Test public void simple() { @@ -305,12 +297,7 @@ public void backpressure() { ts.assertNoErrors(); } - static final Function toArray = new Function() { - @Override - public String apply(Object[] args) { - return Arrays.toString(args); - } - }; + static final Function toArray = args -> Arrays.toString(args); @Test public void manySources() { @@ -538,12 +525,7 @@ public void with2Others() { TestSubscriber> ts = new TestSubscriber<>(); - just.withLatestFrom(just, just, new Function3>() { - @Override - public List apply(Integer a, Integer b, Integer c) { - return Arrays.asList(a, b, c); - } - }) + just.withLatestFrom(just, just, (a, b, c) -> Arrays.asList(a, b, c)) .subscribe(ts); ts.assertValue(Arrays.asList(1, 1, 1)); @@ -557,12 +539,7 @@ public void with3Others() { TestSubscriber> ts = new TestSubscriber<>(); - just.withLatestFrom(just, just, just, new Function4>() { - @Override - public List apply(Integer a, Integer b, Integer c, Integer d) { - return Arrays.asList(a, b, c, d); - } - }) + just.withLatestFrom(just, just, just, (a, b, c, d) -> Arrays.asList(a, b, c, d)) .subscribe(ts); ts.assertValue(Arrays.asList(1, 1, 1, 1)); @@ -576,12 +553,7 @@ public void with4Others() { TestSubscriber> ts = new TestSubscriber<>(); - just.withLatestFrom(just, just, just, just, new Function5>() { - @Override - public List apply(Integer a, Integer b, Integer c, Integer d, Integer e) { - return Arrays.asList(a, b, c, d, e); - } - }) + just.withLatestFrom(just, just, just, just, (a, b, c, d, e) -> Arrays.asList(a, b, c, d, e)) .subscribe(ts); ts.assertValue(Arrays.asList(1, 1, 1, 1, 1)); @@ -591,46 +563,23 @@ public List apply(Integer a, Integer b, Integer c, Integer d, Integer e @Test public void dispose() { - TestHelper.checkDisposed(Flowable.just(1).withLatestFrom(Flowable.just(2), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a; - } - })); + TestHelper.checkDisposed(Flowable.just(1).withLatestFrom(Flowable.just(2), (BiFunction) (a, _) -> a)); - TestHelper.checkDisposed(Flowable.just(1).withLatestFrom(Flowable.just(2), Flowable.just(3), new Function3() { - @Override - public Object apply(Integer a, Integer b, Integer c) throws Exception { - return a; - } - })); + TestHelper.checkDisposed(Flowable.just(1).withLatestFrom(Flowable.just(2), Flowable.just(3), (Function3) (a, _, _) -> a)); } @Test public void manyIteratorThrows() { Flowable.just(1) - .withLatestFrom(new CrashingMappedIterable<>(1, 100, 100, new Function>() { - @Override - public Flowable apply(Integer v) throws Exception { - return Flowable.just(2); - } - }), new Function() { - @Override - public Object apply(Object[] a) throws Exception { - return a; - } - }) + .withLatestFrom(new CrashingMappedIterable<>(1, 100, 100, _ -> Flowable.just(2)), (Function) a -> a) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @Test public void manyCombinerThrows() { - Flowable.just(1).withLatestFrom(Flowable.just(2), Flowable.just(3), new Function3() { - @Override - public Object apply(Integer a, Integer b, Integer c) throws Exception { - throw new TestException(); - } + Flowable.just(1).withLatestFrom(Flowable.just(2), Flowable.just(3), (_, _, _) -> { + throw new TestException(); }) .test() .assertFailure(TestException.class); @@ -649,12 +598,7 @@ protected void subscribeActual(Subscriber subscriber) { subscriber.onError(new TestException("Second")); subscriber.onComplete(); } - }.withLatestFrom(Flowable.just(2), Flowable.just(3), new Function3() { - @Override - public Object apply(Integer a, Integer b, Integer c) throws Exception { - return a; - } - }) + }.withLatestFrom(Flowable.just(2), Flowable.just(3), (Function3) (a, _, _) -> a) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); @@ -676,12 +620,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("First")); s.onError(new TestException("Second")); } - }, new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + }, Integer::sum) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); @@ -694,12 +633,7 @@ public Integer apply(Integer a, Integer b) throws Exception { @Test public void combineToNull1() { Flowable.just(1) - .withLatestFrom(Flowable.just(2), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return null; - } - }) + .withLatestFrom(Flowable.just(2), (_, _) -> null) .test() .assertFailure(NullPointerException.class); } @@ -707,12 +641,7 @@ public Object apply(Integer a, Integer b) throws Exception { @Test public void combineToNull2() { Flowable.just(1) - .withLatestFrom(Arrays.asList(Flowable.just(2), Flowable.just(3)), new Function() { - @Override - public Object apply(Object[] o) throws Exception { - return null; - } - }) + .withLatestFrom(Arrays.asList(Flowable.just(2), Flowable.just(3)), _ -> null) .test() .assertFailure(NullPointerException.class); } @@ -754,12 +683,7 @@ public void singleRequestNotForgottenWhenNoData() { @Test public void coldSourceConsumedWithoutOther() { Flowable.range(1, 10).withLatestFrom(Flowable.never(), - new BiFunction() { - @Override - public Object apply(Integer a, Object b) throws Exception { - return a; - } - }) + (BiFunction) (a, _) -> a) .test(1) .assertResult(); } @@ -767,12 +691,7 @@ public Object apply(Integer a, Object b) throws Exception { @Test public void coldSourceConsumedWithoutManyOthers() { Flowable.range(1, 10).withLatestFrom(Flowable.never(), Flowable.never(), Flowable.never(), - new Function4() { - @Override - public Object apply(Integer a, Object b, Object c, Object d) throws Exception { - return a; - } - }) + (Function4) (a, _, _, _) -> a) .test(1) .assertResult(); } @@ -785,29 +704,13 @@ public void otherOnSubscribeRace() { final PublishProcessor pp2 = PublishProcessor.create(); final PublishProcessor pp3 = PublishProcessor.create(); - final Flowable source = pp0.withLatestFrom(pp1, pp2, pp3, new Function4() { - @Override - public Object apply(Object a, Integer b, Integer c, Integer d) - throws Exception { - return a; - } - }); + final Flowable source = pp0.withLatestFrom(pp1, pp2, pp3, (Function4) (a, _, _, _) -> a); final TestSubscriber ts = new TestSubscriber<>(); - Runnable r1 = new Runnable() { - @Override - public void run() { - source.subscribe(ts); - } - }; + Runnable r1 = () -> source.subscribe(ts); - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r2 = () -> ts.cancel(); TestHelper.race(r1, r2); @@ -828,29 +731,13 @@ public void otherCompleteRace() { final PublishProcessor pp2 = PublishProcessor.create(); final PublishProcessor pp3 = PublishProcessor.create(); - final Flowable source = pp0.withLatestFrom(pp1, pp2, pp3, new Function4() { - @Override - public Object apply(Object a, Integer b, Integer c, Integer d) - throws Exception { - return a; - } - }); + final Flowable source = pp0.withLatestFrom(pp1, pp2, pp3, (Function4) (a, _, _, _) -> a); final TestSubscriber ts = new TestSubscriber<>(); - Runnable r1 = new Runnable() { - @Override - public void run() { - source.subscribe(ts); - } - }; + Runnable r1 = () -> source.subscribe(ts); - Runnable r2 = new Runnable() { - @Override - public void run() { - pp1.onComplete(); - } - }; + Runnable r2 = () -> pp1.onComplete(); TestHelper.race(r1, r2); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipIterableTest.java index 45b96d6183..9b9f4dce57 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipIterableTest.java @@ -44,12 +44,7 @@ public class FlowableZipIterableTest extends RxJavaTest { @Before public void setUp() { - concat2Strings = new BiFunction() { - @Override - public String apply(String t1, String t2) { - return t1 + "-" + t2; - } - }; + concat2Strings = (t1, t2) -> t1 + "-" + t2; s1 = PublishProcessor.create(); s2 = PublishProcessor.create(); @@ -61,22 +56,8 @@ public String apply(String t1, String t2) { zipped.subscribe(subscriber); } - BiFunction zipr2 = new BiFunction() { - - @Override - public String apply(Object t1, Object t2) { - return "" + t1 + t2; - } - - }; - Function3 zipr3 = new Function3() { - - @Override - public String apply(Object t1, Object t2, Object t3) { - return "" + t1 + t2 + t3; - } - - }; + BiFunction zipr2 = (t1, t2) -> "" + t1 + t2; + Function3 zipr3 = (t1, t2, t3) -> "" + t1 + t2 + t3; @Test public void zipIterableSameSize() { @@ -130,7 +111,7 @@ public void zipIterableEmptySecond() { Subscriber subscriber = TestHelper.mockSubscriber(); InOrder io = inOrder(subscriber); - Iterable r2 = Arrays.asList(); + Iterable r2 = List.of(); r1.zipWith(r2, zipr2).subscribe(subscriber); @@ -222,11 +203,8 @@ public void zipIterableIteratorThrows() { Subscriber subscriber = TestHelper.mockSubscriber(); InOrder io = inOrder(subscriber); - Iterable r2 = new Iterable() { - @Override - public Iterator iterator() { - throw new TestException(); - } + Iterable r2 = () -> { + throw new TestException(); }; r1.zipWith(r2, zipr2).subscribe(subscriber); @@ -249,33 +227,26 @@ public void zipIterableHasNextThrows() { Subscriber subscriber = TestHelper.mockSubscriber(); InOrder io = inOrder(subscriber); - Iterable r2 = new Iterable() { + Iterable r2 = () -> new Iterator() { + int count; + + @Override + public boolean hasNext() { + if (count == 0) { + return true; + } + throw new TestException(); + } + + @Override + public String next() { + count++; + return "1"; + } @Override - public Iterator iterator() { - return new Iterator() { - int count; - - @Override - public boolean hasNext() { - if (count == 0) { - return true; - } - throw new TestException(); - } - - @Override - public String next() { - count++; - return "1"; - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Not supported yet."); - } - - }; + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); } }; @@ -299,27 +270,20 @@ public void zipIterableNextThrows() { Subscriber subscriber = TestHelper.mockSubscriber(); InOrder io = inOrder(subscriber); - Iterable r2 = new Iterable() { + Iterable r2 = () -> new Iterator() { + @Override + public boolean hasNext() { + return true; + } + + @Override + public String next() { + throw new TestException(); + } @Override - public Iterator iterator() { - return new Iterator() { - @Override - public boolean hasNext() { - return true; - } - - @Override - public String next() { - throw new TestException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Not supported yet."); - } - - }; + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); } }; @@ -335,12 +299,7 @@ public void remove() { } - Consumer printer = new Consumer() { - @Override - public void accept(String pv) { - System.out.println(pv); - } - }; + Consumer printer = System.out::println; static final class SquareStr implements Function { final AtomicInteger counter = new AtomicInteger(); @@ -366,37 +325,19 @@ public void take2() { @Test public void dispose() { - TestHelper.checkDisposed(Flowable.just(1).zipWith(Arrays.asList(1), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a + b; - } - })); + TestHelper.checkDisposed(Flowable.just(1).zipWith(List.of(1), + (BiFunction) Integer::sum)); } @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Flowable>() { - @Override - public Flowable apply(Flowable f) throws Exception { - return f.zipWith(Arrays.asList(1), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a + b; - } - }); - } - }); + TestHelper.checkDoubleOnSubscribeFlowable((Function, Flowable>) f -> f.zipWith(List.of(1), + (BiFunction) (a, b) -> a + b)); } @Test public void iteratorThrows() { - Flowable.just(1).zipWith(new CrashingIterable(100, 1, 100), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + Flowable.just(1).zipWith(new CrashingIterable(100, 1, 100), (BiFunction) (a, b) -> a + b) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -416,12 +357,7 @@ protected void subscribeActual(Subscriber subscriber) { subscriber.onComplete(); } } - .zipWith(Arrays.asList(1), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + .zipWith(List.of(1), (BiFunction) (a, b) -> a + b) .test() .assertResult(2); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipTest.java index 400fd6e1a9..89b1c9b825 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableZipTest.java @@ -49,12 +49,7 @@ public class FlowableZipTest extends RxJavaTest { @Before public void setUp() { - concat2Strings = new BiFunction() { - @Override - public String apply(String t1, String t2) { - return t1 + "-" + t2; - } - }; + concat2Strings = (t1, t2) -> t1 + "-" + t2; s1 = PublishProcessor.create(); s2 = PublishProcessor.create(); @@ -154,22 +149,8 @@ public void startpingDifferentLengthFlowableSequences2() { } - BiFunction zipr2 = new BiFunction() { - - @Override - public String apply(Object t1, Object t2) { - return "" + t1 + t2; - } - - }; - Function3 zipr3 = new Function3() { - - @Override - public String apply(Object t1, Object t2, Object t3) { - return "" + t1 + t2 + t3; - } - - }; + BiFunction zipr2 = (t1, t2) -> "" + t1 + t2; + Function3 zipr3 = (t1, t2, t3) -> "" + t1 + t2 + t3; /** * Testing internal private logic due to the complexity so I want to use TDD to test as a I build it rather than @@ -541,69 +522,37 @@ public void onErrorTermination() { } private BiFunction getConcat2Strings() { - return new BiFunction() { - - @Override - public String apply(String t1, String t2) { - return t1 + "-" + t2; - } - }; + return (t1, t2) -> t1 + "-" + t2; } private BiFunction getDivideZipr() { - BiFunction zipr = new BiFunction() { - - @Override - public Integer apply(Integer i1, Integer i2) { - return i1 / i2; - } - - }; + BiFunction zipr = (i1, i2) -> i1 / i2; return zipr; } private Function3 getConcat3StringsZipr() { - Function3 zipr = new Function3() { - - @Override - public String apply(String a1, String a2, String a3) { - if (a1 == null) { - a1 = ""; - } - if (a2 == null) { - a2 = ""; - } - if (a3 == null) { - a3 = ""; - } - return a1 + a2 + a3; + Function3 zipr = (a1, a2, a3) -> { + if (a1 == null) { + a1 = ""; } - + if (a2 == null) { + a2 = ""; + } + if (a3 == null) { + a3 = ""; + } + return a1 + a2 + a3; }; return zipr; } private BiFunction getConcatStringIntegerZipr() { - BiFunction zipr = new BiFunction() { - - @Override - public String apply(String s, Integer i) { - return getStringValue(s) + getStringValue(i); - } - - }; + BiFunction zipr = (s, i) -> getStringValue(s) + getStringValue(i); return zipr; } private Function3 getConcatStringIntegerIntArrayZipr() { - Function3 zipr = new Function3() { - - @Override - public String apply(String s, Integer i, int[] iArray) { - return getStringValue(s) + getStringValue(i) + getStringValue(iArray); - } - - }; + Function3 zipr = (s, i, iArray) -> getStringValue(s) + getStringValue(i) + getStringValue(iArray); return zipr; } @@ -730,12 +679,7 @@ public void startWithOnCompletedTwice() { final Subscriber subscriber = TestHelper.mockSubscriber(); Flowable.zip(Flowable.just(1), - Flowable.just(1), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) { - return a + b; - } - }).subscribe(new DefaultSubscriber() { + Flowable.just(1), (a, b) -> a + b).subscribe(new DefaultSubscriber() { @Override public void onComplete() { @@ -763,22 +707,12 @@ public void onNext(Integer args) { @Test public void start() { Flowable os = OBSERVABLE_OF_5_INTEGERS - .zipWith(OBSERVABLE_OF_5_INTEGERS, new BiFunction() { - - @Override - public String apply(Integer a, Integer b) { - return a + "-" + b; - } - }); + .zipWith(OBSERVABLE_OF_5_INTEGERS, (a, b) -> a + "-" + b); final ArrayList list = new ArrayList<>(); - os.subscribe(new Consumer() { - - @Override - public void accept(String s) { - System.out.println(s); - list.add(s); - } + os.subscribe(s -> { + System.out.println(s); + list.add(s); }); assertEquals(5, list.size()); @@ -790,13 +724,7 @@ public void accept(String s) { @Test public void startAsync() throws InterruptedException { Flowable os = ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)).onBackpressureBuffer() - .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)).onBackpressureBuffer(), new BiFunction() { - - @Override - public String apply(Integer a, Integer b) { - return a + "-" + b; - } - }).take(5); + .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)).onBackpressureBuffer(), (a, b) -> a + "-" + b).take(5); TestSubscriber ts = new TestSubscriber<>(); os.subscribe(ts); @@ -815,13 +743,7 @@ public void startInfiniteAndFinite() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch infiniteFlowable = new CountDownLatch(1); Flowable os = OBSERVABLE_OF_5_INTEGERS - .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(infiniteFlowable), new BiFunction() { - - @Override - public String apply(Integer a, Integer b) { - return a + "-" + b; - } - }); + .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(infiniteFlowable), (a, b) -> a + "-" + b); final ArrayList list = new ArrayList<>(); os.subscribe(new DefaultSubscriber() { @@ -878,23 +800,12 @@ static String value(Notification notification) { public void emitMaterializedNotifications() { Flowable> oi = Flowable.just(1, 2, 3).materialize(); Flowable> os = Flowable.just("a", "b", "c").materialize(); - Flowable f = Flowable.zip(oi, os, new BiFunction, Notification, String>() { - - @Override - public String apply(Notification t1, Notification t2) { - return kind(t1) + "_" + value(t1) + "-" + kind(t2) + "_" + value(t2); - } - - }); + Flowable f = Flowable.zip(oi, os, (t1, t2) -> kind(t1) + "_" + value(t1) + "-" + kind(t2) + "_" + value(t2)); final ArrayList list = new ArrayList<>(); - f.subscribe(new Consumer() { - - @Override - public void accept(String s) { - System.out.println(s); - list.add(s); - } + f.subscribe(s -> { + System.out.println(s); + list.add(s); }); assertEquals(4, list.size()); @@ -907,23 +818,12 @@ public void accept(String s) { @Test public void startEmptyFlowables() { - Flowable f = Flowable.zip(Flowable. empty(), Flowable. empty(), new BiFunction() { - - @Override - public String apply(Integer t1, String t2) { - return t1 + "-" + t2; - } - - }); + Flowable f = Flowable.zip(Flowable. empty(), Flowable. empty(), (t1, t2) -> t1 + "-" + t2); final ArrayList list = new ArrayList<>(); - f.subscribe(new Consumer() { - - @Override - public void accept(String s) { - System.out.println(s); - list.add(s); - } + f.subscribe(s -> { + System.out.println(s); + list.add(s); }); assertEquals(0, list.size()); @@ -935,12 +835,9 @@ public void startEmptyList() { final Object invoked = new Object(); Collection> observables = Collections.emptyList(); - Flowable f = Flowable.zip(observables, new Function() { - @Override - public Object apply(final Object[] args) { - assertEquals("No argument should have been passed", 0, args.length); - return invoked; - } + Flowable f = Flowable.zip(observables, args -> { + Assert.assertEquals("No argument should have been passed", 0, args.length); + return invoked; }); TestSubscriber ts = new TestSubscriber<>(); @@ -959,12 +856,9 @@ public void startEmptyListBlocking() { final Object invoked = new Object(); Collection> observables = Collections.emptyList(); - Flowable f = Flowable.zip(observables, new Function() { - @Override - public Object apply(final Object[] args) { - assertEquals("No argument should have been passed", 0, args.length); - return invoked; - } + Flowable f = Flowable.zip(observables, args -> { + Assert.assertEquals("No argument should have been passed", 0, args.length); + return invoked; }); f.blockingLast(); @@ -978,14 +872,7 @@ public void backpressureSync() { Flowable f2 = createInfiniteFlowable(generatedB); TestSubscriber ts = new TestSubscriber<>(); - Flowable.zip(f1, f2, new BiFunction() { - - @Override - public String apply(Integer t1, Integer t2) { - return t1 + "-" + t2; - } - - }).take(Flowable.bufferSize() * 2).subscribe(ts); + Flowable.zip(f1, f2, (t1, t2) -> t1 + "-" + t2).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -1002,14 +889,7 @@ public void backpressureAsync() { Flowable f2 = createInfiniteFlowable(generatedB).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber<>(); - Flowable.zip(f1, f2, new BiFunction() { - - @Override - public String apply(Integer t1, Integer t2) { - return t1 + "-" + t2; - } - - }).take(Flowable.bufferSize() * 2).subscribe(ts); + Flowable.zip(f1, f2, (t1, t2) -> t1 + "-" + t2).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -1026,14 +906,7 @@ public void downstreamBackpressureRequestsWithFiniteSyncFlowables() { Flowable f2 = createInfiniteFlowable(generatedB).take(Flowable.bufferSize() * 2); TestSubscriber ts = new TestSubscriber<>(); - Flowable.zip(f1, f2, new BiFunction() { - - @Override - public String apply(Integer t1, Integer t2) { - return t1 + "-" + t2; - } - - }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); + Flowable.zip(f1, f2, (t1, t2) -> t1 + "-" + t2).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -1051,14 +924,7 @@ public void downstreamBackpressureRequestsWithInfiniteAsyncFlowables() { Flowable f2 = createInfiniteFlowable(generatedB).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber<>(); - Flowable.zip(f1, f2, new BiFunction() { - - @Override - public String apply(Integer t1, Integer t2) { - return t1 + "-" + t2; - } - - }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); + Flowable.zip(f1, f2, (t1, t2) -> t1 + "-" + t2).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -1076,14 +942,7 @@ public void downstreamBackpressureRequestsWithInfiniteSyncFlowables() { Flowable f2 = createInfiniteFlowable(generatedB); TestSubscriber ts = new TestSubscriber<>(); - Flowable.zip(f1, f2, new BiFunction() { - - @Override - public String apply(Integer t1, Integer t2) { - return t1 + "-" + t2; - } - - }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); + Flowable.zip(f1, f2, (t1, t2) -> t1 + "-" + t2).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -1094,25 +953,20 @@ public String apply(Integer t1, Integer t2) { } private Flowable createInfiniteFlowable(final AtomicInteger generated) { - Flowable flowable = Flowable.fromIterable(new Iterable() { - @Override - public Iterator iterator() { - return new Iterator() { + Flowable flowable = Flowable.fromIterable(() -> new Iterator() { - @Override - public void remove() { - } + @Override + public void remove() { + } - @Override - public Integer next() { - return generated.getAndIncrement(); - } + @Override + public Integer next() { + return generated.getAndIncrement(); + } - @Override - public boolean hasNext() { - return true; - } - }; + @Override + public boolean hasNext() { + return true; } }); return flowable; @@ -1121,52 +975,38 @@ public boolean hasNext() { Flowable OBSERVABLE_OF_5_INTEGERS = OBSERVABLE_OF_5_INTEGERS(new AtomicInteger()); Flowable OBSERVABLE_OF_5_INTEGERS(final AtomicInteger numEmitted) { - return Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(final Subscriber subscriber) { - BooleanSubscription bs = new BooleanSubscription(); - subscriber.onSubscribe(bs); - for (int i = 1; i <= 5; i++) { - if (bs.isCancelled()) { - break; - } - numEmitted.incrementAndGet(); - subscriber.onNext(i); - Thread.yield(); + return Flowable.unsafeCreate(subscriber -> { + BooleanSubscription bs = new BooleanSubscription(); + subscriber.onSubscribe(bs); + for (int i = 1; i <= 5; i++) { + if (bs.isCancelled()) { + break; } - subscriber.onComplete(); + numEmitted.incrementAndGet(); + subscriber.onNext(i); + Thread.yield(); } - + subscriber.onComplete(); }); } Flowable ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(final CountDownLatch latch) { - return Flowable.unsafeCreate(new Publisher() { - - @Override - public void subscribe(final Subscriber subscriber) { - final BooleanSubscription bs = new BooleanSubscription(); - subscriber.onSubscribe(bs); - Thread t = new Thread(new Runnable() { - - @Override - public void run() { - System.out.println("-------> subscribe to infinite sequence"); - System.out.println("Starting thread: " + Thread.currentThread()); - int i = 1; - while (!bs.isCancelled()) { - subscriber.onNext(i++); - Thread.yield(); - } - subscriber.onComplete(); - latch.countDown(); - System.out.println("Ending thread: " + Thread.currentThread()); - } - }); - t.start(); - - } + return Flowable.unsafeCreate(subscriber -> { + final BooleanSubscription bs = new BooleanSubscription(); + subscriber.onSubscribe(bs); + Thread t = new Thread(() -> { + System.out.println("-------> subscribe to infinite sequence"); + System.out.println("Starting thread: " + Thread.currentThread()); + int i = 1; + while (!bs.isCancelled()) { + subscriber.onNext(i++); + Thread.yield(); + } + subscriber.onComplete(); + latch.countDown(); + System.out.println("Ending thread: " + Thread.currentThread()); + }); + t.start(); }); } @@ -1175,21 +1015,9 @@ public void run() { public void issue1812() { // https://github.com/ReactiveX/RxJava/issues/1812 Flowable zip1 = Flowable.zip(Flowable.range(0, 1026), Flowable.range(0, 1026), - new BiFunction() { - - @Override - public Integer apply(Integer i1, Integer i2) { - return i1 + i2; - } - }); + (i1, i2) -> i1 + i2); Flowable zip2 = Flowable.zip(zip1, Flowable.range(0, 1026), - new BiFunction() { - - @Override - public Integer apply(Integer i1, Integer i2) { - return i1 + i2; - } - }); + (i1, i2) -> i1 + i2); List expected = new ArrayList<>(); for (int i = 0; i < 1026; i++) { expected.add(i * 3); @@ -1199,12 +1027,7 @@ public Integer apply(Integer i1, Integer i2) { @Test public void unboundedDownstreamOverrequesting() { - Flowable source = Flowable.range(1, 2).zipWith(Flowable.range(1, 2), new BiFunction() { - @Override - public Integer apply(Integer t1, Integer t2) { - return t1 + 10 * t2; - } - }); + Flowable source = Flowable.range(1, 2).zipWith(Flowable.range(1, 2), (t1, t2) -> t1 + 10 * t2); TestSubscriberEx ts = new TestSubscriberEx() { @Override @@ -1231,12 +1054,7 @@ public void zipRace() { // used so that this test will not timeout on slow machines. int i = 0; while (System.currentTimeMillis() - startTime < 9000 && i++ < 100000) { - int value = Flowable.zip(src, src, new BiFunction() { - @Override - public Integer apply(Integer t1, Integer t2) { - return t1 + t2 * 10; - } - }).blockingSingle(0); + int value = Flowable.zip(src, src, (t1, t2) -> t1 + t2 * 10).blockingSingle(0); Assert.assertEquals(11, value); } @@ -1250,12 +1068,7 @@ public void zipRequest1() { Flowable src = Flowable.just(1).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber<>(1L); - Flowable.zip(src, src, new BiFunction() { - @Override - public Integer apply(Integer t1, Integer t2) { - return t1 + t2 * 10; - } - }).subscribe(ts); + Flowable.zip(src, src, (t1, t2) -> t1 + t2 * 10).subscribe(ts); ts.awaitDone(1, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -1369,12 +1182,7 @@ public void zip2DelayError() { Flowable error2 = Flowable.error(new TestException("Two")); Flowable source2 = Flowable.range(1, 2).concatWith(error2); - TestSubscriberEx ts = Flowable.zip(source1, source2, new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return "" + a + b; - } - }, true) + TestSubscriberEx ts = Flowable.zip(source1, source2, (BiFunction) (a, b) -> "" + a + b, true) .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class, "11", "22"); @@ -1392,12 +1200,7 @@ public void zip2DelayErrorPrefetch() { Flowable error2 = Flowable.error(new TestException("Two")); Flowable source2 = Flowable.range(1, 2).concatWith(error2); - TestSubscriberEx ts = Flowable.zip(source1, source2, new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return "" + a + b; - } - }, true, 1) + TestSubscriberEx ts = Flowable.zip(source1, source2, (BiFunction) (a, b) -> "" + a + b, true, 1) .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class, "11", "22"); @@ -1411,12 +1214,7 @@ public Object apply(Integer a, Integer b) throws Exception { public void zip2Prefetch() { Flowable.zip(Flowable.range(1, 9), Flowable.range(21, 9), - new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return "" + a + b; - } - }, false, 2 + (BiFunction) (a, b) -> "" + a + b, false, 2 ) .takeLast(1) .test() @@ -1432,13 +1230,8 @@ public void zipArrayEmpty() { public void zip2() { Flowable.zip(Flowable.just(1), Flowable.just(2), - new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return "" + a + b; - } - } - ) + (BiFunction) (a, b) -> "" + a + b + ) .test() .assertResult("12"); } @@ -1447,13 +1240,8 @@ public Object apply(Integer a, Integer b) throws Exception { public void zip3() { Flowable.zip(Flowable.just(1), Flowable.just(2), Flowable.just(3), - new Function3() { - @Override - public Object apply(Integer a, Integer b, Integer c) throws Exception { - return "" + a + b + c; - } - } - ) + (Function3) (a, b, c) -> "" + a + b + c + ) .test() .assertResult("123"); } @@ -1463,13 +1251,8 @@ public void zip4() { Flowable.zip(Flowable.just(1), Flowable.just(2), Flowable.just(3), Flowable.just(4), - new Function4() { - @Override - public Object apply(Integer a, Integer b, Integer c, Integer d) throws Exception { - return "" + a + b + c + d; - } - } - ) + (Function4) (a, b, c, d) -> "" + a + b + c + d + ) .test() .assertResult("1234"); } @@ -1479,13 +1262,8 @@ public void zip5() { Flowable.zip(Flowable.just(1), Flowable.just(2), Flowable.just(3), Flowable.just(4), Flowable.just(5), - new Function5() { - @Override - public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e) throws Exception { - return "" + a + b + c + d + e; - } - } - ) + (Function5) (a, b, c, d, e) -> "" + a + b + c + d + e + ) .test() .assertResult("12345"); } @@ -1496,13 +1274,8 @@ public void zip6() { Flowable.just(2), Flowable.just(3), Flowable.just(4), Flowable.just(5), Flowable.just(6), - new Function6() { - @Override - public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integer f) throws Exception { - return "" + a + b + c + d + e + f; - } - } - ) + (Function6) (a, b, c, d, e, f) -> "" + a + b + c + d + e + f + ) .test() .assertResult("123456"); } @@ -1513,14 +1286,8 @@ public void zip7() { Flowable.just(2), Flowable.just(3), Flowable.just(4), Flowable.just(5), Flowable.just(6), Flowable.just(7), - new Function7() { - @Override - public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integer f, Integer g) - throws Exception { - return "" + a + b + c + d + e + f + g; - } - } - ) + (Function7) (a, b, c, d, e, f, g) -> "" + a + b + c + d + e + f + g + ) .test() .assertResult("1234567"); } @@ -1532,14 +1299,9 @@ public void zip8() { Flowable.just(4), Flowable.just(5), Flowable.just(6), Flowable.just(7), Flowable.just(8), - new Function8() { - @Override - public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integer f, Integer g, - Integer h) throws Exception { - return "" + a + b + c + d + e + f + g + h; - } - } - ) + (Function8) + (a, b, c, d, e, f, g, h) -> "" + a + b + c + d + e + f + g + h + ) .test() .assertResult("12345678"); } @@ -1551,14 +1313,9 @@ public void zip9() { Flowable.just(4), Flowable.just(5), Flowable.just(6), Flowable.just(7), Flowable.just(8), Flowable.just(9), - new Function9() { - @Override - public Object apply(Integer a, Integer b, Integer c, Integer d, Integer e, Integer f, Integer g, - Integer h, Integer i) throws Exception { - return "" + a + b + c + d + e + f + g + h + i; - } - } - ) + (Function9) + (a, b, c, d, e, f, g, h, i) -> "" + a + b + c + d + e + f + g + h + i + ) .test() .assertResult("123456789"); } @@ -1570,34 +1327,19 @@ public void zipArrayMany() { Arrays.fill(arr, Flowable.just(1)); - Flowable.zip(Arrays.asList(arr), new Function() { - @Override - public Object apply(Object[] a) throws Exception { - return Arrays.toString(a); - } - }) + Flowable.zip(Arrays.asList(arr), (Function) a -> Arrays.toString(a)) .test() .assertResult("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"); } @Test public void dispose() { - TestHelper.checkDisposed(Flowable.zip(Flowable.just(1), Flowable.just(1), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a + b; - } - })); + TestHelper.checkDisposed(Flowable.zip(Flowable.just(1), Flowable.just(1), (BiFunction) (a, b) -> a + b)); } @Test public void badRequest() { - TestHelper.assertBadRequestReported(Flowable.zip(Flowable.just(1), Flowable.just(1), new BiFunction() { - @Override - public Object apply(Integer a, Integer b) throws Exception { - return a + b; - } - })); + TestHelper.assertBadRequestReported(Flowable.zip(Flowable.just(1), Flowable.just(1), (BiFunction) (a, b) -> a + b)); } @Test @@ -1613,12 +1355,7 @@ public void multiError() { protected void subscribeActual(Subscriber s) { sub[0] = s; } - }, new BiFunction() { - @Override - public Object apply(Object a, Object b) throws Exception { - return a; - } - }) + }, (a, _) -> a) .to(TestHelper.testConsumer()); pp.onError(new TestException("First")); @@ -1639,12 +1376,7 @@ public void singleErrorDelayed() { PublishProcessor pp1 = PublishProcessor.create(); PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriberEx ts = Flowable.zip(pp1, pp2, new BiFunction() { - @Override - public Object apply(Object a, Object b) throws Exception { - return a; - } - }, true) + TestSubscriberEx ts = Flowable.zip(pp1, pp2, (a, _) -> a, true) .to(TestHelper.testConsumer()); pp1.onError(new TestException("First")); @@ -1659,12 +1391,7 @@ public void singleErrorDelayedBackpressured() { PublishProcessor pp1 = PublishProcessor.create(); PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriberEx ts = Flowable.zip(pp1, pp2, new BiFunction() { - @Override - public Object apply(Object a, Object b) throws Exception { - return a; - } - }) + TestSubscriberEx ts = Flowable.zip(pp1, pp2, (a, _) -> a) .to(TestHelper.testSubscriber(0L)); pp1.onError(new TestException("First")); @@ -1676,68 +1403,36 @@ public Object apply(Object a, Object b) throws Exception { @Test public void fusedInputThrows() { - Flowable.zip(Flowable.just(1).map(new Function() { - @Override - public Integer apply(Integer v) throws Exception { - throw new TestException(); - } - }), Flowable.just(2), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + Flowable.zip(Flowable.just(1).map(_ -> { + throw new TestException(); + }), Flowable.just(2), (BiFunction) (a, b) -> a + b) .test() .assertFailure(TestException.class); } @Test public void fusedInputThrowsDelayError() { - Flowable.zip(Flowable.just(1).map(new Function() { - @Override - public Integer apply(Integer v) throws Exception { - throw new TestException(); - } - }), Flowable.just(2), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }, true) + Flowable.zip(Flowable.just(1).map(_ -> { + throw new TestException(); + }), Flowable.just(2), (BiFunction) (a, b) -> a + b, true) .test() .assertFailure(TestException.class); } @Test public void fusedInputThrowsBackpressured() { - Flowable.zip(Flowable.just(1).map(new Function() { - @Override - public Integer apply(Integer v) throws Exception { - throw new TestException(); - } - }), Flowable.just(2), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + Flowable.zip(Flowable.just(1).map(_ -> { + throw new TestException(); + }), Flowable.just(2), (BiFunction) (a, b) -> a + b) .test(0L) .assertFailure(TestException.class); } @Test public void fusedInputThrowsDelayErrorBackpressured() { - Flowable.zip(Flowable.just(1).map(new Function() { - @Override - public Integer apply(Integer v) throws Exception { - throw new TestException(); - } - }), Flowable.just(2), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }, true) + Flowable.zip(Flowable.just(1).map(_ -> { + throw new TestException(); + }), Flowable.just(2), (BiFunction) (a, b) -> a + b, true) .test(0L) .assertFailure(TestException.class); } @@ -1746,25 +1441,10 @@ public Integer apply(Integer a, Integer b) throws Exception { public void noCrossBoundaryFusion() { for (int i = 0; i < 500; i++) { TestSubscriber> ts = Flowable.zip( - Flowable.just(1).observeOn(Schedulers.single()).map(new Function() { - @Override - public Object apply(Integer v) throws Exception { - return Thread.currentThread().getName().substring(0, 4); - } - }), - Flowable.just(1).observeOn(Schedulers.computation()).map(new Function() { - @Override - public Object apply(Integer v) throws Exception { - return Thread.currentThread().getName().substring(0, 4); - } - }), - new BiFunction>() { - @Override - public List apply(Object t1, Object t2) throws Exception { - return Arrays.asList(t1, t2); - } - } - ) + Flowable.just(1).observeOn(Schedulers.single()).map((Function) _ -> Thread.currentThread().getName().substring(0, 4)), + Flowable.just(1).observeOn(Schedulers.computation()).map((Function) _ -> Thread.currentThread().getName().substring(0, 4)), + (t1, t2) -> Arrays.asList(t1, t2) + ) .test() .awaitDone(5, TimeUnit.SECONDS) .assertValueCount(1); @@ -1823,24 +1503,14 @@ public void subscribe(Subscriber s) { @Test public void fusedInputThrows2() { - Flowable.zip(new ThrowingQueueSubscription(), Flowable.just(1), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + Flowable.zip(new ThrowingQueueSubscription(), Flowable.just(1), (a, b) -> a + b) .test() .assertFailure(TestException.class); } @Test public void fusedInputThrows2Backpressured() { - Flowable.zip(new ThrowingQueueSubscription(), Flowable.just(1), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + Flowable.zip(new ThrowingQueueSubscription(), Flowable.just(1), (a, b) -> a + b) .test(0) .assertFailure(TestException.class); } @@ -1856,12 +1526,7 @@ public void onNext(Integer t) { } }; - Flowable.zip(Flowable.range(1, 2), Flowable.range(3, 2), new BiFunction() { - @Override - public Integer apply(Integer a, Integer b) throws Exception { - return a + b; - } - }) + Flowable.zip(Flowable.range(1, 2), Flowable.range(3, 2), (a, b) -> a + b) .subscribe(ts); ts.assertResult(4); @@ -1872,24 +1537,11 @@ public void firstErrorPreventsSecondSubscription() { final AtomicInteger counter = new AtomicInteger(); List> flowableList = new ArrayList<>(); - flowableList.add(Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) - throws Exception { throw new TestException(); } - }, BackpressureStrategy.MISSING)); - flowableList.add(Flowable.create(new FlowableOnSubscribe() { - @Override - public void subscribe(FlowableEmitter e) - throws Exception { counter.getAndIncrement(); } - }, BackpressureStrategy.MISSING)); + flowableList.add(Flowable.create(_ -> { throw new TestException(); }, BackpressureStrategy.MISSING)); + flowableList.add(Flowable.create(_ -> counter.getAndIncrement(), BackpressureStrategy.MISSING)); Flowable.zip(flowableList, - new Function() { - @Override - public Object apply(Object[] a) throws Exception { - return a; - } - }) + (Function) a -> a) .test() .assertFailure(TestException.class) ; @@ -1899,19 +1551,9 @@ public Object apply(Object[] a) throws Exception { @Test public void publishersInIterable() { - Publisher source = new Publisher() { - @Override - public void subscribe(Subscriber subscriber) { - Flowable.just(1).subscribe(subscriber); - } - }; + Publisher source = subscriber -> Flowable.just(1).subscribe(subscriber); - Flowable.zip(Arrays.asList(source, source), new Function() { - @Override - public Integer apply(Object[] t) throws Throwable { - return 2; - } - }) + Flowable.zip(Arrays.asList(source, source), _ -> 2) .test() .assertResult(2); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeConcatIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeConcatIterableTest.java index 5943224892..77de4b9848 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeConcatIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeConcatIterableTest.java @@ -63,7 +63,7 @@ public void successCancelRace() { final PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = Maybe.concat(Arrays.asList(pp.singleElement())) + final TestSubscriber ts = Maybe.concat(Collections.singletonList(pp.singleElement())) .test(); pp.onNext(1); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java index 6e6fff676b..bc6b4ada8e 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java @@ -580,17 +580,17 @@ public void remove() { @Test public void badRequest() { - TestHelper.assertBadRequestReported(MaybeSubject.create().flattenAsFlowable(v -> Arrays.asList(v))); + TestHelper.assertBadRequestReported(MaybeSubject.create().flattenAsFlowable(v -> Collections.singletonList(v))); } @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeMaybeToFlowable(m -> m.flattenAsFlowable(v -> Arrays.asList(v))); + TestHelper.checkDoubleOnSubscribeMaybeToFlowable(m -> m.flattenAsFlowable(v -> Collections.singletonList(v))); } @Test public void onSuccessRequestRace() { - List list = Arrays.asList(1); + List list = List.of(1); for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { MaybeSubject ms = MaybeSubject.create(); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java index 90db182c28..c89398de27 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java @@ -219,7 +219,7 @@ public void bothSucceed() { public void oneSourceOnly() { Maybe.zipArray(v -> Arrays.asList(v), Maybe.just(1)) .test() - .assertResult(Arrays.asList(1)); + .assertResult(List.of(1)); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapMaybeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapMaybeTest.java index 6c80d94fd5..8163ad90db 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapMaybeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapMaybeTest.java @@ -38,13 +38,7 @@ public class FlowableSwitchMapMaybeTest extends RxJavaTest { @Test public void simple() { Flowable.range(1, 5) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return Maybe.just(v); - } - }) + .switchMapMaybe((Function>) v -> Maybe.just(v)) .test() .assertResult(1, 2, 3, 4, 5); } @@ -52,13 +46,7 @@ public MaybeSource apply(Integer v) @Test public void simpleEmpty() { Flowable.range(1, 5) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return Maybe.empty(); - } - }) + .switchMapMaybe((Function>) _ -> Maybe.empty()) .test() .assertResult(); } @@ -66,15 +54,11 @@ public MaybeSource apply(Integer v) @Test public void simpleMixed() { Flowable.range(1, 10) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v % 2 == 0) { - return Maybe.just(v); - } - return Maybe.empty(); + .switchMapMaybe((Function>) v -> { + if (v % 2 == 0) { + return Maybe.just(v); } + return Maybe.empty(); }) .test() .assertResult(2, 4, 6, 8, 10); @@ -83,15 +67,11 @@ public MaybeSource apply(Integer v) @Test public void backpressured() { TestSubscriber ts = Flowable.range(1, 1024) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v % 2 == 0) { - return Maybe.just(v); - } - return Maybe.empty(); + .switchMapMaybe((Function>) v -> { + if (v % 2 == 0) { + return Maybe.just(v); } + return Maybe.empty(); }) .test(0L); @@ -119,27 +99,15 @@ public void innerError() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { - @Override - public Publisher apply(Flowable f) - throws Exception { - return f - .switchMapMaybe(Functions.justFunction(Maybe.never())); - } - } + TestHelper.checkDoubleOnSubscribeFlowable(f -> f + .switchMapMaybe(Functions.justFunction(Maybe.never())) ); } @Test public void limit() { Flowable.range(1, 5) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return Maybe.just(v); - } - }) + .switchMapMaybe((Function>) v -> Maybe.just(v)) .take(3) .test() .assertResult(1, 2, 3); @@ -152,16 +120,12 @@ public void switchOver() { final MaybeSubject ms1 = MaybeSubject.create(); final MaybeSubject ms2 = MaybeSubject.create(); - TestSubscriber ts = pp.switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms1; - } - return ms2; + TestSubscriber ts = pp.switchMapMaybe((Function>) v -> { + if (v == 1) { + return ms1; } - }).test(); + return ms2; + }).test(); ts.assertEmpty(); @@ -190,16 +154,12 @@ public void switchOverDelayError() { final MaybeSubject ms1 = MaybeSubject.create(); final MaybeSubject ms2 = MaybeSubject.create(); - TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms1; - } - return ms2; + TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) v -> { + if (v == 1) { + return ms1; } - }).test(); + return ms2; + }).test(); ts.assertEmpty(); @@ -231,13 +191,7 @@ public void mainErrorInnerCompleteDelayError() { final MaybeSubject ms = MaybeSubject.create(); - TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) _ -> ms).test(); ts.assertEmpty(); @@ -264,13 +218,7 @@ public void mainErrorInnerSuccessDelayError() { final MaybeSubject ms = MaybeSubject.create(); - TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) _ -> ms).test(); ts.assertEmpty(); @@ -294,13 +242,9 @@ public MaybeSource apply(Integer v) @Test public void mapperCrash() { Flowable.just(1) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - throw new TestException(); - } - }) + .switchMapMaybe(_ -> { + throw new TestException(); + }) .test() .assertFailure(TestException.class); } @@ -310,14 +254,10 @@ public void disposeBeforeSwitchInOnNext() { final TestSubscriber ts = new TestSubscriber<>(); Flowable.just(1) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - ts.cancel(); - return Maybe.just(1); - } - }).subscribe(ts); + .switchMapMaybe((Function>) _ -> { + ts.cancel(); + return Maybe.just(1); + }).subscribe(ts); ts.assertEmpty(); } @@ -327,15 +267,11 @@ public void disposeOnNextAfterFirst() { final TestSubscriber ts = new TestSubscriber<>(); Flowable.just(1, 2) - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v == 2) { - ts.cancel(); - } - return Maybe.just(1); + .switchMapMaybe((Function>) v -> { + if (v == 2) { + ts.cancel(); } + return Maybe.just(1); }).subscribe(ts); ts.assertValue(1) @@ -349,13 +285,7 @@ public void cancel() { final MaybeSubject ms = MaybeSubject.create(); - TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) _ -> ms).test(); ts.assertEmpty(); @@ -384,13 +314,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("outer")); } } - .switchMapMaybe(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return Maybe.error(new TestException("inner")); - } - }) + .switchMapMaybe((Function>) _ -> Maybe.error(new TestException("inner"))) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); @@ -414,18 +338,12 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("outer")); } } - .switchMapMaybe(new Function>() { + .switchMapMaybe((Function>) _ -> new Maybe() { @Override - public MaybeSource apply(Integer v) - throws Exception { - return new Maybe() { - @Override - protected void subscribeActual( - MaybeObserver observer) { - observer.onSubscribe(Disposable.empty()); - moRef.set(observer); - } - }; + protected void subscribeActual( + MaybeObserver observer) { + observer.onSubscribe(Disposable.empty()); + moRef.set(observer); } }) .to(TestHelper.testConsumer()); @@ -449,27 +367,11 @@ public void nextCancelRace() { final MaybeSubject ms = MaybeSubject.create(); - final TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + final TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) _ -> ms).test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r1 = () -> pp.onNext(1); - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r2 = () -> ts.cancel(); TestHelper.race(r1, r2); @@ -490,32 +392,18 @@ public void nextInnerErrorRace() { final MaybeSubject ms = MaybeSubject.create(); - final TestSubscriberEx ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms; - } - return Maybe.never(); + final TestSubscriberEx ts = pp.switchMapMaybeDelayError((Function>) v -> { + if (v == 1) { + return ms; } + return Maybe.never(); }).to(TestHelper.testConsumer()); pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(2); - } - }; + Runnable r1 = () -> pp.onNext(2); - Runnable r2 = new Runnable() { - @Override - public void run() { - ms.onError(ex); - } - }; + Runnable r2 = () -> ms.onError(ex); TestHelper.race(r1, r2); @@ -544,41 +432,22 @@ public void mainErrorInnerErrorRace() { final MaybeSubject ms = MaybeSubject.create(); - final TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms; - } - return Maybe.never(); + final TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) v -> { + if (v == 1) { + return ms; } + return Maybe.never(); }).test(); pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onError(ex); - } - }; + Runnable r1 = () -> pp.onError(ex); - Runnable r2 = new Runnable() { - @Override - public void run() { - ms.onError(ex2); - } - }; + Runnable r2 = () -> ms.onError(ex2); TestHelper.race(r1, r2); - ts.assertError(new Predicate() { - @Override - public boolean test(Throwable e) throws Exception { - return e instanceof TestException || e instanceof CompositeException; - } - }); + ts.assertError(e -> e instanceof TestException || e instanceof CompositeException); if (!errors.isEmpty()) { TestHelper.assertUndeliverable(errors, 0, TestException.class); @@ -597,32 +466,18 @@ public void nextInnerSuccessRace() { final MaybeSubject ms = MaybeSubject.create(); - final TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { - @Override - public MaybeSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms; - } - return Maybe.empty(); + final TestSubscriber ts = pp.switchMapMaybeDelayError((Function>) v -> { + if (v == 1) { + return ms; } + return Maybe.empty(); }).test(); pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(2); - } - }; + Runnable r1 = () -> pp.onNext(2); - Runnable r2 = new Runnable() { - @Override - public void run() { - ms.onSuccess(3); - } - }; + Runnable r2 = () -> ms.onSuccess(3); TestHelper.race(r1, r2); @@ -649,31 +504,13 @@ public void onNext(Integer t) { @Test public void undeliverableUponCancel() { - TestHelper.checkUndeliverableUponCancel(new FlowableConverter>() { - @Override - public Flowable apply(Flowable upstream) { - return upstream.switchMapMaybe(new Function>() { - @Override - public Maybe apply(Integer v) throws Throwable { - return Maybe.just(v).hide(); - } - }); - } - }); + TestHelper.checkUndeliverableUponCancel((FlowableConverter>) upstream -> + upstream.switchMapMaybe((Function>) v -> Maybe.just(v).hide())); } @Test public void undeliverableUponCancelDelayError() { - TestHelper.checkUndeliverableUponCancel(new FlowableConverter>() { - @Override - public Flowable apply(Flowable upstream) { - return upstream.switchMapMaybeDelayError(new Function>() { - @Override - public Maybe apply(Integer v) throws Throwable { - return Maybe.just(v).hide(); - } - }); - } - }); + TestHelper.checkUndeliverableUponCancel((FlowableConverter>) upstream -> + upstream.switchMapMaybeDelayError((Function>) v -> Maybe.just(v).hide())); } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapSingleTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapSingleTest.java index 1a53b7305e..aa8cbed53c 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapSingleTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/mixed/FlowableSwitchMapSingleTest.java @@ -38,13 +38,7 @@ public class FlowableSwitchMapSingleTest extends RxJavaTest { @Test public void simple() { Flowable.range(1, 5) - .switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return Single.just(v); - } - }) + .switchMapSingle((Function>) v -> Single.just(v)) .test() .assertResult(1, 2, 3, 4, 5); } @@ -67,27 +61,15 @@ public void innerError() { @Test public void doubleOnSubscribe() { - TestHelper.checkDoubleOnSubscribeFlowable(new Function, Publisher>() { - @Override - public Publisher apply(Flowable f) - throws Exception { - return f - .switchMapSingle(Functions.justFunction(Single.never())); - } - } + TestHelper.checkDoubleOnSubscribeFlowable(f -> f + .switchMapSingle(Functions.justFunction(Single.never())) ); } @Test public void limit() { Flowable.range(1, 5) - .switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return Single.just(v); - } - }) + .switchMapSingle(Single::just) .take(3) .test() .assertResult(1, 2, 3); @@ -100,16 +82,12 @@ public void switchOver() { final SingleSubject ms1 = SingleSubject.create(); final SingleSubject ms2 = SingleSubject.create(); - TestSubscriber ts = pp.switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms1; - } - return ms2; + TestSubscriber ts = pp.switchMapSingle((Function>) v -> { + if (v == 1) { + return ms1; } - }).test(); + return ms2; + }).test(); ts.assertEmpty(); @@ -138,16 +116,12 @@ public void switchOverDelayError() { final SingleSubject ms1 = SingleSubject.create(); final SingleSubject ms2 = SingleSubject.create(); - TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms1; - } - return ms2; + TestSubscriber ts = pp.switchMapSingleDelayError((Function>) v -> { + if (v == 1) { + return ms1; } - }).test(); + return ms2; + }).test(); ts.assertEmpty(); @@ -177,15 +151,9 @@ public SingleSource apply(Integer v) public void mainErrorInnerCompleteDelayError() { PublishProcessor pp = PublishProcessor.create(); - final SingleSubject ms = SingleSubject.create(); + final SingleSubject ss = SingleSubject.create(); - TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + TestSubscriber ts = pp.switchMapSingleDelayError((Function>) _ -> ss).test(); ts.assertEmpty(); @@ -193,15 +161,15 @@ public SingleSource apply(Integer v) ts.assertEmpty(); - assertTrue(ms.hasObservers()); + assertTrue(ss.hasObservers()); pp.onError(new TestException()); - assertTrue(ms.hasObservers()); + assertTrue(ss.hasObservers()); ts.assertEmpty(); - ms.onSuccess(1); + ss.onSuccess(1); ts.assertFailure(TestException.class, 1); } @@ -210,15 +178,9 @@ public SingleSource apply(Integer v) public void mainErrorInnerSuccessDelayError() { PublishProcessor pp = PublishProcessor.create(); - final SingleSubject ms = SingleSubject.create(); + final SingleSubject ss = SingleSubject.create(); - TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + TestSubscriber ts = pp.switchMapSingleDelayError((Function>) _ -> ss).test(); ts.assertEmpty(); @@ -226,15 +188,15 @@ public SingleSource apply(Integer v) ts.assertEmpty(); - assertTrue(ms.hasObservers()); + assertTrue(ss.hasObservers()); pp.onError(new TestException()); - assertTrue(ms.hasObservers()); + assertTrue(ss.hasObservers()); ts.assertEmpty(); - ms.onSuccess(1); + ss.onSuccess(1); ts.assertFailure(TestException.class, 1); } @@ -242,13 +204,9 @@ public SingleSource apply(Integer v) @Test public void mapperCrash() { Flowable.just(1) - .switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - throw new TestException(); - } - }) + .switchMapSingle(_ -> { + throw new TestException(); + }) .test() .assertFailure(TestException.class); } @@ -258,14 +216,10 @@ public void disposeBeforeSwitchInOnNext() { final TestSubscriber ts = new TestSubscriber<>(); Flowable.just(1) - .switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - ts.cancel(); - return Single.just(1); - } - }).subscribe(ts); + .switchMapSingle(_ -> { + ts.cancel(); + return Single.just(1); + }).subscribe(ts); ts.assertEmpty(); } @@ -275,15 +229,11 @@ public void disposeOnNextAfterFirst() { final TestSubscriber ts = new TestSubscriber<>(); Flowable.just(1, 2) - .switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - if (v == 2) { - ts.cancel(); - } - return Single.just(1); + .switchMapSingle((Function>) v -> { + if (v == 2) { + ts.cancel(); } + return Single.just(1); }).subscribe(ts); ts.assertValue(1) @@ -295,15 +245,9 @@ public SingleSource apply(Integer v) public void cancel() { PublishProcessor pp = PublishProcessor.create(); - final SingleSubject ms = SingleSubject.create(); + final SingleSubject ss = SingleSubject.create(); - TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + TestSubscriber ts = pp.switchMapSingleDelayError((Function>) _ -> ss).test(); ts.assertEmpty(); @@ -312,12 +256,12 @@ public SingleSource apply(Integer v) ts.assertEmpty(); assertTrue(pp.hasSubscribers()); - assertTrue(ms.hasObservers()); + assertTrue(ss.hasObservers()); ts.cancel(); assertFalse(pp.hasSubscribers()); - assertFalse(ms.hasObservers()); + assertFalse(ss.hasObservers()); } @Test @@ -332,13 +276,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("outer")); } } - .switchMapSingle(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return Single.error(new TestException("inner")); - } - }) + .switchMapSingle((Function>) _ -> Single.error(new TestException("inner"))) .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); @@ -362,18 +300,12 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("outer")); } } - .switchMapSingle(new Function>() { + .switchMapSingle((Function>) _ -> new Single() { @Override - public SingleSource apply(Integer v) - throws Exception { - return new Single() { - @Override - protected void subscribeActual( - SingleObserver observer) { - observer.onSubscribe(Disposable.empty()); - moRef.set(observer); - } - }; + protected void subscribeActual( + SingleObserver observer) { + observer.onSubscribe(Disposable.empty()); + moRef.set(observer); } }) .to(TestHelper.testConsumer()); @@ -394,29 +326,13 @@ public void nextCancelRace() { final PublishProcessor pp = PublishProcessor.create(); - final SingleSubject ms = SingleSubject.create(); + final SingleSubject ss = SingleSubject.create(); - final TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - return ms; - } - }).test(); + final TestSubscriber ts = pp.switchMapSingleDelayError((Function>) _ -> ss).test(); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(1); - } - }; + Runnable r1 = () -> pp.onNext(1); - Runnable r2 = new Runnable() { - @Override - public void run() { - ts.cancel(); - } - }; + Runnable r2 = () -> ts.cancel(); TestHelper.race(r1, r2); @@ -437,32 +353,18 @@ public void nextInnerErrorRace() { final SingleSubject ms = SingleSubject.create(); - final TestSubscriberEx ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms; - } - return Single.never(); + final TestSubscriberEx ts = pp.switchMapSingleDelayError((Function>) v -> { + if (v == 1) { + return ms; } + return Single.never(); }).to(TestHelper.testConsumer()); pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(2); - } - }; + Runnable r1 = () -> pp.onNext(2); - Runnable r2 = new Runnable() { - @Override - public void run() { - ms.onError(ex); - } - }; + Runnable r2 = () -> ms.onError(ex); TestHelper.race(r1, r2); @@ -491,41 +393,22 @@ public void mainErrorInnerErrorRace() { final SingleSubject ms = SingleSubject.create(); - final TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms; - } - return Single.never(); + final TestSubscriber ts = pp.switchMapSingleDelayError((Function>) v -> { + if (v == 1) { + return ms; } + return Single.never(); }).test(); pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onError(ex); - } - }; + Runnable r1 = () -> pp.onError(ex); - Runnable r2 = new Runnable() { - @Override - public void run() { - ms.onError(ex2); - } - }; + Runnable r2 = () -> ms.onError(ex2); TestHelper.race(r1, r2); - ts.assertError(new Predicate() { - @Override - public boolean test(Throwable e) throws Exception { - return e instanceof TestException || e instanceof CompositeException; - } - }); + ts.assertError(e -> e instanceof TestException || e instanceof CompositeException); if (!errors.isEmpty()) { TestHelper.assertUndeliverable(errors, 0, TestException.class); @@ -544,32 +427,18 @@ public void nextInnerSuccessRace() { final SingleSubject ms = SingleSubject.create(); - final TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { - @Override - public SingleSource apply(Integer v) - throws Exception { - if (v == 1) { - return ms; - } - return Single.never(); + final TestSubscriber ts = pp.switchMapSingleDelayError((Function>) v -> { + if (v == 1) { + return ms; } + return Single.never(); }).test(); pp.onNext(1); - Runnable r1 = new Runnable() { - @Override - public void run() { - pp.onNext(2); - } - }; + Runnable r1 = () -> pp.onNext(2); - Runnable r2 = new Runnable() { - @Override - public void run() { - ms.onSuccess(3); - } - }; + Runnable r2 = () -> ms.onSuccess(3); TestHelper.race(r1, r2); @@ -606,31 +475,13 @@ public void backpressured() { @Test public void undeliverableUponCancel() { - TestHelper.checkUndeliverableUponCancel(new FlowableConverter>() { - @Override - public Flowable apply(Flowable upstream) { - return upstream.switchMapSingle(new Function>() { - @Override - public Single apply(Integer v) throws Throwable { - return Single.just(v).hide(); - } - }); - } - }); + TestHelper.checkUndeliverableUponCancel((FlowableConverter>) upstream -> + upstream.switchMapSingle((Function>) v -> Single.just(v).hide())); } @Test public void undeliverableUponCancelDelayError() { - TestHelper.checkUndeliverableUponCancel(new FlowableConverter>() { - @Override - public Flowable apply(Flowable upstream) { - return upstream.switchMapSingleDelayError(new Function>() { - @Override - public Single apply(Integer v) throws Throwable { - return Single.just(v).hide(); - } - }); - } - }); + TestHelper.checkUndeliverableUponCancel((FlowableConverter>) upstream -> + upstream.switchMapSingleDelayError((Function>) v -> Single.just(v).hide())); } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableBufferTest.java index 7b47f619f7..c30e74115f 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableBufferTest.java @@ -318,7 +318,7 @@ public void accept(List pv) { scheduler.advanceTimeBy(1001, TimeUnit.MILLISECONDS); - inOrder.verify(o, times(5)).onNext(Arrays. asList()); + inOrder.verify(o, times(5)).onNext(List.of()); to.dispose(); @@ -355,7 +355,7 @@ public void bufferWithBONormal1() { source.onNext(6); boundary.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList(6)); + inOrder.verify(o, times(1)).onNext(List.of(6)); inOrder.verify(o).onComplete(); @@ -374,7 +374,7 @@ public void bufferWithBOEmptyLastViaBoundary() { boundary.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList()); + inOrder.verify(o, times(1)).onNext(List.of()); inOrder.verify(o).onComplete(); @@ -393,7 +393,7 @@ public void bufferWithBOEmptyLastViaSource() { source.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList()); + inOrder.verify(o, times(1)).onNext(List.of()); inOrder.verify(o).onComplete(); @@ -413,7 +413,7 @@ public void bufferWithBOEmptyLastViaBoth() { source.onComplete(); boundary.onComplete(); - inOrder.verify(o, times(1)).onNext(Arrays.asList()); + inOrder.verify(o, times(1)).onNext(List.of()); inOrder.verify(o).onComplete(); @@ -533,8 +533,8 @@ public void bufferWithBoundaryTake2() { scheduler.advanceTimeBy(5, TimeUnit.SECONDS); - inOrder.verify(o).onNext(Arrays.asList(0L)); - inOrder.verify(o).onNext(Arrays.asList(1L)); + inOrder.verify(o).onNext(List.of(0L)); + inOrder.verify(o).onNext(List.of(1L)); inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); @@ -594,7 +594,7 @@ public void bufferWithSizeThrows() { inOrder.verify(o).onNext(Arrays.asList(1, 2)); inOrder.verify(o).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(Arrays.asList(3)); + verify(o, never()).onNext(List.of(3)); verify(o, never()).onComplete(); } @@ -620,7 +620,7 @@ public void bufferWithTimeThrows() { inOrder.verify(o).onNext(Arrays.asList(1, 2)); inOrder.verify(o).onError(any(TestException.class)); inOrder.verifyNoMoreInteractions(); - verify(o, never()).onNext(Arrays.asList(3)); + verify(o, never()).onNext(List.of(3)); verify(o, never()).onComplete(); } @@ -639,7 +639,7 @@ public void bufferWithTimeAndSize() { scheduler.advanceTimeBy(5, TimeUnit.SECONDS); inOrder.verify(o).onNext(Arrays.asList(0L, 1L)); - inOrder.verify(o).onNext(Arrays.asList(2L)); + inOrder.verify(o).onNext(List.of(2L)); inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); } @@ -757,7 +757,7 @@ public void onComplete() { cdl.await(); - verify(o).onNext(Arrays.asList(1)); + verify(o).onNext(List.of(1)); verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); @@ -988,7 +988,7 @@ public void restartTimer() { Observable.range(1, 5) .buffer(1, TimeUnit.DAYS, Schedulers.single(), 2, Functions.createArrayList(16), true) .test() - .assertResult(Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5)); + .assertResult(Arrays.asList(1, 2), Arrays.asList(3, 4), List.of(5)); } @Test @@ -1005,7 +1005,7 @@ public List get() throws Exception { } }) .test() - .assertFailure(TestException.class, Arrays.asList(1)); + .assertFailure(TestException.class, List.of(1)); } @Test @@ -1043,7 +1043,7 @@ public void bufferSkipOverlap() { Arrays.asList(2, 3, 4, 5), Arrays.asList(3, 4, 5), Arrays.asList(4, 5), - Arrays.asList(5) + List.of(5) ); } @@ -1121,7 +1121,7 @@ public List get() throws Exception { ps.onNext(2); to - .assertFailure(TestException.class, Arrays.asList(1)); + .assertFailure(TestException.class, List.of(1)); } @Test @@ -1817,7 +1817,7 @@ public void boundaryCloseCompleteRace() { () -> ps.onComplete() ); - to.assertResult(Arrays.asList(1)); + to.assertResult(List.of(1)); } } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableCollectTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableCollectTest.java index 79250c75ed..e084975cd1 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableCollectTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableCollectTest.java @@ -357,6 +357,6 @@ public void accept(List a, Integer b) throws Exception { } }).toObservable(); } - }, false, 1, 2, Arrays.asList(1)); + }, false, 1, 2, List.of(1)); } } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatMapSchedulerTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatMapSchedulerTest.java index ca37aac3a5..4d876e5e2f 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatMapSchedulerTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatMapSchedulerTest.java @@ -378,7 +378,7 @@ public void concatMapRangeAsyncLoopIssue2876() { .concatMap(new Function>() { @Override public Observable apply(Integer t) { - return Observable.fromIterable(Arrays.asList(t)); + return Observable.fromIterable(Collections.singletonList(t)); } }, 2, ImmediateThinScheduler.INSTANCE) .observeOn(Schedulers.computation()).subscribe(to); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatTest.java index ce5a16bfef..772a0a40ee 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableConcatTest.java @@ -755,7 +755,7 @@ public void concatMapRangeAsyncLoopIssue2876() { .concatMap(new Function>() { @Override public Observable apply(Integer t) { - return Observable.fromIterable(Arrays.asList(t)); + return Observable.fromIterable(Collections.singletonList(t)); } }) .observeOn(Schedulers.computation()) diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableFlatMapTest.java index 105f344ba1..0b162ab718 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableFlatMapTest.java @@ -178,8 +178,8 @@ public R get() { @Test public void flatMapTransformsNormal() { Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onComplete = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onComplete = Observable.fromIterable(List.of(4)); + Observable onError = Observable.fromIterable(List.of(5)); Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); @@ -200,8 +200,8 @@ public void flatMapTransformsNormal() { @Test public void flatMapTransformsException() { Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onComplete = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onComplete = Observable.fromIterable(List.of(4)); + Observable onError = Observable.fromIterable(List.of(5)); Observable source = Observable.concat( Observable.fromIterable(Arrays.asList(10, 20, 30)), @@ -242,8 +242,8 @@ public R apply(T t) { @Test public void flatMapTransformsOnNextFuncThrows() { - Observable onComplete = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onComplete = Observable.fromIterable(List.of(4)); + Observable onError = Observable.fromIterable(List.of(5)); Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); @@ -259,8 +259,8 @@ public void flatMapTransformsOnNextFuncThrows() { @Test public void flatMapTransformsOnErrorFuncThrows() { Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onComplete = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onComplete = Observable.fromIterable(List.of(4)); + Observable onError = Observable.fromIterable(List.of(5)); Observable source = Observable.error(new TestException()); @@ -276,10 +276,10 @@ public void flatMapTransformsOnErrorFuncThrows() { @Test public void flatMapTransformsOnCompletedFuncThrows() { Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onComplete = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onComplete = Observable.fromIterable(List.of(4)); + Observable onError = Observable.fromIterable(List.of(5)); - Observable source = Observable.fromIterable(Arrays. asList()); + Observable source = Observable.fromIterable(List.of()); Observer o = TestHelper.mockObserver(); @@ -293,8 +293,8 @@ public void flatMapTransformsOnCompletedFuncThrows() { @Test public void flatMapTransformsMergeException() { Observable onNext = Observable.error(new TestException()); - Observable onComplete = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onComplete = Observable.fromIterable(List.of(4)); + Observable onError = Observable.fromIterable(List.of(5)); Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); @@ -409,10 +409,10 @@ public void flatMapTransformsMaxConcurrentNormal() { .subscribeOn(Schedulers.computation()) ; - Observable onComplete = composer(Observable.fromIterable(Arrays.asList(4)), subscriptionCount, m) + Observable onComplete = composer(Observable.fromIterable(List.of(4)), subscriptionCount, m) .subscribeOn(Schedulers.computation()); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Observable onError = Observable.fromIterable(List.of(5)); Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableGroupByTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableGroupByTest.java index 1b806af35b..c79fc5e738 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableGroupByTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableGroupByTest.java @@ -56,7 +56,7 @@ public void groupBy() { assertEquals(3, map.size()); assertArrayEquals(Arrays.asList("one", "two", "six").toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList("four", "five").toArray(), map.get(4).toArray()); - assertArrayEquals(Arrays.asList("three").toArray(), map.get(5).toArray()); + assertArrayEquals(List.of("three").toArray(), map.get(5).toArray()); } @Test @@ -69,7 +69,7 @@ public void groupByWithElementSelector() { assertEquals(3, map.size()); assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray()); - assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray()); + assertArrayEquals(List.of(5).toArray(), map.get(5).toArray()); } @Test @@ -82,7 +82,7 @@ public void groupByWithElementSelector2() { assertEquals(3, map.size()); assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray()); - assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray()); + assertArrayEquals(List.of(5).toArray(), map.get(5).toArray()); } @Test @@ -1443,9 +1443,9 @@ public Integer apply(Integer i) { return i % 2; } }).subscribe(outer); - assertEquals(Arrays.asList(e), outer.errors()); - assertEquals(Arrays.asList(e), inner1.errors()); - assertEquals(Arrays.asList(e), inner2.errors()); + assertEquals(List.of(e), outer.errors()); + assertEquals(List.of(e), inner1.errors()); + assertEquals(List.of(e), inner2.errors()); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayEagerTruncateTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayEagerTruncateTest.java index 498565e973..d2e6a7f5f0 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayEagerTruncateTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayEagerTruncateTest.java @@ -761,7 +761,7 @@ public void timedAndSizedTruncation() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -774,7 +774,7 @@ public void timedAndSizedTruncation() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); Assert.assertFalse(buf.hasCompleted()); test.advanceTimeBy(2, TimeUnit.SECONDS); @@ -804,7 +804,7 @@ public void timedAndSizedTruncationError() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -817,7 +817,7 @@ public void timedAndSizedTruncationError() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); Assert.assertFalse(buf.hasCompleted()); Assert.assertFalse(buf.hasError()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayTest.java index cb801a1e79..78609ab5a2 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableReplayTest.java @@ -761,7 +761,7 @@ public void timedAndSizedTruncation() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -774,7 +774,7 @@ public void timedAndSizedTruncation() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); Assert.assertFalse(buf.hasCompleted()); test.advanceTimeBy(2, TimeUnit.SECONDS); @@ -804,7 +804,7 @@ public void timedAndSizedTruncationError() { buf.next(2); test.advanceTimeBy(1, TimeUnit.SECONDS); buf.collect(values); - Assert.assertEquals(Arrays.asList(2), values); + Assert.assertEquals(List.of(2), values); buf.next(3); buf.next(4); @@ -817,7 +817,7 @@ public void timedAndSizedTruncationError() { values.clear(); buf.collect(values); - Assert.assertEquals(Arrays.asList(5), values); + Assert.assertEquals(List.of(5), values); Assert.assertFalse(buf.hasCompleted()); Assert.assertFalse(buf.hasError()); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchIfEmptyTest.java index 55fae91ae2..fc78b40686 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchIfEmptyTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.*; -import java.util.Arrays; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; @@ -46,7 +46,7 @@ public void accept(Disposable d) { @Test public void switchWhenEmpty() throws Exception { final Observable o = Observable.empty() - .switchIfEmpty(Observable.fromIterable(Arrays.asList(42))); + .switchIfEmpty(Observable.fromIterable(List.of(42))); assertEquals(42, o.blockingSingle().intValue()); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchTest.java index 932e26f307..123629f015 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableSwitchTest.java @@ -1231,7 +1231,7 @@ public void switchMapFusedIterable() { @Override public Observable apply(Integer v) throws Throwable { - return Observable.fromIterable(Arrays.asList(v * 10)); + return Observable.fromIterable(List.of(v * 10)); } }) .test() @@ -1245,7 +1245,7 @@ public void switchMapHiddenIterable() { @Override public Observable apply(Integer v) throws Throwable { - return Observable.fromIterable(Arrays.asList(v * 10)).hide(); + return Observable.fromIterable(List.of(v * 10)).hide(); } }) .test() diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableTimeoutWithSelectorTest.java index a5a4147ce1..bf7edc09e1 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableTimeoutWithSelectorTest.java @@ -53,7 +53,7 @@ public Observable apply(Integer t1) { } }; - Observable other = Observable.fromIterable(Arrays.asList(100)); + Observable other = Observable.fromIterable(List.of(100)); Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); @@ -86,7 +86,7 @@ public Observable apply(Integer t1) { } }; - Observable other = Observable.fromIterable(Arrays.asList(100)); + Observable other = Observable.fromIterable(List.of(100)); Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); @@ -120,7 +120,7 @@ public Observable get() { } }; - Observable other = Observable.fromIterable(Arrays.asList(100)); + Observable other = Observable.fromIterable(List.of(100)); Observer o = TestHelper.mockObserver(); @@ -144,7 +144,7 @@ public Observable apply(Integer t1) { } }; - Observable other = Observable.fromIterable(Arrays.asList(100)); + Observable other = Observable.fromIterable(List.of(100)); Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); @@ -171,7 +171,7 @@ public Observable apply(Integer t1) { } }; - Observable other = Observable.fromIterable(Arrays.asList(100)); + Observable other = Observable.fromIterable(List.of(100)); Observer o = TestHelper.mockObserver(); @@ -195,7 +195,7 @@ public Observable apply(Integer t1) { } }; - Observable other = Observable.fromIterable(Arrays.asList(100)); + Observable other = Observable.fromIterable(List.of(100)); Observer o = TestHelper.mockObserver(); InOrder inOrder = inOrder(o); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableToMultimapTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableToMultimapTest.java index bafef0eb86..b09938494c 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableToMultimapTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableToMultimapTest.java @@ -162,7 +162,7 @@ public Map> get() { Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); - expected.put(3, new HashSet<>(Arrays.asList("eee"))); + expected.put(3, new HashSet<>(List.of("eee"))); mapped.subscribe(objectObserver); @@ -407,7 +407,7 @@ public Map> get() { Map> expected = new HashMap<>(); expected.put(2, Arrays.asList("cc", "dd")); - expected.put(3, new HashSet<>(Arrays.asList("eee"))); + expected.put(3, new HashSet<>(List.of("eee"))); mapped.subscribe(singleObserver); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableWindowWithTimeTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableWindowWithTimeTest.java index 588618fcd7..bef95b3e26 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableWindowWithTimeTest.java @@ -179,7 +179,7 @@ public void exactWindowSize() { assertEquals(3, lists.get(2).size()); assertEquals(Arrays.asList(7, 8, 9), lists.get(2)); assertEquals(1, lists.get(3).size()); - assertEquals(Arrays.asList(10), lists.get(3)); + assertEquals(List.of(10), lists.get(3)); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableZipIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableZipIterableTest.java index d434da6168..e4d454c0a1 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableZipIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/observable/ObservableZipIterableTest.java @@ -131,7 +131,7 @@ public void zipIterableEmptySecond() { Observer o = TestHelper.mockObserver(); InOrder io = inOrder(o); - Iterable r2 = Arrays.asList(); + Iterable r2 = List.of(); r1.zipWith(r2, zipr2).subscribe(o); @@ -367,7 +367,7 @@ public void take2() { @Test public void dispose() { - TestHelper.checkDisposed(Observable.just(1).zipWith(Arrays.asList(1), new BiFunction() { + TestHelper.checkDisposed(Observable.just(1).zipWith(List.of(1), new BiFunction() { @Override public Object apply(Integer a, Integer b) throws Exception { return a + b; @@ -380,7 +380,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeObservable(new Function, ObservableSource>() { @Override public ObservableSource apply(Observable o) throws Exception { - return o.zipWith(Arrays.asList(1), new BiFunction() { + return o.zipWith(List.of(1), new BiFunction() { @Override public Object apply(Integer a, Integer b) throws Exception { return a + b; @@ -417,7 +417,7 @@ protected void subscribeActual(Observer observer) { observer.onComplete(); } } - .zipWith(Arrays.asList(1), new BiFunction() { + .zipWith(List.of(1), new BiFunction() { @Override public Object apply(Integer a, Integer b) throws Exception { return a + b; diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java index 768eea60ef..44d13e3ac1 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java @@ -618,7 +618,7 @@ public void onNext(@NonNull Integer t) { @Test public void onSuccessRequestRace() { - List list = Arrays.asList(1); + List list = List.of(1); for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { SingleSubject ss = SingleSubject.create(); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleZipIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleZipIterableTest.java index d3f35a1988..523d3628ac 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleZipIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleZipIterableTest.java @@ -231,7 +231,7 @@ public Object apply(Object[] a) throws Exception { @Test public void singleSourceZipperReturnsNull() { - Single.zip(Arrays.asList(Single.just(1)), Functions.justFunction(null)) + Single.zip(Collections.singletonList(Single.just(1)), Functions.justFunction(null)) .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The zipper returned a null value"); } diff --git a/src/test/java/io/reactivex/rxjava4/internal/subscribers/FlowableConsumersTest.java b/src/test/java/io/reactivex/rxjava4/internal/subscribers/FlowableConsumersTest.java index 1edeb7840c..58b9a50cbf 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/subscribers/FlowableConsumersTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/subscribers/FlowableConsumersTest.java @@ -86,11 +86,11 @@ public void onNextNormal() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onComplete(); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); assertEquals(0, composite.size()); } @@ -108,11 +108,11 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onComplete(); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); assertEquals(0, composite.size()); } @@ -132,7 +132,7 @@ public void onErrorError() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onError(new IOException()); @@ -155,7 +155,7 @@ public void onCompleteNormal() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onComplete(); @@ -177,7 +177,7 @@ public void onCompleteError() { assertTrue(composite.size() > 0); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); processor.onError(new IOException()); @@ -277,7 +277,7 @@ public void onCompleteCrash() { processor.onNext(1); processor.onComplete(); - assertEquals(Arrays.asList(1), events); + assertEquals(List.of(1), events); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { diff --git a/src/test/java/io/reactivex/rxjava4/maybe/MaybeTest.java b/src/test/java/io/reactivex/rxjava4/maybe/MaybeTest.java index 15ab66d1a7..8f76e14baf 100644 --- a/src/test/java/io/reactivex/rxjava4/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/rxjava4/maybe/MaybeTest.java @@ -2215,7 +2215,7 @@ public void run() throws Exception { source.subscribe(Functions.emptyConsumer(), Functions.emptyConsumer(), onComplete); - assertEquals(Arrays.asList(100), values); + assertEquals(List.of(100), values); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/observable/ObservableNullTests.java b/src/test/java/io/reactivex/rxjava4/observable/ObservableNullTests.java index 7690ba22c2..4e28cc13ea 100644 --- a/src/test/java/io/reactivex/rxjava4/observable/ObservableNullTests.java +++ b/src/test/java/io/reactivex/rxjava4/observable/ObservableNullTests.java @@ -83,7 +83,7 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void combineLatestIterableFunctionReturnsNull() { - Observable.combineLatest(Arrays.asList(just1), new Function() { + Observable.combineLatest(Collections.singletonList(just1), new Function() { @Override public Object apply(Object[] v) { return null; @@ -118,7 +118,7 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void combineLatestDelayErrorIterableFunctionReturnsNull() { - Observable.combineLatestDelayError(Arrays.asList(just1), new Function() { + Observable.combineLatestDelayError(Collections.singletonList(just1), new Function() { @Override public Object apply(Object[] v) { return null; @@ -671,7 +671,7 @@ public void flatMapIterableCombinerReturnsNull() { just1.flatMapIterable(new Function>() { @Override public Iterable apply(Integer v) { - return Arrays.asList(1); + return List.of(1); } }, new BiFunction() { @Override @@ -1062,7 +1062,7 @@ public Object apply(Integer a, Integer b) { @Test(expected = NullPointerException.class) public void zipWithIterableCombinerReturnsNull() { - just1.zipWith(Arrays.asList(1), new BiFunction() { + just1.zipWith(List.of(1), new BiFunction() { @Override public Object apply(Integer a, Integer b) { return null; diff --git a/src/test/java/io/reactivex/rxjava4/observable/ObservableSubscriberTest.java b/src/test/java/io/reactivex/rxjava4/observable/ObservableSubscriberTest.java index c40fb793ff..0558a7bc88 100644 --- a/src/test/java/io/reactivex/rxjava4/observable/ObservableSubscriberTest.java +++ b/src/test/java/io/reactivex/rxjava4/observable/ObservableSubscriberTest.java @@ -142,7 +142,7 @@ public void accept(Throwable e) throws Exception { } }); - assertEquals(Arrays.asList(1), list); + assertEquals(List.of(1), list); } @Test @@ -161,7 +161,7 @@ public void accept(Throwable e) throws Exception { } }); - assertEquals(Arrays.asList(100), list); + assertEquals(List.of(100), list); } @Test diff --git a/src/test/java/io/reactivex/rxjava4/parallel/ParallelFlatMapIterableTest.java b/src/test/java/io/reactivex/rxjava4/parallel/ParallelFlatMapIterableTest.java index ebc0509a5f..bb4d277262 100644 --- a/src/test/java/io/reactivex/rxjava4/parallel/ParallelFlatMapIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/parallel/ParallelFlatMapIterableTest.java @@ -14,6 +14,7 @@ package io.reactivex.rxjava4.parallel; import java.util.Arrays; +import java.util.List; import org.junit.Test; @@ -47,7 +48,7 @@ public void none() { for (int i = 1; i < 32; i++) { Flowable.range(1, 1000) .parallel(i) - .flatMapIterable(_ -> Arrays.asList()) + .flatMapIterable(_ -> List.of()) .sequential() .test() .withTag("Parallelism: " + i) @@ -60,7 +61,7 @@ public void mixed() { for (int i = 1; i < 32; i++) { Flowable.range(1, 1000) .parallel(i) - .flatMapIterable(v -> v % 2 == 0 ? Arrays.asList(v) : Arrays.asList()) + .flatMapIterable(v -> v % 2 == 0 ? List.of(v) : List.of()) .sequential() .test() .withTag("Parallelism: " + i) diff --git a/src/test/java/io/reactivex/rxjava4/parallel/ParallelSortedJoinTest.java b/src/test/java/io/reactivex/rxjava4/parallel/ParallelSortedJoinTest.java index 73ddd9556f..35236ea2f8 100644 --- a/src/test/java/io/reactivex/rxjava4/parallel/ParallelSortedJoinTest.java +++ b/src/test/java/io/reactivex/rxjava4/parallel/ParallelSortedJoinTest.java @@ -227,8 +227,8 @@ public void comparatorCrashWhileMainOnError() throws Throwable { }) .test(); - pp1.onNext(Arrays.asList(1)); - pp2.onNext(Arrays.asList(2)); + pp1.onNext(List.of(1)); + pp2.onNext(List.of(2)); pp1.onComplete(); pp2.onComplete(); diff --git a/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorBoundedConcurrencyTest.java b/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorBoundedConcurrencyTest.java index cbf1e2b88e..f51375497b 100644 --- a/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorBoundedConcurrencyTest.java @@ -290,7 +290,7 @@ public void run() { */ @Test public void raceForTerminalState() { - final List expected = Arrays.asList(1); + final List expected = List.of(1); for (int i = 0; i < 100000; i++) { TestSubscriberEx ts = new TestSubscriberEx<>(); Flowable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); diff --git a/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorConcurrencyTest.java b/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorConcurrencyTest.java index 78b2f7ae28..6321faa6d6 100644 --- a/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorConcurrencyTest.java +++ b/src/test/java/io/reactivex/rxjava4/processors/ReplayProcessorConcurrencyTest.java @@ -290,7 +290,7 @@ public void run() { */ @Test public void raceForTerminalState() { - final List expected = Arrays.asList(1); + final List expected = List.of(1); for (int i = 0; i < 100000; i++) { TestSubscriberEx ts = new TestSubscriberEx<>(); Flowable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); diff --git a/src/test/java/io/reactivex/rxjava4/single/SingleTest.java b/src/test/java/io/reactivex/rxjava4/single/SingleTest.java index 66ff1227a6..ffc9ff8098 100644 --- a/src/test/java/io/reactivex/rxjava4/single/SingleTest.java +++ b/src/test/java/io/reactivex/rxjava4/single/SingleTest.java @@ -37,7 +37,7 @@ public class SingleTest extends RxJavaTest { public void helloWorld() { TestSubscriber ts = new TestSubscriber<>(); Single.just("Hello World!").toFlowable().subscribe(ts); - ts.assertValueSequence(Arrays.asList("Hello World!")); + ts.assertValueSequence(List.of("Hello World!")); } @Test @@ -75,7 +75,7 @@ public String apply(String s) { } }) .toFlowable().subscribe(ts); - ts.assertValueSequence(Arrays.asList("AB")); + ts.assertValueSequence(List.of("AB")); } @Test @@ -91,7 +91,7 @@ public String apply(String a1, String b1) { } }) .toFlowable().subscribe(ts); - ts.assertValueSequence(Arrays.asList("AB")); + ts.assertValueSequence(List.of("AB")); } @Test @@ -105,7 +105,7 @@ public String apply(String a1, String b1) { } }) .toFlowable().subscribe(ts); - ts.assertValueSequence(Arrays.asList("AB")); + ts.assertValueSequence(List.of("AB")); } @Test @@ -138,7 +138,7 @@ public void subscribe(SingleObserver observer) { } }).toFlowable().subscribe(ts); - ts.assertValueSequence(Arrays.asList("Hello")); + ts.assertValueSequence(List.of("Hello")); } @Test @@ -178,7 +178,7 @@ public String apply(String v) { }) .toFlowable().subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); - ts.assertValueSequence(Arrays.asList("Hello")); + ts.assertValueSequence(List.of("Hello")); } @Test @@ -195,7 +195,7 @@ public Single apply(String s) { ts.cancel(); Assert.fail("TestSubscriber timed out."); } - ts.assertValueSequence(Arrays.asList("Hello World!")); + ts.assertValueSequence(List.of("Hello World!")); } @Test @@ -511,7 +511,7 @@ public void toFutureThrows() throws Exception { @Test(expected = UnsupportedOperationException.class) public void toFlowableIterableRemove() { - Iterable> f = SingleInternalHelper.iterableToFlowable(Arrays.asList(Single.just(1))); + Iterable> f = SingleInternalHelper.iterableToFlowable(Collections.singletonList(Single.just(1))); Iterator> iterator = f.iterator(); iterator.next(); diff --git a/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectBoundedConcurrencyTest.java b/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectBoundedConcurrencyTest.java index 0cafb7c546..7264e2e41e 100644 --- a/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectBoundedConcurrencyTest.java @@ -294,7 +294,7 @@ public void run() { */ @Test public void raceForTerminalState() { - final List expected = Arrays.asList(1); + final List expected = List.of(1); for (int i = 0; i < 100000; i++) { TestObserverEx to = new TestObserverEx<>(); Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(to); diff --git a/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectConcurrencyTest.java b/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectConcurrencyTest.java index ba4b5ee886..5403f8b43d 100644 --- a/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectConcurrencyTest.java +++ b/src/test/java/io/reactivex/rxjava4/subjects/ReplaySubjectConcurrencyTest.java @@ -294,7 +294,7 @@ public void run() { */ @Test public void raceForTerminalState() { - final List expected = Arrays.asList(1); + final List expected = List.of(1); for (int i = 0; i < 100000; i++) { TestObserverEx to = new TestObserverEx<>(); Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(to); diff --git a/src/test/java/io/reactivex/rxjava4/validators/NonNullMethodTypeArgumentCheck.java b/src/test/java/io/reactivex/rxjava4/validators/NonNullMethodTypeArgumentCheck.java index 64a05cb7cd..e370911dd4 100644 --- a/src/test/java/io/reactivex/rxjava4/validators/NonNullMethodTypeArgumentCheck.java +++ b/src/test/java/io/reactivex/rxjava4/validators/NonNullMethodTypeArgumentCheck.java @@ -106,7 +106,7 @@ static List parseTypeArguments(String line) { @Test public void parseTypeArguments() { - assertEquals(new ArrayList<>(Arrays.asList("T")), parseTypeArguments("")); + assertEquals(new ArrayList<>(List.of("T")), parseTypeArguments("")); assertEquals(new ArrayList<>(Arrays.asList("T", "U")), parseTypeArguments("")); assertEquals(new ArrayList<>(Arrays.asList("T", "Flowable")), parseTypeArguments(">")); assertEquals(new ArrayList<>(Arrays.asList("T", "Flowable")), parseTypeArguments(">"));