@@ -3,14 +3,16 @@ package xyz.xenondevs.cbf.adapter.impl
3
3
import org.junit.jupiter.api.Test
4
4
import xyz.xenondevs.cbf.Compound
5
5
import xyz.xenondevs.cbf.adapter.BinaryAdapterTest
6
+ import xyz.xenondevs.cbf.entry
7
+ import xyz.xenondevs.commons.provider.defaultsToLazily
6
8
import xyz.xenondevs.commons.provider.observed
7
9
import xyz.xenondevs.commons.provider.orElseNew
8
10
import kotlin.test.assertEquals
9
11
10
12
class CompoundBinaryAdapterTest : BinaryAdapterTest <Compound >(Compound .CompoundBinaryAdapter ) {
11
13
12
14
@Test
13
- fun testDirectValues () {
15
+ fun `test direct values` () {
14
16
val compound = Compound ()
15
17
compound[" a" ] = " a"
16
18
compound[" b" ] = 2
@@ -22,7 +24,7 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
22
24
}
23
25
24
26
@Test
25
- fun testProviderValues () {
27
+ fun `test provider values` () {
26
28
val compound = Compound ()
27
29
compound.entry<String >(" a" ).set(" a" )
28
30
compound.entry<Int >(" b" ).set(2 )
@@ -34,7 +36,7 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
34
36
}
35
37
36
38
@Test
37
- fun testCollectionProviderValues () {
39
+ fun `test collection provider values` () {
38
40
val compound = Compound ()
39
41
val mapEntry = compound.entry<MutableMap <String , Int >>(" map" )
40
42
.orElseNew {
@@ -55,7 +57,7 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
55
57
}
56
58
57
59
@Test
58
- fun testMixedValues () {
60
+ fun `test mixed values` () {
59
61
val compound = Compound ()
60
62
compound[" a" ] = " a"
61
63
compound.entry<Int >(" b" ).set(2 )
@@ -72,4 +74,38 @@ class CompoundBinaryAdapterTest : BinaryAdapterTest<Compound>(Compound.CompoundB
72
74
assertEquals(5 , reserializedCompound.get<Int >(" d" ))
73
75
}
74
76
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
+
75
111
}
0 commit comments