diff --git a/.gitignore b/.gitignore index df991c9..6ed1871 100644 --- a/.gitignore +++ b/.gitignore @@ -174,6 +174,7 @@ gradle-app.setting # Java heap dump *.hprof + # End of https://www.toptal.com/developers/gitignore/api/java,gradle,macos,intellij+allauth.yml oauth.yml database.yml diff --git a/src/test/java/kaboo/kaboo_auth/repository/MemberRepositoryTest.java b/src/test/java/kaboo/kaboo_auth/repository/MemberRepositoryTest.java index 8142fd9..f436968 100644 --- a/src/test/java/kaboo/kaboo_auth/repository/MemberRepositoryTest.java +++ b/src/test/java/kaboo/kaboo_auth/repository/MemberRepositoryTest.java @@ -2,6 +2,8 @@ import static org.junit.jupiter.api.Assertions.*; +import java.util.Arrays; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -11,6 +13,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; +import kaboo.kaboo_auth.domain.Course; import kaboo.kaboo_auth.domain.entity.Member; @DataJpaTest @@ -60,4 +63,66 @@ void findByUsername_Failure() { // Then assertEquals(result, Optional.empty()); } + + @Test + @DisplayName("DB에 존재하는 classNum 찾을 때 findByClassNum method 테스트") + void findByClassNum_Success() { + // Given + Member member1 = Member.builder().englishName("Alice").classNum(1).build(); + Member member2 = Member.builder().englishName("Bob").classNum(1).build(); + + memberRepository.save(member1); + memberRepository.save(member2); + + List expectedMembers = Arrays.asList(member1, member2); + + // When + List byClassNum = memberRepository.findByClassNum(1); + + // Then + assertEquals(byClassNum.size(), 2, "리스트의 크기가 다릅니다."); + assertTrue(byClassNum.containsAll(expectedMembers), "리스트에 모든 멤버가 포함되어 있지 않습니다."); + } + + @Test + @DisplayName("DB에 존재하지 않는 classNum 찾을 때 findByClassNum method 테스트") + void findByClassNum_Failure() { + // Given + + // When + List byClassNum = memberRepository.findByClassNum(1); + + // Then + assertEquals(byClassNum.size(), 0); + } + + @Test + @DisplayName("findByKoreaName 성공 테스트") + void findByKoreaName_Success() { + // Given + Member member = Member.builder() + .koreaName("홍길동") + .classNum(1) + .course(Course.AI) + .build(); + memberRepository.save(member); + + // When + Optional byKoreaName = memberRepository.findByKoreaName("홍길동"); + + // Then + assertEquals(byKoreaName.get(), member); + } + + @Test + @DisplayName("findByKoreaName 실패 테스트") + void findByKoreaName_Failure() { + // Given + + // When + Optional byKoreaName = memberRepository.findByKoreaName("홍길동"); + + // Then + assertTrue(byKoreaName.isEmpty()); + } }