Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ› Fix: ๋กœ๊ทธ์ธ ์™„๋ฃŒ ์‹œ ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋˜๋„๋ก ์ˆ˜์ • #8

Merged
merged 6 commits into from
Sep 8, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<Member> expectedMembers = Arrays.asList(member1, member2);

// When
List<Member> 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<Member> 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<Member> byKoreaName = memberRepository.findByKoreaName("ํ™๊ธธ๋™");

// Then
assertEquals(byKoreaName.get(), member);
}

@Test
@DisplayName("findByKoreaName ์‹คํŒจ ํ…Œ์ŠคํŠธ")
void findByKoreaName_Failure() {
// Given

// When
Optional<Member> byKoreaName = memberRepository.findByKoreaName("ํ™๊ธธ๋™");

// Then
assertTrue(byKoreaName.isEmpty());
}
}
Loading