Created
June 13, 2016 16:50
-
-
Save DariusL/95f4ea9d0a1ae69dd398a87b3ae00051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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