Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test("ConcatRecovered streams should contain mapped values from the original stream") {
- /*
- * 1, 2, 3, 4, 5
- *
- * And a request method:
- *
- * num => if (num != 4) Observable.just(num) else Observable.error(new Exception)
- *
- * We should, for example, get:
- *
- * Success(1), Success(2), Success(3), Failure(new Exception), Success(5)
- *
- *
- * Similarly:
- *
- * Observable(1, 2, 3).concatRecovered(num => Observable(num, num, num))
- *
- * should return:
- *
- * Observable(1, 1, 1, 2, 2, 2, 3, 3, 3)
- */
- val o1 = Observable(1, 2, 3, 4, 5)
- // Creates an observable with errors
- def error[T](error: Throwable): Observable[T] = {
- Observable(observer => {
- observer.onError(error)
- Subscription {}
- })
- }
- implicit def intToTry(v: Int) = Success(v)
- val ex = new Exception
- val x1 = o1.concatRecovered(num => if (num != 5) Observable(num) else error(ex))
- assert(x1.toBlockingObservable.toList === List(Success(1), Success(2), Success(3), Success(4), Failure(ex)))
- val x2 = o1.concatRecovered(num => if (num != 1) Observable(num) else error(ex))
- assert(x2.toBlockingObservable.toList === List(Failure(ex), Success(2), Success(3), Success(4), Success(5)))
- // assignment
- val x3 = o1.concatRecovered(num => if (num != 4) Observable(num) else error(ex))
- assert(x3.toBlockingObservable.toList === List(Success(1), Success(2), Success(3), Failure(ex), Success(5)))
- val o2 = Observable(1, 2, 3).concatRecovered(num => Observable(num, num, num))
- assert(o2.toBlockingObservable.toList === List[Try[Int]](1, 1, 1, 2, 2, 2, 3, 3, 3))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement