Skip to content

Commit

Permalink
cast operator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimate-deej committed Mar 1, 2016
1 parent febcbdd commit 102e40f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/kotlin/rx/lang/kotlin/ObservablesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,24 @@ class ObservablesTest {
val list = listOf(1,2,3,2,3,4,3,4,5)
assertEquals(list, list.map { it.toSingletonObservable() }.zip { it }.toBlocking().first())
}

@test fun testCast() {
val source = Observable.just<Any>(1, 2)
val observable = source.cast<Int>()
val subscriber = TestSubscriber<Int>()
observable.subscribe(subscriber)
subscriber.apply {
assertValues(1, 2)
assertNoErrors()
assertCompleted()
}
}

@test fun testCastWithWrongType() {
val source = Observable.just<Any>(1, 2)
val observable = source.cast<String>()
val subscriber = TestSubscriber<Any>()
observable.subscribe(subscriber)
subscriber.assertError(ClassCastException::class.java)
}
}

0 comments on commit 102e40f

Please sign in to comment.