|
15 | 15 | */
|
16 | 16 | package rx;
|
17 | 17 |
|
| 18 | +import static org.junit.Assert.*; |
| 19 | + |
| 20 | +import java.util.Collection; |
| 21 | +import java.util.Collections; |
18 | 22 | import java.util.HashMap;
|
19 | 23 | import java.util.Map;
|
20 | 24 |
|
|
31 | 35 | import rx.functions.Action1;
|
32 | 36 | import rx.functions.Func1;
|
33 | 37 | import rx.functions.Func2;
|
| 38 | +import rx.functions.FuncN; |
34 | 39 | import rx.observables.GroupedObservable;
|
35 | 40 |
|
36 | 41 | public class ZipTests {
|
@@ -91,6 +96,28 @@ public void testCovarianceOfZip() {
|
91 | 96 | Observable.<Movie, CoolRating, Result> zip(horrors, ratings, combine);
|
92 | 97 | }
|
93 | 98 |
|
| 99 | + /** |
| 100 | + * Occasionally zip may be invoked with 0 observables. This blocks indefinitely instead |
| 101 | + * of immediately invoking zip with 0 argument. |
| 102 | + */ |
| 103 | + @Test(timeout = 5000) |
| 104 | + public void nonBlockingObservable() { |
| 105 | + |
| 106 | + final Object invoked = new Object(); |
| 107 | + |
| 108 | + Collection<Observable<Object>> observables = Collections.emptyList(); |
| 109 | + |
| 110 | + Observable<Object> result = Observable.zip(observables, new FuncN<Object>() { |
| 111 | + @Override |
| 112 | + public Object call(final Object... args) { |
| 113 | + assertEquals("No argument should have been passed", 0, args.length); |
| 114 | + return invoked; |
| 115 | + } |
| 116 | + }); |
| 117 | + |
| 118 | + assertSame(invoked, result.toBlockingObservable().last()); |
| 119 | + } |
| 120 | + |
94 | 121 | Func2<Media, Rating, ExtendedResult> combine = new Func2<Media, Rating, ExtendedResult>() {
|
95 | 122 | @Override
|
96 | 123 | public ExtendedResult call(Media m, Rating r) {
|
|
0 commit comments