Skip to content

Commit

Permalink
Simplify toValueMapWorksAsExpected test assertions (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
veyndan authored Oct 16, 2023
1 parent bdc2188 commit 9be0922
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import assertk.assertThat
import assertk.assertions.containsOnly
import assertk.assertions.corresponds
import assertk.assertions.hasSize
import assertk.assertions.isEqualTo
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotNull
import kotlin.test.Test
import kotlin.test.assertTrue
import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonPrimitive

Expand All @@ -31,17 +34,17 @@ class StateSnapshotTest {
fun toValueMapWorksAsExpected() {
val stateSnapshot = stateSnapshot()
val valuesMap = stateSnapshot.toValuesMap()
assertThat(valuesMap.entries.size).isEqualTo(5)
assertTrue(valuesMap["key1"]!![0] is MutableState<*>)
assertThat((valuesMap["key1"]!![0] as MutableState<*>).value).isEqualTo(1.0)

assertThat(valuesMap).hasSize(5)
assertThat(valuesMap["key1"]!![0])
.isNotNull()
.isInstanceOf<MutableState<*>>()
.corresponds(mutableStateOf(1.0), ::mutableStateCorrespondence)
assertThat(valuesMap["key2"]).isEqualTo(listOf(1.0))

assertThat(valuesMap["key3"]!![0] is MutableState<*>)
assertThat((valuesMap["key3"]!![0] as MutableState<*>).value).isEqualTo("str")

assertThat(valuesMap["key3"]!![0])
.isNotNull()
.isInstanceOf<MutableState<*>>()
.corresponds(mutableStateOf("str"), ::mutableStateCorrespondence)
assertThat(valuesMap["key4"]).isEqualTo(listOf("str"))

assertThat(valuesMap["key5"]).isEqualTo(listOf(null))
}

Expand Down Expand Up @@ -76,3 +79,10 @@ class StateSnapshotTest {
"key5" to listOf(null),
)
}

private fun mutableStateCorrespondence(
actual: MutableState<*>,
expected: MutableState<*>,
): Boolean {
return actual.value == expected.value
}

0 comments on commit 9be0922

Please sign in to comment.