Skip to content

Instantly share code, notes, and snippets.

@v3n3
Created April 4, 2018 15:55
Show Gist options
  • Save v3n3/167b0ecd9733001c4ce7b027ca43f933 to your computer and use it in GitHub Desktop.
Save v3n3/167b0ecd9733001c4ce7b027ca43f933 to your computer and use it in GitHub Desktop.
val testPublisher = PublishSubject.create<String>()
var value:String = "initial"
fun myRxFunction(ioThread:Scheduler,mainThread:Scheduler){
testPublisher
.subscribeOn(ioThread)
.observeOn(mainThread)
.subscribe{
saveString(it)
}
}
fun saveString(message:String){
value = message
}
@Test
fun myRxFunctionTest(){
val testString = "test"
val testScheduler = TestScheduler()
myRxFunction(testScheduler,testScheduler)
testScheduler.triggerActions()
testPublisher.onNext(testString)
assertEquals(value,testString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment