Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
[WEAV-20] ✨ VO Regex 수정 및 테스트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Jan 22, 2024
1 parent 64278ff commit 13f01f4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ package com.studentcenter.weave.support.common.vo
value class Email(val value: String) {

companion object {
const val VALIDATION_REGEX = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
const val VALIDATION_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\$"
const val VALIDATION_MESSAGE = "잘못된 Email 형식 입니다."
}

init {
require(value.matches(Regex(VALIDATION_REGEX))) { VALIDATION_MESSAGE }
require(value.matches(VALIDATION_REGEX.toRegex())) { VALIDATION_MESSAGE }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ value class Url(val value: String) {
}

init {
require(value.matches(Regex(VALIDATION_REGEX))) { VALIDATION_MESSAGE }
require(value.matches(VALIDATION_REGEX.toRegex())) { VALIDATION_MESSAGE }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.studentcenter.weave.support.common.vo

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec

class EmailTest: FunSpec({

test("이메일 주소가 올바른 형식이 아닌 경우 예외가 발생한다.") {
val invalidEmail = "invalid_email"
shouldThrow<IllegalArgumentException> {
Email(invalidEmail)
}
}

test("이메일 주소가 올바른 형식인 경우 객체가 생성된다.") {
val validEmail = "[email protected]"
Email(validEmail)
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.studentcenter.weave.support.common.vo

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec

class UrlTest : FunSpec({

test("URL 형식이 아닌 경우 예외가 발생한다.") {
val invalidUrl = "invalid_url"
shouldThrow<IllegalArgumentException> {
Url(invalidUrl)
}
}

test("URL 형식인 경우 객체가 생성된다.") {
val validUrl = "https://test.com"
Url(validUrl)
}

})

0 comments on commit 13f01f4

Please sign in to comment.