Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save talosdev/68a94c2e5cb02c54cce82148b434d0c7 to your computer and use it in GitHub Desktop.
Save talosdev/68a94c2e5cb02c54cce82148b434d0c7 to your computer and use it in GitHub Desktop.
private fun assertObservableToSingle(
sourceObservable: Observable<Int>,
toSingleTransformation: Observable<Int>.() -> Single<Int>,
assertions: TestObserver<Int>.() -> Unit
) {
val connectableObservable : ConnectableObservable<Int> = sourceObservable
.doOnNext { println("Source observable emitting $it") }
.doOnError { println("Source observable emitted an error: $it") }
.publish()
val testObserver = connectableObservable.toSingleTransformation()
.doOnSuccess { println("Single succeeded with value: $it") }
.doOnError { println("Single emitted an error: $it") }
.test()
connectableObservable.connect()
testObserver.await().assertions()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment