From ab19ef1948fa8dec3039a17cca04002654bd8a93 Mon Sep 17 00:00:00 2001 From: Jan Seeger Date: Tue, 12 Mar 2024 11:09:19 +0100 Subject: [PATCH] Add disabled Subclass decoding tests --- .../realtimedb/SubclassDecodingTests.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 realtimedb/src/test/kotlin/de/sipgate/federmappe/realtimedb/SubclassDecodingTests.kt diff --git a/realtimedb/src/test/kotlin/de/sipgate/federmappe/realtimedb/SubclassDecodingTests.kt b/realtimedb/src/test/kotlin/de/sipgate/federmappe/realtimedb/SubclassDecodingTests.kt new file mode 100644 index 0000000..af1c09c --- /dev/null +++ b/realtimedb/src/test/kotlin/de/sipgate/federmappe/realtimedb/SubclassDecodingTests.kt @@ -0,0 +1,51 @@ +package de.sipgate.federmappe.realtimedb + +import com.google.firebase.database.DataSnapshot +import io.mockk.every +import io.mockk.mockk +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.Serializable +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertInstanceOf +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +@Disabled +@OptIn(ExperimentalSerializationApi::class) +class SubclassDecodingTests { + + @Serializable + data class A(val b: String) + + @Test + fun nestedDataStructureDecodingTest() { + @Serializable + data class TestClass(val a: A) + + val bPropertyMock = mockk { + every { value } returns "Some String" + every { key } returns "b" + every { children } returns emptyList() + } + + val aPropertyMock = mockk { + every { value } returns null + every { key } returns "a" + every { children } returns emptyList() + } + + val testClassMock = mockk { + every { key } returns null + every { value } returns null + every { children } returns listOf(aPropertyMock) + every { child("a") } returns aPropertyMock + } + + val result = testClassMock.toObjectWithSerializer(TestClass.serializer()) + + assertInstanceOf(TestClass::class.java, result) + assertNotNull(result.a) + assertEquals("Some String", result.a.b) + } +}