@@ -30,21 +30,15 @@ trait ResultChecker:
30
30
overrides
31
31
.map {
32
32
case TestOverride (Some (k), Exists , _) =>
33
- val matches = result.exists(_.key == k)
34
- if ! matches then
35
- println(s " !!! $k did NOT exist in $result" )
36
- matches
33
+ checkExistsInResult(result, k)
37
34
case TestOverride (Some (k), NotExists , _) =>
38
35
val matches = ! result.exists(_.key == k)
39
36
if ! matches then
40
37
println(s " !!! $k did EXIST in $result" )
41
38
matches
42
39
case TestOverride (Some (k), IsEquals , Some (v)) =>
43
40
val r = result.find(_.key == k)
44
- val matches = r.nonEmpty && r.exists(_.value == v)
45
- if ! matches then
46
- println(s " !!! $v ( $k) is NOT equal in $r" )
47
- matches
41
+ checkExistsInResult(result, k) && checkIsEqualValue(k, v, r.get.value)
48
42
case TestOverride (Some (k), HasSize , Some (value)) =>
49
43
val r = result.find(_.key == k)
50
44
val matches = r.exists {
@@ -176,16 +170,7 @@ trait ResultChecker:
176
170
val expectedJson = toJson(expectedValue.value.toString)
177
171
checkJson(expectedJson, resultJson, key)
178
172
case CamundaProperty (_, cValue) =>
179
- val matches : Boolean = cValue.value == expectedValue.value
180
- if ! matches then
181
- println(
182
- s " <<< cValue: ${cValue.getClass} / expectedValue ${expectedValue.getClass}"
183
- )
184
- println(
185
- s " !!! The expected value ' $expectedValue' of $key does not match the result variable ' ${cValue}'. \n $result"
186
- )
187
- end if
188
- matches
173
+ checkIsEqualValue(key, expectedValue, cValue)
189
174
}
190
175
.getOrElse {
191
176
println(
@@ -198,6 +183,47 @@ trait ResultChecker:
198
183
199
184
end checkP
200
185
186
+ private def checkExistsInResult (result : Seq [CamundaProperty ], key : String ) =
187
+ val matches = result.exists(_.key == key)
188
+ if ! matches then
189
+ println(s " !!! $key did NOT exist in $result" )
190
+ matches
191
+
192
+ private def checkIsEqualValue [T <: Product ](
193
+ key : String ,
194
+ expectedValue : CamundaVariable ,
195
+ resultValue : CamundaVariable
196
+ ) =
197
+ val matches : Boolean = resultValue.value == expectedValue.value
198
+ if ! matches then
199
+ if resultValue.getClass != expectedValue.getClass then
200
+ println(
201
+ s """ !!! The type of $key is different:
202
+ | - expected: ${expectedValue.getClass}
203
+ | - result : ${resultValue.getClass}""" .stripMargin
204
+ )
205
+ else
206
+ println(
207
+ s """ !!! The value of $key is different:
208
+ | - expected: ${expectedValue.value}
209
+ | - result : ${resultValue.value}""" .stripMargin
210
+ )
211
+ if expectedValue.value.toString.contains(" \n " ) then // compare each line for complex strings
212
+ val result = resultValue.value.toString.split(" \n " )
213
+ val expected = expectedValue.value.toString.split(" \n " )
214
+ result.zip(expected).foreach:
215
+ case (r, e) =>
216
+ if r != e then
217
+ println(
218
+ s """ >>> Bad Line:
219
+ | - expected: ' $e'
220
+ | - result : ' $r' """ .stripMargin
221
+ )
222
+ end if
223
+ end if
224
+ matches
225
+ end checkIsEqualValue
226
+
201
227
private def checkJson (
202
228
expectedJson : io.circe.Json ,
203
229
resultJson : io.circe.Json ,
0 commit comments