-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disabled Subclass decoding tests
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
realtimedb/src/test/kotlin/de/sipgate/federmappe/realtimedb/SubclassDecodingTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |