-
Notifications
You must be signed in to change notification settings - Fork 11
Examples
Ruby Lichtenshtein edited this page Jan 2, 2018
·
9 revisions
Observable.just("Hello RxTest!")
.test {
it should complete()
}
PublishSubject.create<String>()
.test {
it should notComplete()
}
val assertionError = AssertionError()
PublishSubject.create<String>()
.apply {
onError(assertionError)
}
.test {
it shouldHave error(assertionError)
}
PublishSubject.create<String>()
.apply {
onError(AssertionError())
}
.test {
it shouldHave error(AssertionError::class.java)
}
val assertionError = AssertionError()
PublishSubject.create<String>()
.apply {
onError(assertionError)
}
.test {
it shouldHave error(Predicate { it == assertionError })
}
PublishSubject.create<String>()
.test {
it shouldHave noErrors()
}
val value = "a"
val obs = Observable.just(value)
obs.test {
it shouldHave value(value)
}
obs.test {
it shouldEmit value
}
val value = "a"
val obs = Observable.just(value)
obs.test {
it shouldHave value(Predicate { it == value })
}
obs.test {
it shouldEmit Predicate { it == value }
}
val obs = Observable.just("Hello", "RxTest")
obs.test {
it shouldEmit values("Hello", "RxTest")
}
obs.test {
it shouldEmit values("Hello", "RxTest")
}
val valueSequence = listOf("Hello", "RxTest")
val obs = Observable.fromIterable(valueSequence)
obs.test {
it shouldEmit valueSequence(valueSequence)
}
val valueSequence = listOf("Hello", "RxTest")
val obs = Observable.fromIterable(valueSequence)
obs.test {
it shouldEmit valueSet(valueSequence)
}
ReplaySubject.create<String>()
.also {
it.onNext("Hello")
it.onNext("Kotlin")
}
.test {
it shouldEmit valueOnly("Hello", "Kotlin")
}
Observable.just("Bloop")
.test {
it shouldHave valueCount(1)
}
val value = "a"
val never = "b"
val obs = Observable.just(value)
val valuePredicate = Predicate { v: String -> v == never }
obs.test {
it should never(never)
}
obs.test {
it shouldNeverEmit never
}
val value = "a"
val never = "b"
val obs = Observable.just(value)
val valuePredicate = Predicate { v: String -> v == never }
obs.test {
it should never(valuePredicate)
}
obs.test {
it shouldNeverEmit valuePredicate
}
val value0 = "a"
val value1 = "b"
val obs = Observable.just(value0, value1)
obs.test {
it shouldHave valueAt(0, value0)
it shouldHave valueAt(1, value1)
}
val value0 = "a"
val value1 = "b"
val obs = Observable.just(value0, value1)
obs.test {
it shouldHave valueAt(0, Predicate { value -> value == value0 })
it shouldHave valueAt(1, Predicate { value -> value == value1 })
}
PublishSubject.create<String>()
.test {
it shouldBe empty()
}
val scheduler = TestScheduler()
Observable
.interval(100, TimeUnit.MILLISECONDS, scheduler)
.test {
it.await(50, TimeUnit.MILLISECONDS)
it shouldHave timeout()
}
val scheduler = TestScheduler()
Observable
.interval(100, TimeUnit.MILLISECONDS, scheduler)
.test {
it shouldHave noTimeout()
}
Observable.just("Wabba Labba!")
.apply {
subscribe({ })
test {
it should subscribed()
}
}
TestObserver<String>()
.apply {
should(notSubscribed())
}
val value0 = "a"
val value1 = "b"
val errorMessage = "Error"
val error = Throwable(errorMessage)
val obs = ReplaySubject.create<String>()
.also {
it.onNext(value0)
it.onNext(value1)
it.onError(error)
}
obs.test {
it shouldHave failure(Predicate { true }, value0, value1)
}
val value0 = "a"
val value1 = "b"
val errorMessage = "Error"
val error = Throwable(errorMessage)
val obs = ReplaySubject.create<String>()
.also {
it.onNext(value0)
it.onNext(value1)
it.onError(error)
}
obs.test {
it shouldHave failure(Throwable::class.java, value0, value1)
}
val value0 = "a"
val value1 = "b"
val errorMessage = "Error"
val error = Throwable(errorMessage)
val obs = ReplaySubject.create<String>()
.also {
it.onNext(value0)
it.onNext(value1)
it.onError(error)
}
obs.test {
it shouldHave failureAndMessage(Throwable::class.java, errorMessage, value0, value1)
}
val value0 = "a"
val value1 = "b"
val values = listOf(value0, value1)
Observable.just(values)
.test {
it shouldHave result(values)
}
Observable.just(item0)
.test {
it should terminate()
}
Observable.error<String>(Throwable())
.test {
it should terminate()
}