From e74b4df32fcd5cf6faade1ae6c99c1843b32260c Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 31 Jul 2024 16:44:10 +0900 Subject: [PATCH 1/4] =?UTF-8?q?test:=20ChatFixture=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/fixture/ChatFixture.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/src/test/java/mouda/backend/fixture/ChatFixture.java diff --git a/backend/src/test/java/mouda/backend/fixture/ChatFixture.java b/backend/src/test/java/mouda/backend/fixture/ChatFixture.java new file mode 100644 index 000000000..0f8dd8644 --- /dev/null +++ b/backend/src/test/java/mouda/backend/fixture/ChatFixture.java @@ -0,0 +1,39 @@ +package mouda.backend.fixture; + +import java.time.LocalDate; +import java.time.LocalTime; + +import mouda.backend.chat.domain.Chat; + +public class ChatFixture { + + public static Chat getChatWithHogeeAtBasketballMoim() { + return Chat.builder() + .time(LocalTime.now()) + .date(LocalDate.now()) + .content("ㅎㅇㅎㅇ") + .member(MemberFixture.getHogee()) + .moim(MoimFixture.getBasketballMoim()) + .build(); + } + + public static Chat getChatWithAnnaAtCoffeeMoim() { + return Chat.builder() + .time(LocalTime.now()) + .date(LocalDate.now()) + .content("반갑읍니다") + .member(MemberFixture.getAnna()) + .moim(MoimFixture.getCoffeeMoim()) + .build(); + } + + public static Chat getChatWithTebahAtSoccerMoim() { + return Chat.builder() + .time(LocalTime.now()) + .date(LocalDate.now()) + .content("ㅎㅇㅎㅇ") + .member(MemberFixture.getTebah()) + .moim(MoimFixture.getSoccerMoim()) + .build(); + } +} From ec182a0e8a4edfd4a49a7171239ad2c7c39c4381 Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 31 Jul 2024 16:44:19 +0900 Subject: [PATCH 2/4] =?UTF-8?q?test:=20MoimFixture=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/fixture/MoimFixture.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 backend/src/test/java/mouda/backend/fixture/MoimFixture.java diff --git a/backend/src/test/java/mouda/backend/fixture/MoimFixture.java b/backend/src/test/java/mouda/backend/fixture/MoimFixture.java new file mode 100644 index 000000000..f2401878f --- /dev/null +++ b/backend/src/test/java/mouda/backend/fixture/MoimFixture.java @@ -0,0 +1,42 @@ +package mouda.backend.fixture; + +import java.time.LocalDate; +import java.time.LocalTime; + +import mouda.backend.moim.domain.Moim; + +public class MoimFixture { + + public static Moim getSoccerMoim() { + return Moim.builder() + .title("풋살할 사람?") + .time(LocalTime.now().plusHours(1)) + .date(LocalDate.now().plusDays(1)) + .place("잠실 종합운동장") + .description("잘하는 사람만 와라") + .maxPeople(22) + .build(); + } + + public static Moim getBasketballMoim() { + return Moim.builder() + .title("농구할 사람?") + .time(LocalTime.now().plusHours(1)) + .date(LocalDate.now().plusDays(1)) + .place("테바 집") + .description("파주로 와라") + .maxPeople(10) + .build(); + } + + public static Moim getCoffeeMoim() { + return Moim.builder() + .title("커피 마실 사람?") + .time(LocalTime.now().plusHours(1)) + .date(LocalDate.now().plusDays(1)) + .place("안나 집") + .description("커피 머신 들고와라") + .maxPeople(100) + .build(); + } +} From af7ac30505b2d4893c971b682ac6919022411e35 Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 31 Jul 2024 16:44:31 +0900 Subject: [PATCH 3/4] =?UTF-8?q?test:=20MemberFixture=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/fixture/MemberFixture.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 backend/src/test/java/mouda/backend/fixture/MemberFixture.java diff --git a/backend/src/test/java/mouda/backend/fixture/MemberFixture.java b/backend/src/test/java/mouda/backend/fixture/MemberFixture.java new file mode 100644 index 000000000..67c020beb --- /dev/null +++ b/backend/src/test/java/mouda/backend/fixture/MemberFixture.java @@ -0,0 +1,24 @@ +package mouda.backend.fixture; + +import mouda.backend.member.domain.Member; + +public class MemberFixture { + + public static Member getHogee() { + return Member.builder() + .nickname("hogee") + .build(); + } + + public static Member getAnna() { + return Member.builder() + .nickname("anna") + .build(); + } + + public static Member getTebah() { + return Member.builder() + .nickname("tebah") + .build(); + } +} From 3d1d842b0772be347f32fe797364777f9c110c45 Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 31 Jul 2024 16:44:46 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20testFixture=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/mouda/backend/chat/domain/Chat.java | 10 ++++ .../backend/member/domain/MemberTest.java | 6 +-- .../repository/MemberRepositoryTest.java | 15 ++---- .../mouda/backend/moim/domain/MoimTest.java | 10 +--- .../backend/security/JwtProviderTest.java | 51 +++++++++---------- 5 files changed, 43 insertions(+), 49 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chat/domain/Chat.java b/backend/src/main/java/mouda/backend/chat/domain/Chat.java index 14b4da05e..fe07b088c 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chat.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chat.java @@ -8,6 +8,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import mouda.backend.member.domain.Member; @@ -33,4 +34,13 @@ public class Chat { private LocalDate date; private LocalTime time; + + @Builder + public Chat(String content, Moim moim, Member member, LocalDate date, LocalTime time) { + this.content = content; + this.moim = moim; + this.member = member; + this.date = date; + this.time = time; + } } diff --git a/backend/src/test/java/mouda/backend/member/domain/MemberTest.java b/backend/src/test/java/mouda/backend/member/domain/MemberTest.java index 1ca75ae11..f34f764ef 100644 --- a/backend/src/test/java/mouda/backend/member/domain/MemberTest.java +++ b/backend/src/test/java/mouda/backend/member/domain/MemberTest.java @@ -6,17 +6,15 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import mouda.backend.fixture.MemberFixture; import mouda.backend.moim.exception.MoimException; class MemberTest { - private static final String NICNKAME = "안나"; @DisplayName("회원을 정상적으로 생성한다.") @Test void createMember() { - assertDoesNotThrow(() -> Member.builder() - .nickname(NICNKAME) - .build()); + assertDoesNotThrow(MemberFixture::getAnna); } @DisplayName("닉네임을 입력하지 않아 회원 생성에 실패한다.") diff --git a/backend/src/test/java/mouda/backend/member/repository/MemberRepositoryTest.java b/backend/src/test/java/mouda/backend/member/repository/MemberRepositoryTest.java index f0a78e8fe..7e02924f0 100644 --- a/backend/src/test/java/mouda/backend/member/repository/MemberRepositoryTest.java +++ b/backend/src/test/java/mouda/backend/member/repository/MemberRepositoryTest.java @@ -1,7 +1,5 @@ package mouda.backend.member.repository; -import java.time.LocalDate; -import java.time.LocalTime; import java.util.List; import org.assertj.core.api.Assertions; @@ -12,6 +10,8 @@ import org.springframework.boot.test.context.SpringBootTest; import mouda.backend.config.DatabaseCleaner; +import mouda.backend.fixture.MemberFixture; +import mouda.backend.fixture.MoimFixture; import mouda.backend.member.domain.Member; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.repository.MoimRepository; @@ -36,15 +36,8 @@ void cleanUp() { @DisplayName("모임에 가입된 참여자의 수를 반환한다.") @Test void findNickNamesByMoimId() { - Member member = new Member("tehah"); - Moim moim = Moim.builder() - .title("모임 제목") - .date(LocalDate.now().plusDays(1)) - .time(LocalTime.now().minusHours(1)) - .place("서울시 강북구 중앙로 2길 25") - .maxPeople(10) - .description("모임 설명입니다.") - .build(); + Member member = MemberFixture.getHogee(); + Moim moim = MoimFixture.getBasketballMoim(); Moim saveMoim = moimRepository.save(moim); member.joinMoim(saveMoim); memberRepository.save(member); diff --git a/backend/src/test/java/mouda/backend/moim/domain/MoimTest.java b/backend/src/test/java/mouda/backend/moim/domain/MoimTest.java index dc2558e10..729f786d8 100644 --- a/backend/src/test/java/mouda/backend/moim/domain/MoimTest.java +++ b/backend/src/test/java/mouda/backend/moim/domain/MoimTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import mouda.backend.fixture.MoimFixture; import mouda.backend.moim.exception.MoimException; class MoimTest { @@ -24,14 +25,7 @@ class MoimTest { @DisplayName("모임 객체를 정상적으로 생성한다.") @Test void createMoim() { - Assertions.assertDoesNotThrow(() -> Moim.builder() - .title(TITLE) - .date(DATE) - .time(TIME) - .place(PLACE) - .maxPeople(MAX_PEOPLE) - .description(DESCRIPTION) - .build()); + Assertions.assertDoesNotThrow(MoimFixture::getBasketballMoim); } @DisplayName("제목 길이가 제한을 초과하면 모임 객체 생성에 실패한다.") diff --git a/backend/src/test/java/mouda/backend/security/JwtProviderTest.java b/backend/src/test/java/mouda/backend/security/JwtProviderTest.java index 439838845..26e7c830c 100644 --- a/backend/src/test/java/mouda/backend/security/JwtProviderTest.java +++ b/backend/src/test/java/mouda/backend/security/JwtProviderTest.java @@ -1,45 +1,44 @@ package mouda.backend.security; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; -import mouda.backend.config.DatabaseCleaner; -import mouda.backend.member.domain.Member; -import mouda.backend.member.repository.MemberRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import mouda.backend.config.DatabaseCleaner; +import mouda.backend.fixture.MemberFixture; +import mouda.backend.member.domain.Member; +import mouda.backend.member.repository.MemberRepository; + @SpringBootTest class JwtProviderTest { - @Autowired - JwtProvider jwtProvider; + @Autowired + JwtProvider jwtProvider; - @Autowired - MemberRepository memberRepository; + @Autowired + MemberRepository memberRepository; - @Autowired - private DatabaseCleaner databaseCleaner; + @Autowired + private DatabaseCleaner databaseCleaner; - @AfterEach - void cleanUp() { - databaseCleaner.cleanUp(); - } + @AfterEach + void cleanUp() { + databaseCleaner.cleanUp(); + } - @DisplayName("토큰을 발급한다.") - @Test - void createToken() { - String nickname = "테바"; - Member member = Member.builder() - .nickname(nickname) - .build(); - Member savedMember = memberRepository.save(member); - String token = jwtProvider.createToken(savedMember); + @DisplayName("토큰을 발급한다.") + @Test + void createToken() { + Member member = MemberFixture.getTebah(); + Member savedMember = memberRepository.save(member); + String token = jwtProvider.createToken(savedMember); - String savedNickname = jwtProvider.extractNickname(token); + String savedNickname = jwtProvider.extractNickname(token); - assertThat(savedNickname).isEqualTo(nickname); - } + assertThat(savedNickname).isEqualTo(member.getNickname()); + } }