Skip to content

Commit 437b85b

Browse files
committed
ProtoStructDecoderUnitTest.kt: add test for decoding unknown keys
1 parent c2f254b commit 437b85b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package com.google.firebase.dataconnect
1919

2020
import com.google.firebase.dataconnect.SerializationTestData.serializationTestDataAllTypes
2121
import com.google.firebase.dataconnect.SerializationTestData.withEmptyListOfUnitRecursive
22+
import com.google.firebase.dataconnect.testutil.property.arbitrary.dataConnect
23+
import com.google.firebase.dataconnect.testutil.property.arbitrary.twoValues
2224
import com.google.firebase.dataconnect.testutil.shouldContainWithNonAbuttingTextIgnoringCase
2325
import com.google.firebase.dataconnect.util.ProtoUtil.buildStructProto
2426
import com.google.firebase.dataconnect.util.ProtoUtil.decodeFromStruct
@@ -477,6 +479,21 @@ class ProtoStructDecoderUnitTest {
477479
}
478480
}
479481

482+
@Test
483+
fun `decodeFromStruct() ignores unknown struct keys`() = runTest {
484+
@Serializable data class TestData1(val value1: String, val value2: String)
485+
@Serializable data class TestData2(val value1: String)
486+
487+
val testData1Arb: Arb<TestData1> =
488+
Arb.twoValues(Arb.dataConnect.string()).map { (value1, value2) -> TestData1(value1, value2) }
489+
490+
checkAll(propTestConfig, testData1Arb) { testData1 ->
491+
val struct = encodeToStruct(testData1)
492+
val decodedTestData = decodeFromStruct<TestData2>(struct)
493+
decodedTestData shouldBe TestData2(testData1.value1)
494+
}
495+
}
496+
480497
@Test
481498
fun `decodeFromStruct() should throw SerializationException if attempting to decode an Int`() {
482499
assertDecodeFromStructThrowsIncorrectKindCase<Int>(

0 commit comments

Comments
 (0)