Skip to content

Instantly share code, notes, and snippets.

@DariusL
Created June 13, 2016 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DariusL/95f4ea9d0a1ae69dd398a87b3ae00051 to your computer and use it in GitHub Desktop.
Save DariusL/95f4ea9d0a1ae69dd398a87b3ae00051 to your computer and use it in GitHub Desktop.
class HookTest {
@Test
fun testChangeHooks() {
val first = Hook()
RxJavaPlugins.getInstance().registerObservableExecutionHook(first)
Observable.just(null).subscribe { }
assertThat(first.invoked, `is`(true))
RxJavaPlugins.getInstance().reset()
val second = Hook()
RxJavaPlugins.getInstance().registerObservableExecutionHook(second)
Observable.just(null).subscribe { }
assertThat(second.invoked, `is`(true))
}
class Hook : RxJavaObservableExecutionHook() {
@Volatile
var invoked = false
override fun <T : Any?> onSubscribeStart(observableInstance: Observable<out T>?, onSubscribe: Observable.OnSubscribe<T>?): Observable.OnSubscribe<T>? {
invoked = true
return super.onSubscribeStart(observableInstance, onSubscribe)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment