daily pastebin goal
96%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import io.reactivex.observers.TestObserver
  2. import io.reactivex.subjects.PublishSubject
  3. import org.junit.Test
  4.  
  5. class StartWithPlaygroundTest {
  6.     private val intentSubject = PublishSubject.create<Pair<String, String>>()
  7.     private val apiSubject = PublishSubject.create<PartialRegisterChanges>()
  8.  
  9.     @Test
  10.     fun `startWith with ( ) braces`() {
  11.         val testObserver = TestObserver<PartialRegisterChanges>()
  12.  
  13.         intentSubject.flatMap {
  14.             apiSubject.startWith(PartialRegisterChanges.RegistrationInProgress)
  15.         }.subscribe(testObserver)
  16.  
  17.         intentSubject.onNext(Pair("login", "password"))
  18.         apiSubject.onNext(PartialRegisterChanges.RegistrationSuccess)
  19.  
  20.         testObserver.assertValueAt(0, PartialRegisterChanges.RegistrationInProgress)
  21.         testObserver.assertValueAt(1, PartialRegisterChanges.RegistrationSuccess)
  22.     }
  23.  
  24.     @Test
  25.     fun `startWith with { } braces`() {
  26.         val testObserver = TestObserver<PartialRegisterChanges>()
  27.  
  28.         intentSubject.flatMap {
  29.             apiSubject.startWith { PartialRegisterChanges.RegistrationInProgress }
  30.         }.subscribe(testObserver)
  31.  
  32.         intentSubject.onNext(Pair("login", "password"))
  33.         apiSubject.onNext(PartialRegisterChanges.RegistrationSuccess)
  34.  
  35.         testObserver.assertValueAt(0, PartialRegisterChanges.RegistrationInProgress)
  36.         testObserver.assertValueAt(1, PartialRegisterChanges.RegistrationSuccess)
  37.     }
  38. }
  39.  
  40. sealed class PartialRegisterChanges {
  41.     object RegistrationInProgress : PartialRegisterChanges()
  42.     object RegistrationSuccess : PartialRegisterChanges()
  43. }
RAW Paste Data
Top