summaryrefslogtreecommitdiff
path: root/src/test/kotlin/IPAddressTest.kt
blob: b213d717a8de2ff50ba7c158f40a5bfeb26b4589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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))
        }
    }

}