mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-10-06 09:25:08 +00:00
35 lines
1.1 KiB
Kotlin
35 lines
1.1 KiB
Kotlin
|
import dev.inmo.micro_utils.coroutines.SpecialMutableStateFlow
|
||
|
import dev.inmo.micro_utils.coroutines.subscribe
|
||
|
import kotlinx.coroutines.Job
|
||
|
import kotlinx.coroutines.flow.first
|
||
|
import kotlinx.coroutines.test.runTest
|
||
|
import kotlin.test.Test
|
||
|
import kotlin.test.assertEquals
|
||
|
|
||
|
class SpecialMutableStateFlowTests {
|
||
|
@Test
|
||
|
fun simpleTest() {
|
||
|
val specialMutableStateFlow = SpecialMutableStateFlow(0)
|
||
|
runTest {
|
||
|
specialMutableStateFlow.value = 1
|
||
|
specialMutableStateFlow.first { it == 1 }
|
||
|
}
|
||
|
assertEquals(1, specialMutableStateFlow.value)
|
||
|
}
|
||
|
@Test
|
||
|
fun specialTest() {
|
||
|
val specialMutableStateFlow = SpecialMutableStateFlow(0)
|
||
|
runTest {
|
||
|
lateinit var subscriberJob: Job
|
||
|
subscriberJob = specialMutableStateFlow.subscribe(this) {
|
||
|
when (it) {
|
||
|
1 -> specialMutableStateFlow.value = 2
|
||
|
2 -> subscriberJob.cancel()
|
||
|
}
|
||
|
}
|
||
|
specialMutableStateFlow.value = 1
|
||
|
subscriberJob.join()
|
||
|
}
|
||
|
assertEquals(2, specialMutableStateFlow.value)
|
||
|
}
|
||
|
}
|