Skip to content

Commit 9683478

Browse files
Add more compound binary adapter tests
1 parent 6c35f35 commit 9683478

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

cosmic-binary-format/src/test/kotlin/xyz/xenondevs/cbf/adapter/impl/CompoundBinaryAdapterTest.kt

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package xyz.xenondevs.cbf.adapter.impl
33
import org.junit.jupiter.api.Test
44
import xyz.xenondevs.cbf.Compound
55
import xyz.xenondevs.cbf.adapter.BinaryAdapterTest
6+
import xyz.xenondevs.cbf.entry
7+
import xyz.xenondevs.commons.provider.defaultsToLazily
68
import xyz.xenondevs.commons.provider.observed
79
import xyz.xenondevs.commons.provider.orElseNew
810
import kotlin.test.assertEquals
911

1012
class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundBinaryAdapter) {
1113

1214
@Test
13-
fun testDirectValues() {
15+
fun `test direct values`() {
1416
val compound = Compound()
1517
compound["a"] = "a"
1618
compound["b"] = 2
@@ -22,7 +24,7 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
2224
}
2325

2426
@Test
25-
fun testProviderValues() {
27+
fun `test provider values`() {
2628
val compound = Compound()
2729
compound.entry<String>("a").set("a")
2830
compound.entry<Int>("b").set(2)
@@ -34,7 +36,7 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
3436
}
3537

3638
@Test
37-
fun testCollectionProviderValues() {
39+
fun `test collection provider values`() {
3840
val compound = Compound()
3941
val mapEntry = compound.entry<MutableMap<String, Int>>("map")
4042
.orElseNew {
@@ -55,7 +57,7 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
5557
}
5658

5759
@Test
58-
fun testMixedValues() {
60+
fun `test mixed values`() {
5961
val compound = Compound()
6062
compound["a"] = "a"
6163
compound.entry<Int>("b").set(2)
@@ -72,4 +74,38 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
7274
assertEquals(5, reserializedCompound.get<Int>("d"))
7375
}
7476

77+
@Test
78+
fun `test compound provider entry`() {
79+
val compound = Compound()
80+
val innerEntry = compound.entry<Compound>("compound")
81+
.defaultsToLazily(::Compound)
82+
83+
innerEntry.get()["a"] = "a"
84+
85+
val reserializedCompound = reserializeValue(compound)
86+
assertEquals("a", reserializedCompound.get<Compound>("compound")!!.get<String>("a"))
87+
88+
innerEntry.get()["a"] = "b"
89+
90+
val reserializedCompound2 = reserializeValue(compound)
91+
assertEquals("b", reserializedCompound2.get<Compound>("compound")!!.get<String>("a"))
92+
}
93+
94+
@Test
95+
fun `test compound provider entry that has observed list provider entry`() {
96+
val compound = Compound()
97+
98+
val provider = compound.entry<Compound>("compound")
99+
.defaultsToLazily(::Compound)
100+
.entry<MutableList<String>>("list")
101+
.orElseNew(::ArrayList)
102+
.observed()
103+
104+
provider.get() += "A"
105+
assertEquals(listOf("A"), reserializeValue(compound).get<Compound>("compound")!!.get<List<String>>("list"))
106+
107+
provider.get() += "B"
108+
assertEquals(listOf("A", "B"), reserializeValue(compound).get<Compound>("compound")!!.get<List<String>>("list"))
109+
}
110+
75111
}

0 commit comments

Comments
 (0)