@@ -32,7 +32,16 @@ import org.scalatest.junit.JUnitSuite
32
32
import rx .lang .scala ._
33
33
import rx .lang .scala .schedulers ._
34
34
35
- // @Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
35
+ /**
36
+ * Demo how the different operators can be used. In Eclipse, you can right-click
37
+ * a test and choose "Run As" > "Scala JUnit Test".
38
+ *
39
+ * For each operator added to Observable.java, we add a little usage demo here.
40
+ * It does not need to test the functionality (that's already done by the tests in
41
+ * RxJava core), but it should demonstrate how it can be used, to make sure that
42
+ * the method signature makes sense.
43
+ */
44
+ @ Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
36
45
class RxScalaDemo extends JUnitSuite {
37
46
38
47
@ Test def intervalExample () {
@@ -251,30 +260,36 @@ class RxScalaDemo extends JUnitSuite {
251
260
}
252
261
253
262
@ Test def combineLatestExample () {
254
- val first_counter = Observable .interval(250 millis)
255
- val second_counter = Observable .interval(550 millis)
256
- val combined_counter = first_counter .combineLatest(second_counter ,
263
+ val firstCounter = Observable .interval(250 millis)
264
+ val secondCounter = Observable .interval(550 millis)
265
+ val combinedCounter = firstCounter .combineLatest(secondCounter ,
257
266
(x : Long , y : Long ) => List (x,y)) take 10
258
267
259
- combined_counter subscribe {x => println(s " Emitted group: $x" )}
268
+ combinedCounter subscribe {x => println(s " Emitted group: $x" )}
269
+ waitFor(combinedCounter)
260
270
}
261
271
272
+ @ Test def olympicsExampleWithoutPublish () {
273
+ val medals = Olympics .mountainBikeMedals.doOnEach(_ => println(" onNext" ))
274
+ medals.subscribe(println(_)) // triggers an execution of medals Observable
275
+ waitFor(medals) // triggers another execution of medals Observable
276
+ }
262
277
263
- @ Test def olympicsExample () {
264
- val medals = Olympics .mountainBikeMedals.publish
265
- medals.subscribe(println(_))
278
+ @ Test def olympicsExampleWithPublish () {
279
+ val medals = Olympics .mountainBikeMedals.doOnEach(_ => println( " onNext " )). publish
280
+ medals.subscribe(println(_)) // triggers an execution of medals Observable
266
281
medals.connect
267
- // waitFor(medals)
282
+ waitFor(medals) // triggers another execution of medals Observable
268
283
}
269
284
270
285
@ Test def exampleWithoutPublish () {
271
- val unshared = List (1 to 4 ).toObservable
286
+ val unshared = Observable .from (1 to 4 )
272
287
unshared.subscribe(n => println(s " subscriber 1 gets $n" ))
273
288
unshared.subscribe(n => println(s " subscriber 2 gets $n" ))
274
289
}
275
290
276
291
@ Test def exampleWithPublish () {
277
- val unshared = List (1 to 4 ).toObservable
292
+ val unshared = Observable .from (1 to 4 )
278
293
val shared = unshared.publish
279
294
shared.subscribe(n => println(s " subscriber 1 gets $n" ))
280
295
shared.subscribe(n => println(s " subscriber 2 gets $n" ))
@@ -403,7 +418,7 @@ class RxScalaDemo extends JUnitSuite {
403
418
}
404
419
405
420
@ Test def timestampExample () {
406
- val timestamped = Observable .interval(100 millis).take(3 ).timestamp.toBlockingObservable
421
+ val timestamped = Observable .interval(100 millis).take(6 ).timestamp.toBlockingObservable
407
422
for ((millis, value) <- timestamped if value > 0 ) {
408
423
println(value + " at t = " + millis)
409
424
}
@@ -442,15 +457,6 @@ class RxScalaDemo extends JUnitSuite {
442
457
val oc3 : rx.Notification [_ <: Int ] = oc2.asJavaNotification
443
458
val oc4 : rx.Notification [_ <: Any ] = oc2.asJavaNotification
444
459
}
445
-
446
- @ Test def elementAtReplacement () {
447
- assertEquals(" b" , List (" a" , " b" , " c" ).toObservable.drop(1 ).first.toBlockingObservable.single)
448
- }
449
-
450
- @ Test def elementAtOrDefaultReplacement () {
451
- assertEquals(" b" , List (" a" , " b" , " c" ).toObservable.drop(1 ).firstOrElse(" !" ).toBlockingObservable.single)
452
- assertEquals(" !!" , List (" a" , " b" , " c" ).toObservable.drop(10 ).firstOrElse(" !!" ).toBlockingObservable.single)
453
- }
454
460
455
461
@ Test def takeWhileWithIndexAlternative {
456
462
val condition = true
0 commit comments