Add valueUpdatesOnly tests

This commit is contained in:
Kirill Kamakin
2022-11-05 11:44:14 +01:00
parent d873bfa2ed
commit 2027f6ac60

View File

@@ -0,0 +1,42 @@
package gq.kirmanak.mealient.extensions
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.runTest
import org.junit.Test
@OptIn(ExperimentalCoroutinesApi::class)
class FlowExtensionsKtTest {
@Test
fun `when flow has an update then valueUpdatesOnly sends updated value`() = runTest {
val flow = flowOf(1, 2)
assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2))
}
@Test
fun `when flow has repeated values then valueUpdatesOnly sends updated value`() = runTest {
val flow = flowOf(1, 1, 1, 2)
assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2))
}
@Test
fun `when flow has one value then valueUpdatesOnly is empty`() = runTest {
val flow = flowOf(1)
assertThat(flow.valueUpdatesOnly().toList()).isEmpty()
}
@Test
fun `when flow has two updates then valueUpdatesOnly sends both`() = runTest {
val flow = flowOf(1, 2, 1)
assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2, 1))
}
@Test
fun `when flow has three updates then valueUpdatesOnly sends all`() = runTest {
val flow = flowOf(1, 2, 1, 3)
assertThat(flow.valueUpdatesOnly().toList()).isEqualTo(listOf(2, 1, 3))
}
}