Skip to content

Commit

Permalink
refactor: domain test 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
minjo-on committed Jan 16, 2025
1 parent f4dcf97 commit 4ef0001
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@

public class ClubDomainTest {
private Club club;
private static final String DEFAULT_NAME = "Club A";
private static final String DEFAULT_DESCRIPTION = "a 동아리입니다.";
private static final String DEFAULT_SITE = "http://club-a.kyonggi.ac.kr";
private static final String NAME = "Club A";
private static final String DESCRIPTION = "a 동아리입니다.";
private static final String SITE = "http://club-a.kyonggi.ac.kr";

@BeforeEach
void setUp() {
club = Club.create(DEFAULT_NAME, DEFAULT_DESCRIPTION, DEFAULT_SITE);
club = Club.create(NAME, DESCRIPTION, SITE);
}

@Test
@DisplayName("Club 객체를 생성할 수 있다")
public void createClub_Success() {

// when
Club newClub = Club.create(DEFAULT_NAME, DEFAULT_DESCRIPTION, DEFAULT_SITE);
Club newClub = Club.create(NAME, DESCRIPTION, SITE);

// then
assertNotNull(newClub);
assertEquals(DEFAULT_NAME, newClub.getName());
assertEquals(DEFAULT_DESCRIPTION, newClub.getDescription());
assertEquals(DEFAULT_SITE, newClub.getSite());
assertEquals(NAME, newClub.getName());
assertEquals(DESCRIPTION, newClub.getDescription());
assertEquals(SITE, newClub.getSite());
}

@Test
Expand Down
13 changes: 5 additions & 8 deletions aics-domain/src/testFixtures/java/lab/domain/LabDomainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import kgu.developers.domain.lab.domain.Lab;

public class LabDomainTest {
private Lab lab;
private static final String NAME = "Lab A";
private static final String LOC = "8500";
private static final String SITE = "http://lab1.kyonggi.ac.kr";
private static final String ADVISOR = "박교수";

private Lab createTestLab() {
return Lab.create(NAME, LOC, SITE, ADVISOR);
@BeforeEach
public void init() {
lab = Lab.create(NAME, LOC, SITE, ADVISOR);
}

@Test
@DisplayName("LAB 객체를 생성할 수 있다")
public void createLab_Success() {
// when
Lab lab = createTestLab();

// then
assertNotNull(lab);
assertEquals(NAME, lab.getName());
Expand All @@ -37,7 +38,6 @@ public void createLab_Success() {
@DisplayName("LAB 얀구실명 수정할 수 있다")
public void updateName_Success() {
// given
Lab lab = createTestLab();
String newName = "Updated Lab A";

// when
Expand All @@ -51,7 +51,6 @@ public void updateName_Success() {
@DisplayName("LAB 위치를 수정할 수 있다")
public void updateLoc_Success() {
// given
Lab lab = createTestLab();
String newLoc = "8601";

// when
Expand All @@ -65,7 +64,6 @@ public void updateLoc_Success() {
@DisplayName("LAB 사이트를 수정할 수 있다")
public void updateSite_Success() {
// given
Lab lab = createTestLab();
String newSite = "http://new.kyonggi.ac.kr";

// when
Expand All @@ -79,7 +77,6 @@ public void updateSite_Success() {
@DisplayName("LAB 담당교수를 수정할 수 있다")
public void updateAdvisor_Success() {
// given
Lab lab = createTestLab();
String newAdvisor = "이교수";

// when
Expand Down
69 changes: 21 additions & 48 deletions aics-domain/src/testFixtures/java/post/domain/PostDomainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.util.stream.IntStream;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand All @@ -18,37 +19,41 @@
import kgu.developers.domain.user.domain.User;

public class PostDomainTest {
private Post post;
private User author;
private static final String TITLE = "Valid Title";
private static final String CONTENT = "This is valid content.";

@BeforeEach
public void init() {
author = User.create("202411345",
"password",
"홍길동",
"[email protected]",
"010-1234-5678", CSE);

post = Post.create(TITLE, CONTENT, NEWS, author);
}

@Test
@DisplayName("POST 객체를 생성할 수 있다")
public void createPost_Success() {
// given
String title = "Valid Title";
String content = "This is valid content.";
Category category = NEWS;
User user = getUser();

// when
Post post = Post.create(title, content, category, user);

// then
assertNotNull(post);
assertEquals(title, post.getTitle());
assertEquals(content, post.getContent());
assertEquals(TITLE, post.getTitle());
assertEquals(CONTENT, post.getContent());
assertEquals(0, post.getViews());
assertFalse(post.isPinned());
assertEquals(category, post.getCategory());
assertEquals(user, post.getAuthor());
assertEquals(NEWS, post.getCategory());
assertEquals(author, post.getAuthor());
}

@Test
@DisplayName("POST 제목을 업데이트할 수 있다")
public void updatePostTitle_Success() {
// given
String title = "Valid Title";
String content = "This is valid content.";
User user = getUser();

Post post = Post.create(title, content, NEWS, user);
String newTitle = "Updated Title";

// when
Expand All @@ -62,11 +67,6 @@ public void updatePostTitle_Success() {
@DisplayName("POST 내용을 업데이트할 수 있다")
public void updatePostContent_Success() {
// given
String title = "Valid Title";
String content = "This is valid content.";
User user = getUser();

Post post = Post.create(title, content, NEWS, user);
String newContent = "Updated Content";

// when
Expand All @@ -80,11 +80,6 @@ public void updatePostContent_Success() {
@DisplayName("POST 카테고리를 업데이트할 수 있다")
public void updatePostCategory_Success() {
// given
String title = "Valid Title";
String content = "This is valid content.";
User user = getUser();

Post post = Post.create(title, content, NEWS, user);
Category newCategory = NOTIFICATION;

// when
Expand All @@ -98,11 +93,6 @@ public void updatePostCategory_Success() {
@DisplayName("POST 조회수를 증가시킬 수 있다")
public void increasePostViews_Success() {
// given
String title = "Valid Title";
String content = "This is valid content.";
User user = getUser();

Post post = Post.create(title, content, NEWS, user);
int incrementCount = 5;

// when
Expand All @@ -116,12 +106,6 @@ public void increasePostViews_Success() {
@Test
@DisplayName("POST 고정 여부를 토글할 수 있다")
public void togglePostPinned_Success() {
// given
String title = "Valid Title";
String content = "This is valid content.";
User user = getUser();

Post post = Post.create(title, content, NEWS, user);

// when
post.togglePinned();
Expand All @@ -133,15 +117,4 @@ public void togglePostPinned_Success() {
// then
assertFalse(post.isPinned());
}

private User getUser() {
String id = "202411345";
String password = "password";
String name = "홍길동";
String email = "[email protected]";
String phone = "010-1234-5678";

return User.create(id, password, name, email, phone, CSE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import kgu.developers.domain.professor.domain.Professor;
import kgu.developers.domain.professor.domain.Role;

public class ProfessorDomainTest {
private Professor professor;
private static final String NAME = "박민준";
private static final Role ROLE = PROFESSOR;
private static final String CONTACT = "010-1234-5678";
private static final String EMAIL = "[email protected]";
private static final String IMAGE = "https://image.com/professor/profile/image";
private static final String OFFICE_LOC = "8000호";

private Professor createTestProfessor() {
return Professor.create(NAME, ROLE, CONTACT, EMAIL, IMAGE, OFFICE_LOC);
@BeforeEach
public void init() {
professor = Professor.create(NAME, ROLE, CONTACT, EMAIL, IMAGE, OFFICE_LOC);
}

@Test
@DisplayName("PROFESSOR 객체를 생성할 수 있다")
public void createProfessor_Success() {

// when
Professor professor = createTestProfessor();

// then
assertNotNull(professor);
assertEquals(NAME, professor.getName());
Expand All @@ -43,8 +44,6 @@ public void createProfessor_Success() {
@Test
@DisplayName("PROFESSOR 객체의 이름을 수정할 수 있다")
public void updateName_Success() {
// given
Professor professor = createTestProfessor();

// when
String newName = "이신행";
Expand All @@ -57,8 +56,6 @@ public void updateName_Success() {
@Test
@DisplayName("PROFESSOR 객체의 역할을 수정할 수 있다")
public void updateRole_Success() {
// given
Professor professor = createTestProfessor();

// when
Role newRole = ASSISTANT;
Expand All @@ -71,8 +68,6 @@ public void updateRole_Success() {
@Test
@DisplayName("PROFESSOR 객체의 연락처를 수정할 수 있다")
public void updateContact_Success() {
// given
Professor professor = createTestProfessor();

// when
String newContact = "010-1234-8765";
Expand All @@ -85,8 +80,6 @@ public void updateContact_Success() {
@Test
@DisplayName("PROFESSOR 객체의 메일을 수정할 수 있다")
public void updateEmail_Success() {
// given
Professor professor = createTestProfessor();

// when
String newEmail = "[email protected]";
Expand Down

0 comments on commit 4ef0001

Please sign in to comment.