Skip to content

Commit

Permalink
refactor(common-utils): Use forAll in tests to simplify code
Browse files Browse the repository at this point in the history
Move the stand-alone assertion to the begging of the block for
visibility while at it.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed May 24, 2024
1 parent 11baaeb commit 4fb504e
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions utils/common/src/test/kotlin/ExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 4fb504e

Please sign in to comment.