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.
Merge pull request ReactiveX#363 from benjchristensen/reduce-covariance
unit tests for covariance
- Loading branch information
Showing
6 changed files
with
328 additions
and
188 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,53 @@ | ||
package rx; | ||
|
||
import org.junit.Test; | ||
|
||
import rx.CovarianceTest.CoolRating; | ||
import rx.CovarianceTest.ExtendedResult; | ||
import rx.CovarianceTest.HorrorMovie; | ||
import rx.CovarianceTest.Media; | ||
import rx.CovarianceTest.Movie; | ||
import rx.CovarianceTest.Rating; | ||
import rx.CovarianceTest.Result; | ||
import rx.util.functions.Action1; | ||
import rx.util.functions.Func2; | ||
|
||
public class CombineLatestTests { | ||
/** | ||
* This won't compile if super/extends isn't done correctly on generics | ||
*/ | ||
@Test | ||
public void testCovarianceOfCombineLatest() { | ||
Observable<HorrorMovie> horrors = Observable.from(new HorrorMovie()); | ||
Observable<CoolRating> ratings = Observable.from(new CoolRating()); | ||
|
||
Observable.<Movie, CoolRating, Result> combineLatest(horrors, ratings, combine).toBlockingObservable().forEach(action); | ||
Observable.<Movie, CoolRating, Result> combineLatest(horrors, ratings, combine).toBlockingObservable().forEach(action); | ||
Observable.<Media, Rating, ExtendedResult> combineLatest(horrors, ratings, combine).toBlockingObservable().forEach(extendedAction); | ||
Observable.<Media, Rating, Result> combineLatest(horrors, ratings, combine).toBlockingObservable().forEach(action); | ||
Observable.<Media, Rating, ExtendedResult> combineLatest(horrors, ratings, combine).toBlockingObservable().forEach(action); | ||
|
||
Observable.<Movie, CoolRating, Result> combineLatest(horrors, ratings, combine); | ||
} | ||
|
||
Func2<Media, Rating, ExtendedResult> combine = new Func2<Media, Rating, ExtendedResult>() { | ||
@Override | ||
public ExtendedResult call(Media m, Rating r) { | ||
return new ExtendedResult(); | ||
} | ||
}; | ||
|
||
Action1<Result> action = new Action1<Result>() { | ||
@Override | ||
public void call(Result t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
}; | ||
|
||
Action1<ExtendedResult> extendedAction = new Action1<ExtendedResult>() { | ||
@Override | ||
public void call(ExtendedResult t1) { | ||
System.out.println("Result: " + t1); | ||
} | ||
}; | ||
} |
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
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
Oops, something went wrong.