Use Maybe instead of 0 when can't get lucky number (#7)

This commit is contained in:
Kacper Ziubryniewicz 2019-01-19 23:45:42 +01:00 committed by Mikołaj Pich
parent 0b675978a9
commit 038763a968
2 changed files with 6 additions and 4 deletions

View file

@ -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 }
}
}

View file

@ -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())
}
}