diff --git a/base/src/test/kotlin/com/motorro/rxlcemodel/base/LceUtilsKtTest.kt b/base/src/test/kotlin/com/motorro/rxlcemodel/base/LceUtilsKtTest.kt index fa988ea7..87b1cdca 100644 --- a/base/src/test/kotlin/com/motorro/rxlcemodel/base/LceUtilsKtTest.kt +++ b/base/src/test/kotlin/com/motorro/rxlcemodel/base/LceUtilsKtTest.kt @@ -16,6 +16,8 @@ package com.motorro.rxlcemodel.base import io.reactivex.Completable import io.reactivex.Observable import io.reactivex.Single +import io.reactivex.subjects.BehaviorSubject +import io.reactivex.subjects.PublishSubject import org.junit.Test import java.io.IOException @@ -224,6 +226,35 @@ class LceUtilsKtTest { ) } + + @Test + fun createsRefreshingStream() { + val value1 = LceState.Content(1, true) + val value2 = LceState.Content(2, true) + val refreshStream = PublishSubject.create() + val model = object : LceModel { + val stateSubject = BehaviorSubject.createDefault>(value1) + var refreshed = false + + override val state: Observable> = stateSubject + override val refresh: Completable = Completable.fromAction { + refreshed = true + stateSubject.onNext(value2) + } + override val params: String = PARAMS + } + + val observer = model.withRefresh(refreshStream).test() + observer.assertNotComplete() + observer.assertNoErrors() + observer.assertValues(value1) + + refreshStream.onNext(1) + observer.assertNotComplete() + observer.assertNoErrors() + observer.assertValues(value1, value2) + } + @Test fun substitutesEmptyLoading() { val original = LceState.Loading(null, false)