From 4fb504ef56c6aa123659c81e5c6113d0fefefa67 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 24 May 2024 13:58:09 +0200 Subject: [PATCH] refactor(common-utils): Use `forAll` in tests to simplify code Move the stand-alone assertion to the begging of the block for visibility while at it. Signed-off-by: Sebastian Schuberth --- .../common/src/test/kotlin/ExtensionsTest.kt | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/utils/common/src/test/kotlin/ExtensionsTest.kt b/utils/common/src/test/kotlin/ExtensionsTest.kt index 187ddb442ba8f..d0fc507dd70ba 100644 --- a/utils/common/src/test/kotlin/ExtensionsTest.kt +++ b/utils/common/src/test/kotlin/ExtensionsTest.kt @@ -19,7 +19,6 @@ package org.ossreviewtoolkit.utils.common -import io.kotest.assertions.assertSoftly import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.WordSpec @@ -374,26 +373,24 @@ class ExtensionsTest : WordSpec({ val special = listOf('-', '.', '_', '~') val unreserved = alpha + digit + special - assertSoftly { - reserved.forEach { - val decoded = it.toString() + " ".percentEncode() shouldBe "%20" - val encoded = decoded.percentEncode() + reserved.forAll { + val decoded = it.toString() - encoded shouldBe String.format(Locale.ROOT, "%%%02X", it.code) - URLDecoder.decode(encoded, Charsets.UTF_8) shouldBe decoded - } + val encoded = decoded.percentEncode() - unreserved.forEach { - val decoded = it.toString() + encoded shouldBe String.format(Locale.ROOT, "%%%02X", it.code) + URLDecoder.decode(encoded, Charsets.UTF_8) shouldBe decoded + } - val encoded = decoded.percentEncode() + unreserved.asList().forAll { + val decoded = it.toString() - encoded shouldBe decoded - URLDecoder.decode(encoded, Charsets.UTF_8) shouldBe decoded - } + val encoded = decoded.percentEncode() - " ".percentEncode() shouldBe "%20" + encoded shouldBe decoded + URLDecoder.decode(encoded, Charsets.UTF_8) shouldBe decoded } } }