Skip to content

Commit

Permalink
test: Member 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed Oct 7, 2023
1 parent 8f54279 commit 1e39078
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 8 deletions.
3 changes: 2 additions & 1 deletion backend/src/main/java/com/festago/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.util.StringUtils;

@Entity
@SQLDelete(sql = "UPDATE member SET deleted_at = now(), nickname = '탈퇴한 회원', profile_image = '', social_id = null WHERE id=?")
Expand Down Expand Up @@ -76,7 +77,7 @@ public Member(Long id, String socialId, SocialType socialType, String nickname,
this.socialId = socialId;
this.socialType = socialType;
this.nickname = nickname;
this.profileImage = (profileImage != null) ? profileImage : DEFAULT_IMAGE_URL;
this.profileImage = (StringUtils.hasText(profileImage)) ? profileImage : DEFAULT_IMAGE_URL;
}

private void validate(String socialId, SocialType socialType, String nickname, String profileImage) {
Expand Down
85 changes: 78 additions & 7 deletions backend/src/test/java/com/festago/member/domain/MemberTest.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,95 @@
package com.festago.member.domain;

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

import com.festago.support.MemberFixture;
import com.festago.auth.domain.SocialType;
import com.festago.common.exception.ValidException;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

@DisplayNameGeneration(ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class MemberTest {

@Test
void 프로필_이미지가_null이면_기본값이_할당된다() {
// when
Member actual = MemberFixture.member()
.profileImage(null)
.build();
void Member_생성_성공() {
// given
Member member = new Member(1L, "12345", SocialType.FESTAGO, "nickname", "profileImage.png");

// then
// when & then
assertThat(member.getId()).isEqualTo(1L);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void socialId가_null_또는_공백이면_예외(String socialId) {
// when & then
assertThatThrownBy(() -> new Member(1L, socialId, SocialType.FESTAGO, "nickname", "profileImage.png"))
.isInstanceOf(ValidException.class);
}

@Test
void socialId의_길이가_255자를_초과하면_예외() {
// given
String socialId = "1".repeat(256);

// when & then
assertThatThrownBy(() -> new Member(1L, socialId, SocialType.FESTAGO, "nickname", "profileImage.png"))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
void socialType이_null이면_예외(SocialType socialType) {
// when & then
assertThatThrownBy(() -> new Member(1L, "12345", socialType, "nickname", "profileImage.png"))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void nickname이_null_또는_공백이면_예외(String nickname) {
// when & then
assertThatThrownBy(() -> new Member(1L, "12345", SocialType.FESTAGO, nickname, "profileImage.png"))
.isInstanceOf(ValidException.class);
}

@Test
void nickname의_길이가_30자를_초과하면_예외() {
// given
String nickname = "1".repeat(31);

// when & then
assertThatThrownBy(() -> new Member(1L, "12345", SocialType.FESTAGO, nickname, "profileImage.png"))
.isInstanceOf(ValidException.class);
}

@Test
void profileImage의_길이가_255자를_초과하면_예외() {
// given
String profileImage = "1".repeat(256);

// when & then
assertThatThrownBy(() -> new Member(1L, "12345", SocialType.FESTAGO, "nickname", profileImage))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void profileImage가_null_또는_공백이면_기본값이_할당된다(String profileImage) {
// given
Member actual = new Member("12345", SocialType.FESTAGO, "nickname", profileImage);

// when & then
assertThat(actual.getProfileImage()).isNotNull();
assertThat(actual.getProfileImage()).isNotBlank();
}
}

0 comments on commit 1e39078

Please sign in to comment.