Skip to content

Instantly share code, notes, and snippets.

@damien5314
Last active April 20, 2017 19:00
Show Gist options
  • Select an option

  • Save damien5314/b9f4d0cb3d8ad5e443b93b5ba8c214bc to your computer and use it in GitHub Desktop.

Select an option

Save damien5314/b9f4d0cb3d8ad5e443b93b5ba8c214bc to your computer and use it in GitHub Desktop.
package com
import io.reactivex.Observable
import org.junit.Assert.assertEquals
import org.junit.Test
class RxJavaTests {
@Test
fun foo1() { // fails, doOnDispose isn't called (Observable isn't disposed?)
var called = false
Observable.just(1)
.doOnNext { throw RuntimeException() }
.doOnDispose { called = true }
.test()
assertEquals(true, called)
}
@Test
fun foo2() { // passes
var called = false
Observable.just(1)
.doOnNext { throw RuntimeException() }
.doOnTerminate { called = true }
.test()
assertEquals(true, called)
}
@Test
fun foo3() { // passes
var called = false
Observable.just(1)
.doOnNext { throw RuntimeException() }
.doAfterTerminate { called = true }
.test()
assertEquals(true, called)
}
@Test
fun foo4() { // fails, doOnNext must come before doOnTerminate
var called = false
Observable.just(1)
.doOnTerminate { called = true }
.doOnNext { throw RuntimeException() }
.test()
assertEquals(true, called)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment