[Test] Sort failed exceptions in JUnit5Assertions.assertAll

This is needed to throw FileComparisonFailure first, because idea
  test UI can not show multiple diff windows for multiple assertions
  and shows only first, which is not useful
This commit is contained in:
Dmitriy Novozhilov
2021-05-11 17:01:48 +03:00
committed by TeamCityServer
parent 2530ae6b3d
commit 1407af6301
@@ -54,7 +54,7 @@ object JUnit5Assertions : AssertionsService() {
override fun assertAll(exceptions: List<Throwable>) {
exceptions.singleOrNull()?.let { throw it }
JUnit5PlatformAssertions.assertAll(exceptions.map { Executable { throw it } })
JUnit5PlatformAssertions.assertAll(exceptions.sortedWith(FileComparisonFailureFirst).map { Executable { throw it } })
}
override fun assertNotNull(value: Any?, message: (() -> String)?) {
@@ -68,4 +68,10 @@ object JUnit5Assertions : AssertionsService() {
override fun fail(message: () -> String): Nothing {
org.junit.jupiter.api.fail(message)
}
private object FileComparisonFailureFirst : Comparator<Throwable> {
override fun compare(o1: Throwable?, o2: Throwable?): Int {
return if (o1 is FileComparisonFailure) -1 else 0
}
}
}