Skip to content

Commit

Permalink
test: ShelterPassword 검증 테스트코드를 작성한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjo6300 committed Nov 1, 2023
1 parent 1cb8a90 commit 7467582
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ShelterNameTest {

@Nested
@DisplayName("VolunteerName 생성 시")
@DisplayName("ShelterName 생성 시")
class newShelterNameTest {

String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.clova.anifriends.domain.shelter.wrapper;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchException;

import com.clova.anifriends.domain.shelter.exception.ShelterBadRequestException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

class ShelterPasswordTest {

@Nested
@DisplayName("ShelterPassword 생성 시")
class newShelterPasswordTest {

String password;

@Test
@DisplayName("성공")
void newShelterPassword() {
// given
password = "asdfqwer123";

// when
ShelterPassword shelterPassword = new ShelterPassword(password);

// then
assertThat(shelterPassword.getPassword()).isEqualTo(password);
}

@Test
@DisplayName("예외(ShelterNotFoundException): 비밀번호가 null인 경우")
void throwExceptionWhenPasswordIsNull() {
// given
password = null;

// when
Exception exception = catchException(
() -> new ShelterName(password));

// then
assertThat(exception).isInstanceOf(ShelterBadRequestException.class);
}

@Test
@DisplayName("예외(ShelterNotFoundException): 비밀번호가 blank인 경우")
void throwExceptionWhenPasswordIsBlank() {
// given
password = null;

// when
Exception exception = catchException(
() -> new ShelterName(password));

// then
assertThat(exception).isInstanceOf(ShelterBadRequestException.class);
}

@Test
@DisplayName("예외(ShelterBadRequestException): 비밀번호가 6자 미만인 경우")
void throwExceptionWhenPasswordIsLessThanSix() {
// given
password = "asdf";

// when
Exception exception = catchException(
() -> new ShelterPassword(password));

// then
assertThat(exception).isInstanceOf(ShelterBadRequestException.class);
}

@Test
@DisplayName("예외(ShelterBadRequestException): 비밀번호가 16자 초과인 경우")
void throwExceptionWhenPasswordIsOverThanSixteen() {
// given
password = "asdfqwer123asdfqwer123";

// when
Exception exception = catchException(
() -> new ShelterName(password));

// then
assertThat(exception).isInstanceOf(ShelterBadRequestException.class);
}
}
}

0 comments on commit 7467582

Please sign in to comment.