-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 16 additions & 11 deletions
27
src/test/kotlin/lotto/input/InputWinningNumberValidationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,50 @@ | ||
package lotto.input | ||
|
||
import camp.nextstep.edu.missionutils.Console | ||
import camp.nextstep.edu.missionutils.test.Assertions.assertSimpleTest | ||
import camp.nextstep.edu.missionutils.test.NsTest | ||
import lotto.constants.ErrorMessage | ||
import lotto.utils.ValidationUtils | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class InputWinningNumberValidationTest : NsTest() { | ||
|
||
@Test | ||
fun `예외 테스트-당첨번호가 "숫자,"가 아닌 다른 문자열이 섞여 있을 때`() { | ||
assertSimpleTest { | ||
assertThrows<IllegalArgumentException> { runException("1,2,3,7,선미,샌디") } | ||
fun `예외 테스트-당첨번호가 '숫자,'가 아닌 다른 문자열이 섞여 있을 때`() { | ||
val exception = assertThrows<IllegalArgumentException> { | ||
runException("1,2,3,7,선미,샌디") | ||
} | ||
assertEquals(ErrorMessage.WINNING_NUMBER_INVALID_FORMAT, exception.message) | ||
} | ||
|
||
@Test | ||
fun `예외 테스트-당첨번호의 개수가 6개가 아닐 때`() { | ||
assertSimpleTest { | ||
assertThrows<IllegalArgumentException> { runException("1,2,3,4,5") } | ||
val exception = assertThrows<IllegalArgumentException> { | ||
runException("1,2,3,4,5") | ||
} | ||
assertEquals(ErrorMessage.WINNING_NUMBER_NOT_ONE_SET_SIZE, exception.message) | ||
} | ||
|
||
@Test | ||
fun `예외 테스트-당첨번호에 1~45 사이가 아닌 정수가 있을 때`() { | ||
assertSimpleTest { | ||
assertThrows<IllegalArgumentException> { runException("1,2,3,4,5,100") } | ||
val exception = assertThrows<IllegalArgumentException> { | ||
runException("1,2,3,4,5,100") | ||
} | ||
assertEquals(ErrorMessage.WINNING_NUMBER_NOT_IN_RANGE, exception.message) | ||
} | ||
|
||
@Test | ||
fun `예외 테스트-당첨번호에 중복된 숫자가 있을 때`() { | ||
assertSimpleTest { | ||
assertThrows<IllegalArgumentException> { runException("20000000") } | ||
val exception = assertThrows<IllegalArgumentException> { | ||
runException("1,5,5,6,7,8") | ||
} | ||
assertEquals(ErrorMessage.WINNING_NUMBER_OVERLAP, exception.message) | ||
} | ||
|
||
override fun runMain() { | ||
val number = Console.readLine() | ||
ValidationUtils.checkValidWinningNumbers(number, ",") | ||
ValidationUtils.checkValidWinningNumbers(number) | ||
Console.close() | ||
} | ||
} |