Fix compilation of JUnit4Assertions after change in kotlin repo

Assertions now has one more abstract method. I tried to stop reusing
Assertions from kotlin repo, but aparently JUnit4Assertions is used for
testing JPS in different environments (see MockLibraryUtilExt) and I
won't shave this yak

GitOrigin-RevId: 8f9f46281f6bcee6ceae7420c70e91333579c912
This commit is contained in:
Nikita Bobko
2024-03-19 19:37:53 +01:00
committed by intellij-monorepo-bot
parent 129345e28d
commit 935f4e90df
2 changed files with 20 additions and 3 deletions
@@ -8,6 +8,11 @@ import org.junit.Assert
import java.io.File
object JUnit4Assertions : Assertions() {
override fun doesEqualToFile(expectedFile: File, actual: String, sanitizer: (String) -> String): Boolean {
val expectedPath = expectedFile.toPath()
return KotlinTestHelpers.doesEqualsToPath(expectedPath, actual, sanitizer).yes
}
override fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String, message: () -> String) {
val expectedPath = expectedFile.toPath()
KotlinTestHelpers.assertEqualsToPath(expectedPath, actual, sanitizer, message)
@@ -30,7 +30,9 @@ object KotlinTestHelpers {
assertEqualsToPath(expectedPath, actual, { it }) { "Expected file content differs from the actual result" }
}
fun assertEqualsToPath(expectedPath: Path, actual: String, sanitizer: (String) -> String, message: () -> String) {
data class DoesEqual(val yes: Boolean, val processedExpected: String, val processedActual: String)
fun doesEqualsToPath(expectedPath: Path, actual: String, sanitizer: (String) -> String): DoesEqual {
if (!expectedPath.exists()) {
expectedPath.writeText(actual)
TestCase.fail("File didn't exist. New file was created (${expectedPath.absolutePathString()}).")
@@ -46,8 +48,18 @@ object KotlinTestHelpers {
val processedExpected = process(expectedPath.readText())
val processedActual = process(actual)
if (processedExpected != processedActual) {
throw FileComparisonFailedError(message(), processedExpected, processedActual, expectedPath.absolutePathString())
return DoesEqual(processedExpected == processedActual, processedExpected, processedActual)
}
fun assertEqualsToPath(expectedPath: Path, actual: String, sanitizer: (String) -> String, message: () -> String) {
val equalsToPath = doesEqualsToPath(expectedPath, actual, sanitizer)
if (!equalsToPath.yes) {
throw FileComparisonFailedError(
message(),
equalsToPath.processedExpected,
equalsToPath.processedActual,
expectedPath.absolutePathString()
)
}
}
}