add assertion to compare to file content.

This commit is contained in:
2025-02-07 11:08:19 +01:00
parent 1f6329f687
commit f12b750fe3

View File

@@ -0,0 +1,15 @@
package ltd.hlaeja.test
import org.assertj.core.api.AbstractStringAssert
@Suppress("unused")
fun <SELF : AbstractStringAssert<SELF>?> AbstractStringAssert<SELF>.compareToFile(
file: String,
): AbstractStringAssert<SELF> = 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",
)