Last active
May 14, 2021 14:15
-
-
Save WendyYanto/c2126a65bdf7746b74f331e346ede479 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 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