Use Maybe instead of 0 when can't get lucky number (#7)
This commit is contained in:
parent
0b675978a9
commit
038763a968
2 changed files with 6 additions and 4 deletions
|
@ -1,12 +1,14 @@
|
|||
package io.github.wulkanowy.api.repository
|
||||
|
||||
import io.github.wulkanowy.api.service.HomepageService
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.Maybe
|
||||
|
||||
class HomepageRepository(private val api: HomepageService) {
|
||||
|
||||
fun getLuckyNumber(): Single<Int> {
|
||||
return api.getLuckyNumber().map { it.luckyNumer }
|
||||
fun getLuckyNumber(): Maybe<Int> {
|
||||
return api.getLuckyNumber()
|
||||
.map { it.luckyNumer }
|
||||
.filter { it != 0 }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class LuckyNumberTest : BaseLocalTest() {
|
|||
server.enqueue(MockResponse().setBody(LuckyNumberTest::class.java.getResource("Index-withoutLuckyNumber.html").readText()))
|
||||
server.start(3000)
|
||||
|
||||
assertEquals(0, api.getLuckyNumber().blockingGet())
|
||||
assertEquals(null, api.getLuckyNumber().blockingGet())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue