|
|
|
@ -21,17 +21,13 @@ import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
|
|
|
|
|
|
import io.reactivex.Flowable; |
|
|
|
|
|
|
|
import io.reactivex.Maybe; |
|
|
|
|
|
|
|
import kotlinx.coroutines.Deferred; |
|
|
|
import kotlinx.coroutines.Deferred; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.Nested; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.FluxProcessor; |
|
|
|
import reactor.core.publisher.FluxProcessor; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import rx.Completable; |
|
|
|
|
|
|
|
import rx.Observable; |
|
|
|
|
|
|
|
import rx.Single; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
|
|
|
|
@ -45,35 +41,6 @@ class ReactiveAdapterRegistryTests { |
|
|
|
private final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); |
|
|
|
private final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void defaultAdapterRegistrations() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reactor
|
|
|
|
|
|
|
|
assertThat(getAdapter(Mono.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(Flux.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Publisher
|
|
|
|
|
|
|
|
assertThat(getAdapter(Publisher.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Completable
|
|
|
|
|
|
|
|
assertThat(getAdapter(CompletableFuture.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RxJava 1
|
|
|
|
|
|
|
|
assertThat(getAdapter(Observable.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(Single.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(Completable.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RxJava 2
|
|
|
|
|
|
|
|
assertThat(getAdapter(Flowable.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Observable.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Single.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(Maybe.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Completable.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Coroutines
|
|
|
|
|
|
|
|
assertThat(getAdapter(Deferred.class)).isNotNull(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void getAdapterForReactiveSubType() { |
|
|
|
void getAdapterForReactiveSubType() { |
|
|
|
|
|
|
|
|
|
|
|
@ -93,192 +60,301 @@ class ReactiveAdapterRegistryTests { |
|
|
|
assertThat(adapter3).isNotSameAs(adapter1); |
|
|
|
assertThat(adapter3).isNotSameAs(adapter1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Nested |
|
|
|
void publisherToFlux() { |
|
|
|
class Reactor { |
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Publisher<Integer> source = Flowable.fromIterable(sequence); |
|
|
|
@Test |
|
|
|
Object target = getAdapter(Flux.class).fromPublisher(source); |
|
|
|
void defaultAdapterRegistrations() { |
|
|
|
boolean condition = target instanceof Flux; |
|
|
|
|
|
|
|
assertThat(condition).isTrue(); |
|
|
|
// Reactor
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
assertThat(getAdapter(Mono.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(Flux.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Publisher
|
|
|
|
|
|
|
|
assertThat(getAdapter(Publisher.class)).isNotNull(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Completable
|
|
|
|
|
|
|
|
assertThat(getAdapter(CompletableFuture.class)).isNotNull(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toFlux() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(Flux.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Flux).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toMono() { |
|
|
|
|
|
|
|
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromArray(1, 2, 3); |
|
|
|
|
|
|
|
Object target = getAdapter(Mono.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toCompletableFuture() throws Exception { |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3}); |
|
|
|
|
|
|
|
Object target = getAdapter(CompletableFuture.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof CompletableFuture).isTrue(); |
|
|
|
|
|
|
|
assertThat(((CompletableFuture<Integer>) target).get()).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromCompletableFuture() { |
|
|
|
|
|
|
|
CompletableFuture<Integer> future = new CompletableFuture<>(); |
|
|
|
|
|
|
|
future.complete(1); |
|
|
|
|
|
|
|
Object target = getAdapter(CompletableFuture.class).toPublisher(future); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: publisherToMono/CompletableFuture vs Single (ISE on multiple elements)?
|
|
|
|
@Nested |
|
|
|
|
|
|
|
class RxJava1 { |
|
|
|
@Test |
|
|
|
|
|
|
|
void publisherToMono() { |
|
|
|
@Test |
|
|
|
Publisher<Integer> source = Flowable.fromArray(1, 2, 3); |
|
|
|
void defaultAdapterRegistrations() { |
|
|
|
Object target = getAdapter(Mono.class).fromPublisher(source); |
|
|
|
assertThat(getAdapter(rx.Observable.class)).isNotNull(); |
|
|
|
boolean condition = target instanceof Mono; |
|
|
|
assertThat(getAdapter(rx.Single.class)).isNotNull(); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(getAdapter(rx.Completable.class)).isNotNull(); |
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toObservable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Observable.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof rx.Observable).isTrue(); |
|
|
|
|
|
|
|
assertThat(((rx.Observable<?>) target).toList().toBlocking().first()).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toSingle() { |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1}); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Single.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof rx.Single).isTrue(); |
|
|
|
|
|
|
|
assertThat(((rx.Single<Integer>) target).toBlocking().value()).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toCompletable() { |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3}); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Completable.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof rx.Completable).isTrue(); |
|
|
|
|
|
|
|
assertThat(((rx.Completable) target).get()).isNull(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromObservable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = rx.Observable.from(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Observable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromSingle() { |
|
|
|
|
|
|
|
Object source = rx.Single.just(1); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Single.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromCompletable() { |
|
|
|
|
|
|
|
Object source = rx.Completable.complete(); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Completable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
((Mono<Void>) target).block(Duration.ofMillis(1000)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Nested |
|
|
|
void publisherToCompletableFuture() throws Exception { |
|
|
|
class RxJava2 { |
|
|
|
Publisher<Integer> source = Flowable.fromArray(1, 2, 3); |
|
|
|
|
|
|
|
Object target = getAdapter(CompletableFuture.class).fromPublisher(source); |
|
|
|
@Test |
|
|
|
boolean condition = target instanceof CompletableFuture; |
|
|
|
void defaultAdapterRegistrations() { |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
assertThat(((CompletableFuture<Integer>) target).get()).isEqualTo(Integer.valueOf(1)); |
|
|
|
// RxJava 2
|
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Flowable.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Observable.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Single.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Maybe.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Completable.class)).isNotNull(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toFlowable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Flowable.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof io.reactivex.Flowable).isTrue(); |
|
|
|
|
|
|
|
assertThat(((io.reactivex.Flowable<?>) target).toList().blockingGet()).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toObservable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Observable.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof io.reactivex.Observable).isTrue(); |
|
|
|
|
|
|
|
assertThat(((io.reactivex.Observable<?>) target).toList().blockingGet()).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toSingle() { |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1}); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Single.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof io.reactivex.Single).isTrue(); |
|
|
|
|
|
|
|
assertThat(((io.reactivex.Single<Integer>) target).blockingGet()).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void toCompletable() { |
|
|
|
|
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3}); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Completable.class).fromPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof io.reactivex.Completable).isTrue(); |
|
|
|
|
|
|
|
((io.reactivex.Completable) target).blockingAwait(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromFlowable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = io.reactivex.Flowable.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Flowable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromObservable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = io.reactivex.Observable.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Observable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromSingle() { |
|
|
|
|
|
|
|
Object source = io.reactivex.Single.just(1); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Single.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromCompletable() { |
|
|
|
|
|
|
|
Object source = io.reactivex.Completable.complete(); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Completable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
((Mono<Void>) target).block(Duration.ofMillis(1000)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Nested |
|
|
|
void publisherToRxObservable() { |
|
|
|
class RxJava3 { |
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Publisher<Integer> source = Flowable.fromIterable(sequence); |
|
|
|
@Test |
|
|
|
Object target = getAdapter(rx.Observable.class).fromPublisher(source); |
|
|
|
void defaultAdapterRegistrations() { |
|
|
|
boolean condition = target instanceof Observable; |
|
|
|
|
|
|
|
assertThat(condition).isTrue(); |
|
|
|
// RxJava 3
|
|
|
|
assertThat(((Observable<?>) target).toList().toBlocking().first()).isEqualTo(sequence); |
|
|
|
assertThat(getAdapter(io.reactivex.rxjava3.core.Flowable.class)).isNotNull(); |
|
|
|
} |
|
|
|
assertThat(getAdapter(io.reactivex.rxjava3.core.Observable.class)).isNotNull(); |
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.rxjava3.core.Single.class)).isNotNull(); |
|
|
|
@Test |
|
|
|
assertThat(getAdapter(io.reactivex.rxjava3.core.Maybe.class)).isNotNull(); |
|
|
|
void publisherToRxSingle() { |
|
|
|
assertThat(getAdapter(io.reactivex.rxjava3.core.Completable.class)).isNotNull(); |
|
|
|
Publisher<Integer> source = Flowable.fromArray(1); |
|
|
|
} |
|
|
|
Object target = getAdapter(rx.Single.class).fromPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Single; |
|
|
|
@Test |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
void toFlowable() { |
|
|
|
assertThat(((Single<Integer>) target).toBlocking().value()).isEqualTo(Integer.valueOf(1)); |
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
} |
|
|
|
Publisher<Integer> source = Flux.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Flowable.class).fromPublisher(source); |
|
|
|
@Test |
|
|
|
assertThat(target instanceof io.reactivex.rxjava3.core.Flowable).isTrue(); |
|
|
|
void publisherToRxCompletable() { |
|
|
|
assertThat(((io.reactivex.rxjava3.core.Flowable<?>) target).toList().blockingGet()).isEqualTo(sequence); |
|
|
|
Publisher<Integer> source = Flowable.fromArray(1, 2, 3); |
|
|
|
} |
|
|
|
Object target = getAdapter(rx.Completable.class).fromPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Completable; |
|
|
|
@Test |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
void toObservable() { |
|
|
|
assertThat(((Completable) target).get()).isNull(); |
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
} |
|
|
|
Publisher<Integer> source = Flux.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Observable.class).fromPublisher(source); |
|
|
|
@Test |
|
|
|
assertThat(target instanceof io.reactivex.rxjava3.core.Observable).isTrue(); |
|
|
|
void publisherToReactivexFlowable() { |
|
|
|
assertThat(((io.reactivex.rxjava3.core.Observable<?>) target).toList().blockingGet()).isEqualTo(sequence); |
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
} |
|
|
|
Publisher<Integer> source = Flux.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Flowable.class).fromPublisher(source); |
|
|
|
@Test |
|
|
|
boolean condition = target instanceof Flowable; |
|
|
|
void toSingle() { |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1}); |
|
|
|
assertThat(((Flowable<?>) target).toList().blockingGet()).isEqualTo(sequence); |
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Single.class).fromPublisher(source); |
|
|
|
} |
|
|
|
assertThat(target instanceof io.reactivex.rxjava3.core.Single).isTrue(); |
|
|
|
|
|
|
|
assertThat(((io.reactivex.rxjava3.core.Single<Integer>) target).blockingGet()).isEqualTo(Integer.valueOf(1)); |
|
|
|
@Test |
|
|
|
} |
|
|
|
void publisherToReactivexObservable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
@Test |
|
|
|
Publisher<Integer> source = Flowable.fromIterable(sequence); |
|
|
|
void toCompletable() { |
|
|
|
Object target = getAdapter(io.reactivex.Observable.class).fromPublisher(source); |
|
|
|
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3}); |
|
|
|
boolean condition = target instanceof io.reactivex.Observable; |
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Completable.class).fromPublisher(source); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(target instanceof io.reactivex.rxjava3.core.Completable).isTrue(); |
|
|
|
assertThat(((io.reactivex.Observable<?>) target).toList().blockingGet()).isEqualTo(sequence); |
|
|
|
((io.reactivex.rxjava3.core.Completable) target).blockingAwait(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void publisherToReactivexSingle() { |
|
|
|
void fromFlowable() { |
|
|
|
Publisher<Integer> source = Flowable.fromArray(1); |
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
Object target = getAdapter(io.reactivex.Single.class).fromPublisher(source); |
|
|
|
Object source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence); |
|
|
|
boolean condition = target instanceof io.reactivex.Single; |
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Flowable.class).toPublisher(source); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
assertThat(((io.reactivex.Single<Integer>) target).blockingGet()).isEqualTo(Integer.valueOf(1)); |
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromObservable() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = io.reactivex.rxjava3.core.Observable.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Observable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromSingle() { |
|
|
|
|
|
|
|
Object source = io.reactivex.rxjava3.core.Single.just(1); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Single.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void fromCompletable() { |
|
|
|
|
|
|
|
Object source = io.reactivex.rxjava3.core.Completable.complete(); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.rxjava3.core.Completable.class).toPublisher(source); |
|
|
|
|
|
|
|
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
((Mono<Void>) target).block(Duration.ofMillis(1000)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Nested |
|
|
|
void publisherToReactivexCompletable() { |
|
|
|
class Kotlin { |
|
|
|
Publisher<Integer> source = Flowable.fromArray(1, 2, 3); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Completable.class).fromPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof io.reactivex.Completable; |
|
|
|
|
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
((io.reactivex.Completable) target).blockingAwait(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void rxObservableToPublisher() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = rx.Observable.from(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Observable.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Flux; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void rxSingleToPublisher() { |
|
|
|
|
|
|
|
Object source = rx.Single.just(1); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Single.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Mono; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void rxCompletableToPublisher() { |
|
|
|
|
|
|
|
Object source = rx.Completable.complete(); |
|
|
|
|
|
|
|
Object target = getAdapter(rx.Completable.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Mono; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
((Mono<Void>) target).block(Duration.ofMillis(1000)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void reactivexFlowableToPublisher() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = io.reactivex.Flowable.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Flowable.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Flux; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void reactivexObservableToPublisher() { |
|
|
|
|
|
|
|
List<Integer> sequence = Arrays.asList(1, 2, 3); |
|
|
|
|
|
|
|
Object source = io.reactivex.Observable.fromIterable(sequence); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Observable.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Flux; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000))).isEqualTo(sequence); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void reactivexSingleToPublisher() { |
|
|
|
|
|
|
|
Object source = io.reactivex.Single.just(1); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Single.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Mono; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void reactivexCompletableToPublisher() { |
|
|
|
|
|
|
|
Object source = io.reactivex.Completable.complete(); |
|
|
|
|
|
|
|
Object target = getAdapter(io.reactivex.Completable.class).toPublisher(source); |
|
|
|
|
|
|
|
boolean condition = target instanceof Mono; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
((Mono<Void>) target).block(Duration.ofMillis(1000)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void completableFutureToPublisher() { |
|
|
|
|
|
|
|
CompletableFuture<Integer> future = new CompletableFuture<>(); |
|
|
|
|
|
|
|
future.complete(1); |
|
|
|
|
|
|
|
Object target = getAdapter(CompletableFuture.class).toPublisher(future); |
|
|
|
|
|
|
|
boolean condition = target instanceof Mono; |
|
|
|
|
|
|
|
assertThat(condition).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue(); |
|
|
|
|
|
|
|
assertThat(((Mono<Integer>) target).block(Duration.ofMillis(1000))).isEqualTo(Integer.valueOf(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void deferred() { |
|
|
|
|
|
|
|
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isEqualTo(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(getAdapter(Mono.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
@Test |
|
|
|
assertThat(getAdapter(Flux.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
void defaultAdapterRegistrations() { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(getAdapter(io.reactivex.Completable.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
// Coroutines
|
|
|
|
assertThat(getAdapter(io.reactivex.Single.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
assertThat(getAdapter(Deferred.class)).isNotNull(); |
|
|
|
assertThat(getAdapter(io.reactivex.Flowable.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
} |
|
|
|
assertThat(getAdapter(io.reactivex.Observable.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
@Test |
|
|
|
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
void deferred() { |
|
|
|
|
|
|
|
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isEqualTo(false); |
|
|
|
|
|
|
|
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
|
|
|
|
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isEqualTo(true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ReactiveAdapter getAdapter(Class<?> reactiveType) { |
|
|
|
private ReactiveAdapter getAdapter(Class<?> reactiveType) { |
|
|
|
|