diff options
author | Edoardo La Greca | 2025-06-20 02:55:32 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-06-20 02:55:32 +0200 |
commit | c210af76ef32c6e521f2e3a0fc65781098d9cd83 (patch) | |
tree | 8dc68f858667e2c6b28bda529ec6b6a5f6401d15 | |
parent | f37a18827a6826c702d9de3621b1de86c1f9aca4 (diff) |
add tests for IPAddress
-rw-r--r-- | src/test/kotlin/IPAddressTest.kt | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/kotlin/IPAddressTest.kt b/src/test/kotlin/IPAddressTest.kt new file mode 100644 index 0000000..b213d71 --- /dev/null +++ b/src/test/kotlin/IPAddressTest.kt @@ -0,0 +1,38 @@ +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.function.Executable + +private class IPAddressConstructor(private val address: String) : Executable { + override fun execute() { + IPAddress(this.address) + } +} + +class IPAddressTest { + @Test + fun testAddressVersion4() { + val testAddressesCorrect = listOf( + "10.255.0.1", + "0011:2233:4455:6677:8899:aabb:ccdd:eeff", + "aabb::", + ) + + val testAddressesWrong = listOf( + "999.888.777.666", + "ghil:mnop:qrst:uvwx:yz99:8877:6655:4433", + "aaabbb::", + "aa::", + "gg::", + + ) + + // assert correct + assertAll(testAddressesCorrect.map { IPAddressConstructor(it) }) + + // assert wrong + for (address in testAddressesWrong) { + assertThrowsExactly<NumberFormatException>(NumberFormatException().javaClass, IPAddressConstructor(address)) + } + } + +}
\ No newline at end of file |