Skip to content

Commit b14cdb0

Browse files
committed
Improved result comparison of multiline strings.
1 parent a4cadcc commit b14cdb0

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

03-simulation/src/main/scala/camundala/simulation/ResultChecker.scala

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,15 @@ trait ResultChecker:
3030
overrides
3131
.map {
3232
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)
3734
case TestOverride(Some(k), NotExists, _) =>
3835
val matches = !result.exists(_.key == k)
3936
if !matches then
4037
println(s"!!! $k did EXIST in $result")
4138
matches
4239
case TestOverride(Some(k), IsEquals, Some(v)) =>
4340
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)
4842
case TestOverride(Some(k), HasSize, Some(value)) =>
4943
val r = result.find(_.key == k)
5044
val matches = r.exists {
@@ -176,16 +170,7 @@ trait ResultChecker:
176170
val expectedJson = toJson(expectedValue.value.toString)
177171
checkJson(expectedJson, resultJson, key)
178172
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)
189174
}
190175
.getOrElse {
191176
println(
@@ -198,6 +183,47 @@ trait ResultChecker:
198183

199184
end checkP
200185

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+
201227
private def checkJson(
202228
expectedJson: io.circe.Json,
203229
resultJson: io.circe.Json,

0 commit comments

Comments
 (0)