Skip to content

Instantly share code, notes, and snippets.

@WendyYanto
Last active May 14, 2021 14:15
Show Gist options
  • Save WendyYanto/c2126a65bdf7746b74f331e346ede479 to your computer and use it in GitHub Desktop.
Save WendyYanto/c2126a65bdf7746b74f331e346ede479 to your computer and use it in GitHub Desktop.
class RxJavaTest {
companion object {
private const val USER_ID = "USER_ID"
private const val NAME = "John Doe"
private const val AGE = 20
}
@Test
fun getUser() {
getUserId()
.flatMap(this::getUser)
.flatMap(this::saveUser)
.subscribe(::println)
}
private fun getUserId(): Observable<String> {
return Observable.fromCallable {
USER_ID
}
}
private fun getUser(id: String): Observable<User> {
val user = User(
id = id,
name = NAME,
age = AGE
)
return Observable.fromCallable { user }
}
private fun saveUser(user: User): Observable<User> {
// Perform save user data operations
return Observable.fromCallable { user }
}
}
data class User(
val id: String,
val name: String,
val age: Int
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment