From 902a2a2c0b350d6dc669389405104ccf96dfe12b Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Wed, 5 Mar 2025 16:07:28 +0100 Subject: [PATCH] add assertion to compare uuid against string representation of an uuid --- gradle.properties | 2 +- src/main/kotlin/ltd/hlaeja/test/Assertion.kt | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 336226c..09bfae1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.code.style=official version=0.2.0-SNAPSHOT -catalog=0.9.0 +catalog=0.10.0-SNAPSHOT diff --git a/src/main/kotlin/ltd/hlaeja/test/Assertion.kt b/src/main/kotlin/ltd/hlaeja/test/Assertion.kt index f975b26..101d9ec 100644 --- a/src/main/kotlin/ltd/hlaeja/test/Assertion.kt +++ b/src/main/kotlin/ltd/hlaeja/test/Assertion.kt @@ -1,5 +1,7 @@ package ltd.hlaeja.test +import java.util.UUID +import org.assertj.core.api.AbstractAssert import org.assertj.core.api.AbstractStringAssert @Suppress("unused") @@ -13,3 +15,12 @@ fun ?> AbstractStringAssert.compareToFil ?: throw UnsupportedOperationException( "Attempted to compare assertion object to context of a file but expected file was not found: $file", ) + +@Suppress("unused") +fun ?, ACTUAL> AbstractAssert.isEqualToUuid( + uuid: String, +): SELF = try { + UUID.fromString(uuid).let { expected -> this.isEqualTo(expected) } +} catch (e: IllegalArgumentException) { + throw UnsupportedOperationException("Invalid UUID string provided: $uuid", e) +}