1
1
package rx ;
2
2
3
- import static org .junit .Assert .*;
4
-
5
3
import java .util .ArrayList ;
6
- import java .util .List ;
7
4
8
5
import org .junit .Test ;
9
6
10
- import rx .Observable .OnSubscribeFunc ;
11
- import rx .subscriptions .Subscriptions ;
12
- import rx .util .functions .Action1 ;
13
- import rx .util .functions .Func2 ;
14
-
15
7
/**
16
8
* Test super/extends of generics.
17
9
*
@@ -29,187 +21,9 @@ public void testCovarianceOfFrom() {
29
21
// Observable.<HorrorMovie>from(new Movie()); // may not compile
30
22
}
31
23
32
- /**
33
- * This won't compile if super/extends isn't done correctly on generics
34
- */
35
- @ Test
36
- public void testCovarianceOfMerge () {
37
- Observable <HorrorMovie > horrors = Observable .from (new HorrorMovie ());
38
- Observable <Observable <HorrorMovie >> metaHorrors = Observable .just (horrors );
39
- Observable .<Media > merge (metaHorrors );
40
- }
41
-
42
- /**
43
- * This won't compile if super/extends isn't done correctly on generics
44
- */
45
- @ Test
46
- public void testCovarianceOfZip () {
47
- Observable <HorrorMovie > horrors = Observable .from (new HorrorMovie ());
48
- Observable <CoolRating > ratings = Observable .from (new CoolRating ());
49
-
50
- Observable .<Movie , CoolRating , Result > zip (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
51
- Observable .<Movie , CoolRating , Result > zip (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
52
- Observable .<Media , Rating , ExtendedResult > zip (horrors , ratings , combine ).toBlockingObservable ().forEach (extendedAction );
53
- Observable .<Media , Rating , Result > zip (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
54
- Observable .<Media , Rating , ExtendedResult > zip (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
55
-
56
- Observable .<Movie , CoolRating , Result > zip (horrors , ratings , combine );
57
- }
58
-
59
- /**
60
- * This won't compile if super/extends isn't done correctly on generics
24
+ /*
25
+ * Most tests are moved into their applicable classes such as [Operator]Tests.java
61
26
*/
62
- @ Test
63
- public void testCovarianceOfCombineLatest () {
64
- Observable <HorrorMovie > horrors = Observable .from (new HorrorMovie ());
65
- Observable <CoolRating > ratings = Observable .from (new CoolRating ());
66
-
67
- Observable .<Movie , CoolRating , Result > combineLatest (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
68
- Observable .<Movie , CoolRating , Result > combineLatest (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
69
- Observable .<Media , Rating , ExtendedResult > combineLatest (horrors , ratings , combine ).toBlockingObservable ().forEach (extendedAction );
70
- Observable .<Media , Rating , Result > combineLatest (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
71
- Observable .<Media , Rating , ExtendedResult > combineLatest (horrors , ratings , combine ).toBlockingObservable ().forEach (action );
72
-
73
- Observable .<Movie , CoolRating , Result > combineLatest (horrors , ratings , combine );
74
- }
75
-
76
- @ Test
77
- public void testConcatCovariance () {
78
- Observable <Media > o1 = Observable .<Media > from (new HorrorMovie (), new Movie ());
79
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
80
-
81
- Observable <Observable <Media >> os = Observable .from (o1 , o2 );
82
-
83
- List <Media > values = Observable .concat (os ).toList ().toBlockingObservable ().single ();
84
- }
85
-
86
- @ Test
87
- public void testConcatCovariance2 () {
88
- Observable <Media > o1 = Observable .from (new HorrorMovie (), new Movie (), new Media ());
89
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
90
-
91
- Observable <Observable <Media >> os = Observable .from (o1 , o2 );
92
-
93
- List <Media > values = Observable .concat (os ).toList ().toBlockingObservable ().single ();
94
- }
95
-
96
- @ Test
97
- public void testConcatCovariance3 () {
98
- Observable <Movie > o1 = Observable .from (new HorrorMovie (), new Movie ());
99
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
100
-
101
- List <Media > values = Observable .concat (o1 , o2 ).toList ().toBlockingObservable ().single ();
102
-
103
- assertTrue (values .get (0 ) instanceof HorrorMovie );
104
- assertTrue (values .get (1 ) instanceof Movie );
105
- assertTrue (values .get (2 ) instanceof Media );
106
- assertTrue (values .get (3 ) instanceof HorrorMovie );
107
- }
108
-
109
- @ Test
110
- public void testConcatCovariance4 () {
111
-
112
- Observable <Movie > o1 = Observable .create (new OnSubscribeFunc <Movie >() {
113
-
114
- @ Override
115
- public Subscription onSubscribe (Observer <? super Movie > o ) {
116
- o .onNext (new HorrorMovie ());
117
- o .onNext (new Movie ());
118
- // o.onNext(new Media()); // correctly doesn't compile
119
- o .onCompleted ();
120
- return Subscriptions .empty ();
121
- }
122
- });
123
-
124
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
125
-
126
- List <Media > values = Observable .concat (o1 , o2 ).toList ().toBlockingObservable ().single ();
127
-
128
- assertTrue (values .get (0 ) instanceof HorrorMovie );
129
- assertTrue (values .get (1 ) instanceof Movie );
130
- assertTrue (values .get (2 ) instanceof Media );
131
- assertTrue (values .get (3 ) instanceof HorrorMovie );
132
- }
133
-
134
-
135
- @ Test
136
- public void testMergeCovariance () {
137
- Observable <Media > o1 = Observable .<Media > from (new HorrorMovie (), new Movie ());
138
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
139
-
140
- Observable <Observable <Media >> os = Observable .from (o1 , o2 );
141
-
142
- List <Media > values = Observable .merge (os ).toList ().toBlockingObservable ().single ();
143
- }
144
-
145
- @ Test
146
- public void testMergeCovariance2 () {
147
- Observable <Media > o1 = Observable .from (new HorrorMovie (), new Movie (), new Media ());
148
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
149
-
150
- Observable <Observable <Media >> os = Observable .from (o1 , o2 );
151
-
152
- List <Media > values = Observable .merge (os ).toList ().toBlockingObservable ().single ();
153
- }
154
-
155
- @ Test
156
- public void testMergeCovariance3 () {
157
- Observable <Movie > o1 = Observable .from (new HorrorMovie (), new Movie ());
158
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
159
-
160
- List <Media > values = Observable .merge (o1 , o2 ).toList ().toBlockingObservable ().single ();
161
-
162
- assertTrue (values .get (0 ) instanceof HorrorMovie );
163
- assertTrue (values .get (1 ) instanceof Movie );
164
- assertTrue (values .get (2 ) instanceof Media );
165
- assertTrue (values .get (3 ) instanceof HorrorMovie );
166
- }
167
-
168
- @ Test
169
- public void testMergeCovariance4 () {
170
-
171
- Observable <Movie > o1 = Observable .create (new OnSubscribeFunc <Movie >() {
172
-
173
- @ Override
174
- public Subscription onSubscribe (Observer <? super Movie > o ) {
175
- o .onNext (new HorrorMovie ());
176
- o .onNext (new Movie ());
177
- // o.onNext(new Media()); // correctly doesn't compile
178
- o .onCompleted ();
179
- return Subscriptions .empty ();
180
- }
181
- });
182
-
183
- Observable <Media > o2 = Observable .from (new Media (), new HorrorMovie ());
184
-
185
- List <Media > values = Observable .merge (o1 , o2 ).toList ().toBlockingObservable ().single ();
186
-
187
- assertTrue (values .get (0 ) instanceof HorrorMovie );
188
- assertTrue (values .get (1 ) instanceof Movie );
189
- assertTrue (values .get (2 ) instanceof Media );
190
- assertTrue (values .get (3 ) instanceof HorrorMovie );
191
- }
192
-
193
- Func2 <Media , Rating , ExtendedResult > combine = new Func2 <Media , Rating , ExtendedResult >() {
194
- @ Override
195
- public ExtendedResult call (Media m , Rating r ) {
196
- return new ExtendedResult ();
197
- }
198
- };
199
-
200
- Action1 <Result > action = new Action1 <Result >() {
201
- @ Override
202
- public void call (Result t1 ) {
203
- System .out .println ("Result: " + t1 );
204
- }
205
- };
206
-
207
- Action1 <ExtendedResult > extendedAction = new Action1 <ExtendedResult >() {
208
- @ Override
209
- public void call (ExtendedResult t1 ) {
210
- System .out .println ("Result: " + t1 );
211
- }
212
- };
213
27
214
28
static class Media {
215
29
}
0 commit comments