@@ -118,8 +118,92 @@ internal class DslJsonBodyBuilderTest {
118
118
.isEqualTo(expectedBody.pactDslObject.toString())
119
119
}
120
120
121
+ @Test
122
+ internal fun `should map inner object multiple occurrences` () {
123
+ data class InnerObjectRequiredProperty (val property : String )
124
+ data class ObjectRequiredProperty (val inner : InnerObjectRequiredProperty ,
125
+ val second : InnerObjectRequiredProperty )
126
+
127
+ val actualJsonBody = LambdaDsl .newJsonBody(basedOnConstructor(ObjectRequiredProperty ::class ))
128
+
129
+ val expectedBody =
130
+ LambdaDsl .newJsonBody { root ->
131
+ root.`object `(" inner" ) {
132
+ it.stringType(" property" )
133
+ }
134
+ root.`object `(" second" ) {
135
+ it.stringType(" property" )
136
+ }
137
+ }
138
+
139
+ assertThat(actualJsonBody.pactDslObject.toString())
140
+ .isEqualTo(expectedBody.pactDslObject.toString())
141
+ }
142
+
143
+ data class InnerObjectRequiredProperty (val property : ObjectRequiredProperty )
144
+ data class ObjectRequiredProperty (val inner : InnerObjectRequiredProperty )
145
+ @Test
146
+ internal fun `should map inner object with loop reference for the first level` () {
147
+ val actualJsonBody = LambdaDsl .newJsonBody(basedOnConstructor(ObjectRequiredProperty ::class ))
148
+
149
+ val expectedBody =
150
+ LambdaDsl .newJsonBody { root ->
151
+ root.`object `(" inner" ) { it.`object `(" property" ) { } }
152
+ }
153
+
154
+ assertThat(actualJsonBody.pactDslObject.toString())
155
+ .isEqualTo(expectedBody.pactDslObject.toString())
156
+ }
157
+
158
+ data class ThirdProperty (val dependOnFirst : FirstProperty , val property : String )
159
+ data class SecondProperty (val third : ThirdProperty )
160
+ data class FirstProperty (val second : SecondProperty )
161
+ @Test
162
+ internal fun `should map inner object with loop reference keeping other fields` () {
163
+ val actualJsonBody = LambdaDsl .newJsonBody(basedOnConstructor(FirstProperty ::class ))
164
+
165
+ val expectedBody =
166
+ LambdaDsl .newJsonBody { root ->
167
+ root.`object `(" second" ) {
168
+ it.`object `(" third" ) { loop ->
169
+ loop.`object `(" dependOnFirst" ) { }
170
+ loop.stringType(" property" )
171
+ }
172
+ }
173
+ }
174
+
175
+ assertThat(actualJsonBody.pactDslObject.toString())
176
+ .isEqualTo(expectedBody.pactDslObject.toString())
177
+ }
178
+
179
+ @Test
180
+ internal fun `should map inner object reusing the same class internally` () {
181
+ data class CommonClass (val name : String )
182
+ data class ThirdToUseCommonProperty (val common : CommonClass )
183
+ data class SecondToUseCommonProperty (val third : ThirdToUseCommonProperty , val common : CommonClass )
184
+ data class FirstToUseCommonProperty (val second : SecondToUseCommonProperty )
185
+
186
+ val actualJsonBody = LambdaDsl .newJsonBody(basedOnConstructor(FirstToUseCommonProperty ::class ))
187
+
188
+ val expectedBody =
189
+ LambdaDsl .newJsonBody { root ->
190
+ root.`object `(" second" ) {
191
+ it.`object `(" third" ) { loop ->
192
+ loop.`object `(" common" ) { third -> third.stringType(" name" ) }
193
+ }
194
+ it.`object `(" common" ) { loop ->
195
+ loop.stringType(" name" )
196
+ }
197
+ }
198
+ }
199
+
200
+ assertThat(actualJsonBody.pactDslObject.toString())
201
+ .isEqualTo(expectedBody.pactDslObject.toString())
202
+ }
203
+
121
204
companion object {
122
205
@JvmStatic
206
+ @Suppress(" UnusedPrivateMember" )
123
207
private fun numberPropertyNonOptional (): Stream <KClass <* >> {
124
208
data class ByteObjectNonRequiredProperty (val property : Byte )
125
209
data class ShortObjectNonRequiredProperty (val property : Short )
@@ -141,6 +225,7 @@ internal class DslJsonBodyBuilderTest {
141
225
}
142
226
143
227
@JvmStatic
228
+ @Suppress(" UnusedPrivateMember" )
144
229
private fun stringPropertyOptionalProperties (): Stream <KClass <* >> {
145
230
data class StringObjectNonRequiredPropertyImmutable (val property : String = " " )
146
231
data class StringObjectNonRequiredPropertyMutable (var property : String = " " )
@@ -152,6 +237,7 @@ internal class DslJsonBodyBuilderTest {
152
237
}
153
238
154
239
@JvmStatic
240
+ @Suppress(" UnusedPrivateMember" )
155
241
private fun stringPropertyNonOptionalProperties (): Stream <KClass <* >> {
156
242
data class StringObjectRequiredPropertyImmutable (val property : String )
157
243
data class StringObjectRequiredPropertyMutable (var property : String )
0 commit comments