Skip to content

Commit df2bcc2

Browse files
committed
improve error logging for ignore-order assertions
1 parent 440a558 commit df2bcc2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

core/src/test/kotlin/org/neo4j/graphql/utils/CypherTestSuite.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,22 @@ class CypherTestSuite(fileName: String, val driver: Driver? = null, createMissin
527527

528528
private fun assertEqualIgnoreOrder(expected: Any?, actual: Any?) {
529529
when (expected) {
530-
is Map<*, *> -> Assertions.assertThat(actual).asInstanceOf(InstanceOfAssertFactories.MAP)
531-
.hasSize(expected.size)
532-
.containsOnlyKeys(*expected.keys.toTypedArray())
533-
.satisfies(Consumer { it.forEach { (key, value) -> assertEqualIgnoreOrder(expected[key], value) } })
530+
is Map<*, *> -> {
531+
val mapAssert = Assertions.assertThat(actual).asInstanceOf(InstanceOfAssertFactories.MAP)
532+
.hasSize(expected.size)
533+
.containsOnlyKeys(*expected.keys.toTypedArray())
534+
expected.forEach { (key, value) ->
535+
mapAssert.extractingByKey(key)
536+
.satisfies(Consumer { assertEqualIgnoreOrder(value, (actual as Map<*, *>)[key]) })
537+
}
538+
}
534539

535540
is Collection<*> -> {
536541
val assertions: List<Consumer<Any>> =
537542
expected.map { e -> Consumer<Any> { a -> assertEqualIgnoreOrder(e, a) } }
538543
Assertions.assertThat(actual).asInstanceOf(InstanceOfAssertFactories.LIST)
539544
.hasSize(expected.size)
545+
.withFailMessage { "Expecting actual:\n ${actual}\n to satisfy\n ${expected}\n in any order." }
540546
.satisfiesExactlyInAnyOrder(*assertions.toTypedArray())
541547
}
542548

0 commit comments

Comments
 (0)