Debian Codegraph @

src/test/java/io/reactivex/rxjava3/flowable/FlowableMergeTests.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.flowable;
15
16 import static org.junit.Assert.*;
17
18 import java.util.List;
19
20 import org.junit.Test;
21 import org.reactivestreams.Publisher;
22
23 import io.reactivex.rxjava3.core.*;
24 import io.reactivex.rxjava3.flowable.FlowableCovarianceTest.*;
25 import io.reactivex.rxjava3.functions.Supplier;
26
27 public class FlowableMergeTests extends RxJavaTest {
28
29 /**
30 * This won't compile if super/extends isn't done correctly on generics.
31 */
32 @Test
33 public void covarianceOfMerge() {
34 Flowable<HorrorMovie> horrors = Flowable.just(new HorrorMovie());
35 Flowable<Flowable<HorrorMovie>> metaHorrors = Flowable.just(horrors);
36 Flowable.<Media> merge(metaHorrors);
37 }
38
39 @Test
40 public void mergeCovariance() {
41 Flowable<Media> f1 = Flowable.<Media> just(new HorrorMovie(), new Movie());
42 Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie());
43
44 Flowable<Flowable<Media>> os = Flowable.just(f1, f2);
45
46 List<Media> values = Flowable.merge(os).toList().blockingGet();
47
48 assertEquals(4, values.size());
49 }
50
51 @Test
52 public void mergeCovariance2() {
53 Flowable<Media> f1 = Flowable.just(new HorrorMovie(), new Movie(), new Media());
54 Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie());
55
56 Flowable<Flowable<Media>> os = Flowable.just(f1, f2);
57
58 List<Media> values = Flowable.merge(os).toList().blockingGet();
59
60 assertEquals(5, values.size());
61 }
62
63 @Test
64 public void mergeCovariance3() {
65 Flowable<Movie> f1 = Flowable.just(new HorrorMovie(), new Movie());
66 Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie());
67
68 List<Media> values = Flowable.merge(f1, f2).toList().blockingGet();
69
70 assertTrue(values.get(0) instanceof HorrorMovie);
71 assertTrue(values.get(1) instanceof Movie);
72 assertNotNull(values.get(2));
73 assertTrue(values.get(3) instanceof HorrorMovie);
74 }
75
76 @Test
77 public void mergeCovariance4() {
78
79 Flowable<Movie> f1 = Flowable.defer(new Supplier<Publisher<Movie>>() {
80 @Override
81 public Publisher<Movie> get() {
82 return Flowable.just(
83 new HorrorMovie(),
84 new Movie()
85 );
86 }
87 });
88
89 Flowable<Media> f2 = Flowable.just(new Media(), new HorrorMovie());
90
91 List<Media> values = Flowable.merge(f1, f2).toList().blockingGet();
92
93 assertTrue(values.get(0) instanceof HorrorMovie);
94 assertTrue(values.get(1) instanceof Movie);
95 assertNotNull(values.get(2));
96 assertTrue(values.get(3) instanceof HorrorMovie);
97 }
98
99 }