Skip to content

Commit 3143874

Browse files
examples to examples, tests to tests
1 parent 2130684 commit 3143874

File tree

4 files changed

+103
-100
lines changed

4 files changed

+103
-100
lines changed

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/examples/RxJavaDemos.scala renamed to language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@
1515
*/
1616
package rx.lang.scala.examples
1717

18-
import org.scalatest.junit.JUnitSuite
19-
import rx.lang.scala._
20-
import scala.concurrent.duration._
18+
import java.io.IOException
19+
20+
import scala.concurrent.duration.Duration
21+
import scala.concurrent.duration.DurationInt
22+
import scala.concurrent.duration.DurationLong
23+
import scala.language.postfixOps
24+
25+
import org.junit.Assert.assertEquals
26+
import org.junit.Assert.assertTrue
27+
import org.junit.Ignore
2128
import org.junit.Test
22-
import org.junit.Assert._
29+
import org.scalatest.junit.JUnitSuite
30+
31+
import rx.lang.scala.Notification
32+
import rx.lang.scala.Observable
33+
import rx.lang.scala.observable
2334
import rx.lang.scala.concurrency.Schedulers
24-
import java.io.IOException
25-
import rx.lang.scala.examples.Olympics
26-
import rx.lang.scala.Notification.OnCompleted
27-
import rx.lang.scala.Notification.OnError
28-
import rx.lang.scala.Notification.OnNext
29-
import org.scalatest.Ignore
3035

3136
@Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
3237
class RxScalaDemo extends JUnitSuite {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package rx.lang.scala
2+
3+
import org.junit.{ Ignore, Assert, Test }
4+
import org.scalatest.junit.JUnitSuite
5+
6+
class ObservableTests extends JUnitSuite {
7+
8+
// Tests which needn't be run:
9+
10+
@Ignore
11+
def testCovariance = {
12+
//println("hey, you shouldn't run this test")
13+
14+
val o1: Observable[Nothing] = Observable()
15+
val o2: Observable[Int] = o1
16+
val o3: Observable[App] = o1
17+
val o4: Observable[Any] = o2
18+
val o5: Observable[Any] = o3
19+
}
20+
21+
// Tests which have to be run:
22+
23+
@Test
24+
def testDematerialize() {
25+
val o = Observable(1, 2, 3)
26+
val mat = o.materialize
27+
val demat = mat.dematerialize
28+
29+
// correctly rejected:
30+
//val wrongDemat = Observable("hello").dematerialize
31+
32+
Assert.assertEquals(demat.toBlockingObservable.toIterable.toList, List(1, 2, 3))
33+
}
34+
35+
// Test that Java's firstOrDefault propagates errors.
36+
// If this changes (i.e. it suppresses errors and returns default) then Scala's firstOrElse
37+
// should be changed accordingly.
38+
@Test def testJavaFirstOrDefault() {
39+
Assert.assertEquals(1, rx.Observable.from(1, 2).firstOrDefault(10).toBlockingObservable().single)
40+
Assert.assertEquals(10, rx.Observable.empty().firstOrDefault(10).toBlockingObservable().single)
41+
val msg = "msg6251"
42+
var receivedMsg = "none"
43+
try {
44+
rx.Observable.error(new Exception(msg)).firstOrDefault(10).toBlockingObservable().single
45+
} catch {
46+
case e: Exception => receivedMsg = e.getCause().getMessage()
47+
}
48+
Assert.assertEquals(receivedMsg, msg)
49+
}
50+
51+
@Test def testFirstOrElse() {
52+
def mustNotBeCalled: String = sys.error("this method should not be called")
53+
def mustBeCalled: String = "this is the default value"
54+
Assert.assertEquals("hello", Observable("hello").firstOrElse(mustNotBeCalled).toBlockingObservable.single)
55+
Assert.assertEquals("this is the default value", Observable().firstOrElse(mustBeCalled).toBlockingObservable.single)
56+
}
57+
58+
@Test def testFirstOrElseWithError() {
59+
val msg = "msg6251"
60+
var receivedMsg = "none"
61+
try {
62+
Observable[Int](new Exception(msg)).firstOrElse(10).toBlockingObservable.single
63+
} catch {
64+
case e: Exception => receivedMsg = e.getCause().getMessage()
65+
}
66+
Assert.assertEquals(receivedMsg, msg)
67+
}
68+
69+
/*
70+
@Test def testHead() {
71+
val observer = mock(classOf[Observer[Int]])
72+
val o = Observable().head
73+
val sub = o.subscribe(observer)
74+
75+
verify(observer, never).onNext(any(classOf[Int]))
76+
verify(observer, never).onCompleted()
77+
verify(observer, times(1)).onError(any(classOf[NoSuchElementException]))
78+
}
79+
*/
80+
81+
@Test def testTest() = {
82+
val a: Observable[Int] = Observable()
83+
Assert.assertEquals(4, Observable(1, 2, 3, 4).toBlockingObservable.toIterable.last)
84+
//println("This UnitTestSuite.testTest() for rx.lang.scala.Observable")
85+
}
86+
87+
}

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/examples/UnitTestSuite.scala

Lines changed: 0 additions & 88 deletions
This file was deleted.

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/examples/SubscriptionTests.scala renamed to language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/subscriptions/SubscriptionTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package rx.lang.scala.examples
1+
package rx.lang.scala.subscriptions
22

33
import org.junit.{Assert, Test}
44
import org.scalatest.junit.JUnitSuite
5-
import rx.lang.scala.subscriptions.{MultipleAssignmentSubscription, CompositeSubscription, BooleanSubscription, Subscription}
65

76
class SubscriptionTests extends JUnitSuite {
87

0 commit comments

Comments
 (0)