Add Domain
value class
This commit is contained in:
parent
2dbecb667c
commit
8b8bc409e8
2 changed files with 33 additions and 0 deletions
|
@ -0,0 +1,8 @@
|
|||
package app.k9mail.core.common.net
|
||||
|
||||
@JvmInline
|
||||
value class Domain(val value: String) {
|
||||
init {
|
||||
requireNotNull(HostNameUtils.isLegalHostName(value)) { "Not a valid domain name: '$value'" }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package app.k9mail.core.common.net
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.hasMessage
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isInstanceOf
|
||||
import kotlin.test.Test
|
||||
|
||||
class DomainTest {
|
||||
@Test
|
||||
fun `valid domain`() {
|
||||
val domain = Domain("domain.example")
|
||||
|
||||
assertThat(domain.value).isEqualTo("domain.example")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid domain should throw`() {
|
||||
assertFailure {
|
||||
Domain("invalid domain")
|
||||
}.isInstanceOf<IllegalArgumentException>()
|
||||
.hasMessage("Not a valid domain name: 'invalid domain'")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue