Skip to content

Commit 48aab50

Browse files
authored
dataconnect: modernize SerializationTestData.kt to use Arb instead of bespoke random data generation (#6339)
1 parent 2d3e414 commit 48aab50

File tree

3 files changed

+145
-197
lines changed

3 files changed

+145
-197
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 ->

0 commit comments

Comments
 (0)