Skip to content

Commit

Permalink
Add disabled Subclass decoding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Mar 12, 2024
1 parent 2dc45cf commit ab19ef1
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<DataSnapshot> {
every { value } returns "Some String"
every { key } returns "b"
every { children } returns emptyList()
}

val aPropertyMock = mockk<DataSnapshot> {
every { value } returns null
every { key } returns "a"
every { children } returns emptyList()
}

val testClassMock = mockk<DataSnapshot> {
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)
}
}

0 comments on commit ab19ef1

Please sign in to comment.