3434import rx .functions .Func2 ;
3535import rx .internal .operators .OnSubscribeCache ;
3636import rx .observers .TestObserver ;
37+ import rx .observers .TestSubscriber ;
3738import rx .schedulers .Schedulers ;
3839import rx .subjects .AsyncSubject ;
3940import rx .subjects .BehaviorSubject ;
@@ -93,7 +94,8 @@ public void call(String v) {
9394 }
9495 assertEquals (1 , counter .get ());
9596 }
96- void testWithCustomSubjectAndRepeat (Subject <Integer , Integer > subject , Integer ... expected ) {
97+
98+ private void testWithCustomSubjectAndRepeat (Subject <Integer , Integer > subject , Integer ... expected ) {
9799 Observable <Integer > source0 = Observable .from (1 , 2 , 3 )
98100 .subscribeOn (Schedulers .io ())
99101 .flatMap (new Func1 <Integer , Observable <Integer >>() {
@@ -107,62 +109,46 @@ public Integer call(Long t1) {
107109 });
108110 }
109111 });
110-
112+
111113 Observable <Integer > source1 = Observable .create (new OnSubscribeCache <Integer >(source0 , subject ));
112-
114+
113115 Observable <Integer > source2 = source1
114116 .repeat (4 )
115117 .zip (Observable .timer (0 , 10 , TimeUnit .MILLISECONDS , Schedulers .newThread ()), new Func2 <Integer , Long , Integer >() {
116118 @ Override
117119 public Integer call (Integer t1 , Long t2 ) {
118120 return t1 ;
119121 }
120-
121- });
122- final CountDownLatch cdl = new CountDownLatch (1 );
123- TestObserver <Integer > test = new TestObserver <Integer >(new Observer <Integer >() {
124- @ Override
125- public void onNext (Integer t ) {
126- }
127122
128- @ Override
129- public void onError (Throwable e ) {
130- cdl .countDown ();
131- }
132-
133- @ Override
134- public void onCompleted () {
135- cdl .countDown ();
136- }
137- });
138- source2 .subscribe (test );
123+ });
124+ TestSubscriber <Integer > ts = new TestSubscriber <Integer >();
125+ source2 .subscribe (ts );
139126
140- try {
141- cdl .await (20 , TimeUnit .SECONDS );
142- } catch (InterruptedException ex ) {
143- fail ("Interrupted" );
144- }
145-
146- test .assertReceivedOnNext (Arrays .asList (expected ));
147- test .assertTerminalEvent ();
148- assertTrue (test .getOnErrorEvents ().isEmpty ());
127+ ts .awaitTerminalEvent ();
128+ ts .assertNoErrors ();
129+ System .out .println (ts .getOnNextEvents ());
130+ ts .assertReceivedOnNext (Arrays .asList (expected ));
149131 }
132+
150133 @ Test (timeout = 10000 )
151134 public void testWithAsyncSubjectAndRepeat () {
152- testWithCustomSubjectAndRepeat (AsyncSubject .<Integer >create (), 3 , 3 , 3 , 3 );
135+ testWithCustomSubjectAndRepeat (AsyncSubject .<Integer > create (), 3 , 3 , 3 , 3 );
153136 }
137+
154138 @ Test (timeout = 10000 )
155139 public void testWithBehaviorSubjectAndRepeat () {
156140 // BehaviorSubject just completes when repeated
157141 testWithCustomSubjectAndRepeat (BehaviorSubject .create (0 ), 0 , 1 , 2 , 3 );
158142 }
143+
159144 @ Test (timeout = 10000 )
160145 public void testWithPublishSubjectAndRepeat () {
161146 // PublishSubject just completes when repeated
162- testWithCustomSubjectAndRepeat (PublishSubject .<Integer >create (), 1 , 2 , 3 );
147+ testWithCustomSubjectAndRepeat (PublishSubject .<Integer > create (), 1 , 2 , 3 );
163148 }
164- @ Test (timeout = 10000 )
149+
150+ @ Test
165151 public void testWithReplaySubjectAndRepeat () {
166- testWithCustomSubjectAndRepeat (ReplaySubject .<Integer >create (), 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 );
152+ testWithCustomSubjectAndRepeat (ReplaySubject .<Integer > create (), 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 );
167153 }
168154}
0 commit comments