Advertisement
pellekrogholt

Untitled

Dec 9th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. test("ConcatRecovered streams should contain mapped values from the original stream") {
  2. /*
  3. * 1, 2, 3, 4, 5
  4. *
  5. * And a request method:
  6. *
  7. * num => if (num != 4) Observable.just(num) else Observable.error(new Exception)
  8. *
  9. * We should, for example, get:
  10. *
  11. * Success(1), Success(2), Success(3), Failure(new Exception), Success(5)
  12. *
  13. *
  14. * Similarly:
  15. *
  16. * Observable(1, 2, 3).concatRecovered(num => Observable(num, num, num))
  17. *
  18. * should return:
  19. *
  20. * Observable(1, 1, 1, 2, 2, 2, 3, 3, 3)
  21. */
  22. val o1 = Observable(1, 2, 3, 4, 5)
  23.  
  24. // Creates an observable with errors
  25. def error[T](error: Throwable): Observable[T] = {
  26. Observable(observer => {
  27. observer.onError(error)
  28. Subscription {}
  29. })
  30. }
  31.  
  32. implicit def intToTry(v: Int) = Success(v)
  33.  
  34. val ex = new Exception
  35.  
  36. val x1 = o1.concatRecovered(num => if (num != 5) Observable(num) else error(ex))
  37. assert(x1.toBlockingObservable.toList === List(Success(1), Success(2), Success(3), Success(4), Failure(ex)))
  38.  
  39. val x2 = o1.concatRecovered(num => if (num != 1) Observable(num) else error(ex))
  40. assert(x2.toBlockingObservable.toList === List(Failure(ex), Success(2), Success(3), Success(4), Success(5)))
  41.  
  42. // assignment
  43. val x3 = o1.concatRecovered(num => if (num != 4) Observable(num) else error(ex))
  44. assert(x3.toBlockingObservable.toList === List(Success(1), Success(2), Success(3), Failure(ex), Success(5)))
  45.  
  46. val o2 = Observable(1, 2, 3).concatRecovered(num => Observable(num, num, num))
  47. assert(o2.toBlockingObservable.toList === List[Try[Int]](1, 1, 1, 2, 2, 2, 3, 3, 3))
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement