diff --git a/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt b/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt index 625a5c2339..1e352e010a 100644 --- a/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt +++ b/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt @@ -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 @@ -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>() + .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>() + .corresponds(mutableStateOf("str"), ::mutableStateCorrespondence) assertThat(valuesMap["key4"]).isEqualTo(listOf("str")) - assertThat(valuesMap["key5"]).isEqualTo(listOf(null)) } @@ -76,3 +79,10 @@ class StateSnapshotTest { "key5" to listOf(null), ) } + +private fun mutableStateCorrespondence( + actual: MutableState<*>, + expected: MutableState<*>, +): Boolean { + return actual.value == expected.value +}