Skip to content

Commit fc9c1dd

Browse files
committed
ProtoStructDecoderUnitTest.kt fixed to use the new Arb-based API in SerializationTestData.kt
1 parent cb4a27b commit fc9c1dd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

firebase-dataconnect/src/test/kotlin/com/google/firebase/dataconnect/ProtoStructDecoderUnitTest.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.google.firebase.dataconnect
1717

18+
import com.google.firebase.dataconnect.SerializationTestData.serializationTestDataAllTypes
19+
import com.google.firebase.dataconnect.SerializationTestData.withEmptyListOfUnitRecursive
1820
import com.google.firebase.dataconnect.testutil.shouldContainWithNonAbuttingTextIgnoringCase
1921
import com.google.firebase.dataconnect.util.ProtoUtil.buildStructProto
2022
import com.google.firebase.dataconnect.util.ProtoUtil.decodeFromStruct
@@ -31,9 +33,9 @@ import io.kotest.property.arbitrary.arbitrary
3133
import io.kotest.property.arbitrary.boolean
3234
import io.kotest.property.arbitrary.constant
3335
import io.kotest.property.arbitrary.double
34-
import io.kotest.property.arbitrary.filter
3536
import io.kotest.property.arbitrary.int
3637
import io.kotest.property.arbitrary.list
38+
import io.kotest.property.arbitrary.map
3739
import io.kotest.property.arbitrary.orNull
3840
import io.kotest.property.arbitrary.string
3941
import io.kotest.property.checkAll
@@ -47,17 +49,21 @@ class ProtoStructDecoderUnitTest {
4749

4850
@Test
4951
fun `decodeFromStruct() can encode and decode complex objects`() = runTest {
50-
val seeds = Arb.string().filter { it.hashCode() != 0 }
51-
checkAll(iterations = 20, seeds) { seed ->
52-
val obj = SerializationTestData.AllTheTypes.newInstance(seed).withEmptyUnitLists()
52+
// TODO(b/370992204) Remove the call to withEmptyListOfUnitRecursive() once the bug that a list
53+
// of Unit is incorrectly decoded as an empty list is fixed.
54+
val arb = Arb.serializationTestDataAllTypes().map { it.withEmptyListOfUnitRecursive() }
55+
checkAll(iterations = 20, arb) { obj ->
5356
val struct = encodeToStruct(obj)
5457
val decodedObj = decodeFromStruct<SerializationTestData.AllTheTypes>(struct)
5558
decodedObj shouldBe obj
5659
}
5760
}
5861

62+
@Ignore(
63+
"b/370992204: Re-enable this test once the bug that a list of Unit is incorrectly " +
64+
"decoded as an empty list is fixed"
65+
)
5966
@Test
60-
@Ignore("A List<Unit> gets decoded as an empty list; if anyone cares, fix it.")
6167
fun `decodeFromStruct() can encode and decode a list of non-nullable Unit`() = runTest {
6268
@Serializable data class TestData(val list: List<Unit>)
6369
checkAll(Arb.list(Arb.constant(Unit))) { list ->

firebase-dataconnect/src/test/kotlin/com/google/firebase/dataconnect/SerializationTestData.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ object SerializationTestData {
214214
* [Unit] to be empty. This may be useful if testing an encoder/decoder that does not support
215215
* [kotlinx.serialization.descriptors.StructureKind.OBJECT] in lists.
216216
*/
217-
fun AllTheTypes.withEmptyUnitLists(): SerializationTestData.AllTheTypes =
217+
fun AllTheTypes.withEmptyListOfUnitRecursive(): AllTheTypes =
218218
copy(
219219
listOfUnit = emptyList(),
220-
listOfNullableUnit = emptyList(),
221-
nested = nested?.withEmptyUnitLists()
220+
nested = nested?.withEmptyListOfUnitRecursive(),
222221
)
223222
}

0 commit comments

Comments
 (0)