From f12b750fe30bd7a19433a305bf8751b83fa7f0ad Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Fri, 7 Feb 2025 11:08:19 +0100 Subject: [PATCH] add assertion to compare to file content. --- src/main/kotlin/ltd/hlaeja/test/Assertion.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/kotlin/ltd/hlaeja/test/Assertion.kt diff --git a/src/main/kotlin/ltd/hlaeja/test/Assertion.kt b/src/main/kotlin/ltd/hlaeja/test/Assertion.kt new file mode 100644 index 0000000..f975b26 --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/test/Assertion.kt @@ -0,0 +1,15 @@ +package ltd.hlaeja.test + +import org.assertj.core.api.AbstractStringAssert + +@Suppress("unused") +fun ?> AbstractStringAssert.compareToFile( + file: String, +): AbstractStringAssert = this::class.java.classLoader + .getResourceAsStream(file) + ?.bufferedReader() + ?.readText() + ?.let { this.isEqualTo(it) } + ?: throw UnsupportedOperationException( + "Attempted to compare assertion object to context of a file but expected file was not found: $file", + )