forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnitTest confirming compilation failure without super/extends and suc…
…cess with them. - only testing zip operator at this time
- Loading branch information
1 parent
6b9867c
commit 6bd2033
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package rx; | ||
|
||
import org.junit.Test; | ||
|
||
import rx.util.functions.Action1; | ||
import rx.util.functions.Func2; | ||
|
||
/** | ||
* Test super/extends of generics. | ||
* | ||
* See https://github.com/Netflix/RxJava/pull/331 | ||
*/ | ||
public class CovarianceTest { | ||
|
||
/** | ||
* This won't compile if super/extends isn't done correctly on generics | ||
*/ | ||
@Test | ||
public void testCovarianceOfZip() { | ||
Observable<HorrorMovie> horrors = Observable.from(new HorrorMovie()); | ||
Observable<CoolRating> ratings = Observable.from(new CoolRating()); | ||
|
||
Func2<Media, Rating, ExtendedResult> combine = new Func2<Media, Rating, ExtendedResult>() { | ||
@Override | ||
public ExtendedResult call(Media m, Rating r) { | ||
return new ExtendedResult(); | ||
} | ||
}; | ||
|
||
Observable.<Result, Movie, CoolRating> zip(horrors, ratings, combine).toBlockingObservable().forEach(new Action1<Result>() { | ||
|
||
@Override | ||
public void call(Result t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
|
||
}); | ||
|
||
Observable.<Result, Movie, CoolRating> zip(horrors, ratings, combine).toBlockingObservable().forEach(new Action1<Result>() { | ||
|
||
@Override | ||
public void call(Result t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
|
||
}); | ||
|
||
Observable.<ExtendedResult, Media, Rating> zip(horrors, ratings, combine).toBlockingObservable().forEach(new Action1<ExtendedResult>() { | ||
|
||
@Override | ||
public void call(ExtendedResult t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
|
||
}); | ||
|
||
Observable.<Result, Media, Rating> zip(horrors, ratings, combine).toBlockingObservable().forEach(new Action1<Result>() { | ||
|
||
@Override | ||
public void call(Result t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
|
||
}); | ||
|
||
Observable.<ExtendedResult, Media, Rating> zip(horrors, ratings, combine).toBlockingObservable().forEach(new Action1<Result>() { | ||
|
||
@Override | ||
public void call(Result t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
|
||
}); | ||
|
||
Observable.<Result, Movie, CoolRating> zip(horrors, ratings, combine); | ||
|
||
} | ||
|
||
static class Media { | ||
} | ||
|
||
static class Movie extends Media { | ||
} | ||
|
||
static class HorrorMovie extends Movie { | ||
} | ||
|
||
static class Rating { | ||
} | ||
|
||
static class CoolRating extends Rating { | ||
} | ||
|
||
static class Result { | ||
} | ||
|
||
static class ExtendedResult extends Result { | ||
} | ||
} |