|
| 1 | +package clap.server.domain.policy.member; |
| 2 | + |
| 3 | +import jakarta.validation.ConstraintValidatorContext; |
| 4 | +import org.junit.jupiter.api.BeforeEach; |
| 5 | +import org.junit.jupiter.api.DisplayName; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | +import static org.mockito.Mockito.mock; |
| 10 | + |
| 11 | +class PasswordPolicyTest { |
| 12 | + |
| 13 | + private PasswordPolicy passwordPolicy; |
| 14 | + private ConstraintValidatorContext context; |
| 15 | + |
| 16 | + @BeforeEach |
| 17 | + void setUp() { |
| 18 | + passwordPolicy = new PasswordPolicy(); |
| 19 | + context = mock(ConstraintValidatorContext.class); // Mock ConstraintValidatorContext |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + @DisplayName("유효한 비밀번호 - 대문자, 소문자, 숫자, 특수문자 포함") |
| 24 | + void validPassword() { |
| 25 | + String validPassword = "Abcdef1!"; |
| 26 | + boolean result = passwordPolicy.isValid(validPassword, context); |
| 27 | + assertThat(result).isTrue(); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + @DisplayName("유효하지 않은 비밀번호 - 대문자 없음") |
| 32 | + void invalidPassword_noUpperCase() { |
| 33 | + String invalidPassword = "abcdef1!"; |
| 34 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 35 | + assertThat(result).isFalse(); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + @DisplayName("유효하지 않은 비밀번호 - 소문자 없음") |
| 40 | + void invalidPassword_noLowerCase() { |
| 41 | + String invalidPassword = "ABCDEF1!"; |
| 42 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 43 | + assertThat(result).isFalse(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + @DisplayName("유효하지 않은 비밀번호 - 숫자 없음") |
| 48 | + void invalidPassword_noDigit() { |
| 49 | + String invalidPassword = "Abcdefgh!"; |
| 50 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 51 | + assertThat(result).isFalse(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + @DisplayName("유효하지 않은 비밀번호 - 특수문자 없음") |
| 56 | + void invalidPassword_noSpecialCharacter() { |
| 57 | + String invalidPassword = "Abcdefg1"; |
| 58 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 59 | + assertThat(result).isFalse(); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + @DisplayName("유효하지 않은 비밀번호 - 길이가 8자 미만") |
| 64 | + void invalidPassword_tooShort() { |
| 65 | + String invalidPassword = "Ab1!"; |
| 66 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 67 | + assertThat(result).isFalse(); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + @DisplayName("유효하지 않은 비밀번호 - 길이가 20자 초과") |
| 72 | + void invalidPassword_tooLong() { |
| 73 | + String invalidPassword = "Abcdefg1!Abcdefg1!Abcdefg1!"; |
| 74 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 75 | + assertThat(result).isFalse(); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + @DisplayName("유효하지 않은 비밀번호 - null 값") |
| 80 | + void invalidPassword_null() { |
| 81 | + String invalidPassword = null; |
| 82 | + boolean result = passwordPolicy.isValid(invalidPassword, context); |
| 83 | + assertThat(result).isFalse(); |
| 84 | + } |
| 85 | +} |
0 commit comments