Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .codeguide/loopers-1-week.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.loopers.domain.member;

import com.loopers.domain.BaseEntity;
import com.loopers.support.error.CoreException;
import com.loopers.support.error.ErrorType;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Entity
@Table(name = "member")
public class Member extends BaseEntity {

private String loginId;
private String encryptedPassword;
private String name;
private String birthDate;
private String email;

protected Member() {}

public Member(String loginId, String rawPassword, String name,
String birthDate, String email) {
validateLoginId(loginId);
validatePassword(rawPassword);
validateName(name);
validateBirthDate(birthDate);
validateEmail(email);

this.loginId = loginId;
this.encryptedPassword = rawPassword;
this.name = name;
this.birthDate = birthDate;
this.email = email;
}

private void validateLoginId(String loginId) {
if (loginId == null || loginId.isBlank()) {
throw new CoreException(ErrorType.BAD_REQUEST, "로그인ID는 필수입니다");
}
}

private void validatePassword(String password) {
if (password == null || password.isBlank()) {
throw new CoreException(ErrorType.BAD_REQUEST, "비밀번호는 필수입니다");
}
}

private void validateName(String name) {
if (name == null || name.isBlank()) {
throw new CoreException(ErrorType.BAD_REQUEST, "이름은 필수입니다");
}
}

private void validateBirthDate(String birthDate) {
if (birthDate == null || birthDate.isBlank()) {
throw new CoreException(ErrorType.BAD_REQUEST, "생년월일은 필수입니다");
}
}

private void validateEmail(String email) {
if (email == null || email.isBlank()) {
throw new CoreException(ErrorType.BAD_REQUEST, "이메일은 필수입니다");
}
}

public String getLoginId() {
return loginId;
}

public String getName() {
return name;
}

public String getBirthDate() {
return birthDate;
}

public String getEmail() {
return email;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.loopers.domain.member;

import com.loopers.support.error.CoreException;
import com.loopers.support.error.ErrorType;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertAll;

class MemberTest {

@DisplayName("회원을 생성할 때")
@Nested
class Create {

@DisplayName("유효한 정보가 주어지면 성공한다")
@Test
void success() {
String loginId = "testuser123";
String password = "password123";
String name = "홍길동";
String birthDate = "1990-01-01";
String email = "test@example.com";

Member member = new Member(loginId, password, name, birthDate, email);

assertAll(
() -> assertThat(member.getLoginId()).isEqualTo(loginId),
() -> assertThat(member.getName()).isEqualTo(name),
() -> assertThat(member.getBirthDate()).isEqualTo(birthDate),
() -> assertThat(member.getEmail()).isEqualTo(email)
);
}

@DisplayName("로그인ID가 null이면 예외가 발생한다")
@Test
void failsWhenLoginIdIsNull() {
assertThatThrownBy(() ->
new Member(null, "pw", "name", "1990-01-01", "email@test.com")
)
.isInstanceOf(CoreException.class)
.hasFieldOrPropertyWithValue("errorType", ErrorType.BAD_REQUEST);
}

@DisplayName("로그인ID가 빈 문자열이면 예외가 발생한다")
@Test
void failsWhenLoginIdIsBlank() {
assertThatThrownBy(() ->
new Member(" ", "pw", "name", "1990-01-01", "email@test.com")
)
.isInstanceOf(CoreException.class);
}

@DisplayName("비밀번호가 null이면 예외가 발생한다")
@Test
void failsWhenPasswordIsNull() {
assertThatThrownBy(() ->
new Member("loginId", null, "name", "1990-01-01", "email@test.com")
)
.isInstanceOf(CoreException.class);
}

@DisplayName("이름이 null이면 예외가 발생한다")
@Test
void failsWhenNameIsNull() {
assertThatThrownBy(() ->
new Member("loginId", "pw", null, "1990-01-01", "email@test.com")
)
.isInstanceOf(CoreException.class);
}

@DisplayName("생년월일이 null이면 예외가 발생한다")
@Test
void failsWhenBirthDateIsNull() {
assertThatThrownBy(() ->
new Member("loginId", "pw", "name", null, "email@test.com")
)
.isInstanceOf(CoreException.class);
}

@DisplayName("이메일이 null이면 예외가 발생한다")
@Test
void failsWhenEmailIsNull() {
assertThatThrownBy(() ->
new Member("loginId", "pw", "name", "1990-01-01", null)
)
.isInstanceOf(CoreException.class);
}
}
}