-
Notifications
You must be signed in to change notification settings - Fork 1
[WTH-40] 캘린터 테스트 코드 작성 (Repository, Service) #221
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
base: develop
Are you sure you want to change the base?
The head ref may contain hidden characters: "WTH-40-Weeth-\uCE98\uB9B0\uD130-\uD14C\uC2A4\uD2B8-\uCF54\uB4DC-\uC791\uC131"
Changes from all commits
c2fbff4
f88ce86
566bfdd
e3d8124
18a5164
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package leets.weeth.config; | ||
|
|
||
| import org.springframework.boot.test.context.TestConfiguration; | ||
| import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.testcontainers.mysql.MySQLContainer; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| @TestConfiguration | ||
| public class TestContainersConfig { | ||
| private static final String MYSQL_IMAGE = "mysql:8.0.41"; | ||
|
|
||
| @Bean | ||
| @ServiceConnection | ||
| public MySQLContainer mysqlContainer() { | ||
| return new MySQLContainer(DockerImageName.parse(MYSQL_IMAGE)) | ||
| .withReuse(true); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package leets.weeth.config; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.testcontainers.mysql.MySQLContainer; | ||
|
|
||
| import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
|
|
||
| @DataJpaTest | ||
| @Import(TestContainersConfig.class) | ||
| @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
| class TestContainersTest { | ||
| @Autowired | ||
| private MySQLContainer mysqlContainer; | ||
|
|
||
| @Test | ||
| void 설정파일로_주입된_컨테이너_정상_동작_테스트() { | ||
| assertThat(mysqlContainer).isNotNull(); | ||
| assertThat(mysqlContainer.isRunning()).isTrue(); | ||
| System.out.println("Container JDBC URL: " + mysqlContainer.getJdbcUrl()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package leets.weeth.domain.schedule.domain.repository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import leets.weeth.config.TestContainersConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import leets.weeth.domain.schedule.domain.entity.Event; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.BeforeEach; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.context.annotation.Import; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.LocalDateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @DataJpaTest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Import(TestContainersConfig.class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class EventRepositoryTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private EventRepository eventRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @BeforeEach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void setUp() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LocalDateTime now = LocalDateTime.now(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Event event1 = Event.builder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .title("Event 1") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .start(now.plusDays(1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .end(now.plusDays(2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .cardinal(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Event event2 = Event.builder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .title("Event 2") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .start(now.plusDays(3)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .end(now.plusDays(4)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .cardinal(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Event event3 = Event.builder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .title("Event 3") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .start(now.plusDays(5)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .end(now.plusDays(6)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .cardinal(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eventRepository.saveAll(List.of(event1, event2, event3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테스트 데이터 생성 방식을 개선하세요.
다음과 같이 개선하는 것을 권장합니다: @BeforeEach
void setUp() {
- LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.of(2024, 1, 1, 0, 0);
Event event1 = Event.builder()
.title("Event 1")
.start(now.plusDays(1))
.end(now.plusDays(2))
.cardinal(1)
.build();
Event event2 = Event.builder()
.title("Event 2")
.start(now.plusDays(3))
.end(now.plusDays(4))
.cardinal(1)
.build();
Event event3 = Event.builder()
.title("Event 3")
.start(now.plusDays(5))
.end(now.plusDays(6))
.cardinal(2)
.build();
eventRepository.saveAll(List.of(event1, event2, event3));
}또한 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testFindByStartLessThanEqualAndEndGreaterThanEqualOrderByStartAsc() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LocalDateTime start = LocalDateTime.now().plusDays(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LocalDateTime end = LocalDateTime.now().plusDays(7); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Event> events = eventRepository.findByStartLessThanEqualAndEndGreaterThanEqualOrderByStartAsc(end, start); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(events) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .hasSize(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .extracting(Event::getTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .containsExactly("Event 2", "Event 3"); // 순서와 구성이 모두 일치하는지 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain쿼리 메서드 호출의 파라미터 순서와 테스트 로직을 검증하세요. 메서드 호출 시 다음 사항들을 확인해주세요:
setUp에서 정의한 고정된 Length of output: 169 🏁 Script executed: #!/bin/bash
# Find and display the EventRepositoryTest class, particularly setUp and the test method
rg -n "class EventRepositoryTest" -A 100 src/test/java/leets/weeth/domain/schedule/domain/repository/ | head -150Length of output: 7338 🏁 Script executed: #!/bin/bash
# Search for the method definition in repository
rg -n "findByStartLessThanEqualAndEndGreaterThanEqualOrderByStartAsc" . -A 2Length of output: 3076 메서드 파라미터 순서 불일치와 테스트 로직 오류를 수정하세요. EventRepository와 MeetingRepository의 메서드 파라미터 순서가 서로 다릅니다:
그런데 두 서비스 모두 또한 테스트 예상 결과가 잘못되었습니다: setUp의 Event 1 (start=now+1, end=now+2)은 쿼리 조건 권장 사항:
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testFindAllByCardinal() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int cardinal = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Event> events = eventRepository.findAllByCardinal(cardinal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(events) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .hasSize(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .extracting(Event::getTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .containsExactly("Event 1", "Event 2"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain쿼리 결과 순서에 대한 가정을 검증하세요.
Spring Data JPA는 메서드명에
assertThat(events)
.hasSize(2)
.extracting(Event::getTitle)
- .containsExactly("Event 1", "Event 2");
+ .containsExactlyInAnyOrder("Event 1", "Event 2");쿼리 메서드의 실제 구현을 확인하여 정렬이 보장되는지 검증해주세요. Length of output: 893 🏁 Script executed: #!/bin/bash
# Locate the EventRepository file
fd "EventRepository\." -e java -e ktLength of output: 80 🏁 Script executed: #!/bin/bash
# Find test setup - look for @BeforeEach or test data initialization in EventRepositoryTest
fd "EventRepositoryTest" -e javaLength of output: 84 Length of output: 472 🏁 Script executed: #!/bin/bash
# Get the full test file to see setup and all test methods
cat src/test/java/leets/weeth/domain/schedule/domain/repository/EventRepositoryTest.javaLength of output: 2544 Length of output: 168 🏁 Script executed: #!/bin/bash
# Get Event entity definition
cat src/main/java/leets/weeth/domain/schedule/domain/entity/Event.javaLength of output: 555 Length of output: 168 🏁 Script executed: #!/bin/bash
# Get Schedule entity definition
cat src/main/java/leets/weeth/domain/schedule/domain/entity/Schedule.javaLength of output: 1406 쿼리 메서드의 정렬 순서 미지정으로 인한 테스트 불안정성 문제 확인됨
문제점:
해결 방안 (둘 중 선택):
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package leets.weeth.domain.schedule.domain.repository; | ||
|
|
||
| import leets.weeth.config.TestContainersConfig; | ||
| import leets.weeth.domain.schedule.domain.entity.Meeting; | ||
| import leets.weeth.domain.schedule.domain.entity.enums.MeetingStatus; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @DataJpaTest | ||
| @Import(TestContainersConfig.class) | ||
| @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
| class MeetingRepositoryTest { | ||
| @Autowired | ||
| private MeetingRepository meetingRepository; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| Meeting meeting1 = Meeting.builder() | ||
| .title("Meeting 1") | ||
| .start(LocalDateTime.now().plusDays(1)) | ||
| .end(LocalDateTime.now().plusDays(2)) | ||
| .code(1111) | ||
| .cardinal(1) | ||
| .meetingStatus(MeetingStatus.OPEN) | ||
| .build(); | ||
|
Comment on lines
+27
to
+34
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 픽스쳐로 간단하게 할수있을거같아요! |
||
|
|
||
| Meeting meeting2 = Meeting.builder() | ||
| .title("Meeting 2") | ||
| .start(LocalDateTime.now().plusDays(3)) | ||
| .end(LocalDateTime.now().plusDays(4)) | ||
| .code(2222) | ||
| .cardinal(1) | ||
| .meetingStatus(MeetingStatus.OPEN) | ||
| .build(); | ||
|
|
||
| Meeting meeting3 = Meeting.builder() | ||
| .title("Meeting 3") | ||
| .start(LocalDateTime.now().plusDays(5)) | ||
| .end(LocalDateTime.now().plusDays(6)) | ||
| .code(3333) | ||
| .cardinal(2) | ||
| .meetingStatus(MeetingStatus.CLOSE) | ||
| .build(); | ||
|
|
||
| meetingRepository.saveAll(java.util.List.of(meeting1, meeting2, meeting3)); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void findByStartLessThanEqualAndEndGreaterThanEqualOrderByStartAsc() { | ||
| // given | ||
| LocalDateTime start = LocalDateTime.now().plusDays(1); | ||
| LocalDateTime end = LocalDateTime.now().plusDays(4); | ||
|
|
||
| // when | ||
| List<Meeting> meetings = meetingRepository.findByStartLessThanEqualAndEndGreaterThanEqualOrderByStartAsc(end, start); | ||
|
|
||
| // then | ||
| assertThat(meetings) | ||
| .hasSize(2) | ||
| .extracting(Meeting::getTitle) | ||
| .containsExactly("Meeting 1", "Meeting 2"); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의도나 명확성이 잘 보이게끔 설계된 코드로 보입니다! |
||
|
|
||
| @Test | ||
| void findAllByCardinalOrderByStartAsc() { | ||
| // given | ||
| int cardinal = 1; | ||
|
|
||
| // when | ||
| List<Meeting> meetings = meetingRepository.findAllByCardinalOrderByStartAsc(cardinal); | ||
|
|
||
| // then | ||
| assertThat(meetings) | ||
| .hasSize(2) | ||
| .extracting(Meeting::getTitle) | ||
| .containsExactly("Meeting 1", "Meeting 2"); | ||
| } | ||
|
|
||
| @Test | ||
| void findAllByCardinalOrderByStartDesc() { | ||
| // given | ||
| int cardinal = 1; | ||
|
|
||
| // when | ||
| List<Meeting> meetings = meetingRepository.findAllByCardinalOrderByStartDesc(cardinal); | ||
|
|
||
| // then | ||
| assertThat(meetings) | ||
| .hasSize(2) | ||
| .extracting(Meeting::getTitle) | ||
| .containsExactly("Meeting 2", "Meeting 1"); | ||
| } | ||
|
|
||
| @Test | ||
| void findAllByCardinal() { | ||
| // given | ||
| int cardinal = 1; | ||
|
|
||
| // when | ||
| List<Meeting> meetings = meetingRepository.findAllByCardinal(cardinal); | ||
|
|
||
| // then | ||
| assertThat(meetings) | ||
| .hasSize(2) | ||
| .extracting(Meeting::getTitle) | ||
| .containsExactlyInAnyOrder("Meeting 1", "Meeting 2"); | ||
| } | ||
|
|
||
| @Test | ||
| void findAllByMeetingStatusAndEndBeforeOrderByEndAsc() { | ||
| // given | ||
| MeetingStatus status = MeetingStatus.OPEN; | ||
|
|
||
| // when | ||
| List<Meeting> meetings = meetingRepository.findAllByMeetingStatusAndEndBeforeOrderByEndAsc(status, LocalDateTime.now().plusDays(5)); | ||
|
|
||
| // then | ||
| assertThat(meetings) | ||
| .hasSize(2) | ||
| .extracting(Meeting::getTitle) | ||
| .containsExactly("Meeting 1", "Meeting 2"); | ||
|
|
||
| assertThat(meetings) | ||
| .extracting(Meeting::getMeetingStatus) | ||
| .containsOnly(MeetingStatus.OPEN) | ||
| .doesNotContain(MeetingStatus.CLOSE); | ||
| } | ||
|
|
||
| @Test | ||
| void findAllByOrderByStartDesc() { | ||
| // when | ||
| List<Meeting> meetings = meetingRepository.findAllByOrderByStartDesc(); | ||
|
|
||
| // then | ||
| assertThat(meetings) | ||
| .hasSize(3) | ||
| .extracting(Meeting::getTitle) | ||
| .containsExactly("Meeting 3", "Meeting 2", "Meeting 1"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package leets.weeth.domain.schedule.domain.service; | ||
|
|
||
| import leets.weeth.domain.schedule.application.exception.EventNotFoundException; | ||
| import leets.weeth.domain.schedule.application.mapper.ScheduleMapper; | ||
| import leets.weeth.domain.schedule.domain.entity.Event; | ||
| import leets.weeth.domain.schedule.domain.repository.EventRepository; | ||
| import leets.weeth.domain.schedule.test.fixture.ScheduleTestFixture; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class EventGetServiceTest { | ||
|
|
||
| @Mock | ||
| private EventRepository eventRepository; | ||
|
|
||
| @Mock | ||
| private ScheduleMapper scheduleMapper; | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ScheduleMapper 이녀석은 위 파일에서 사용하지 않는 것 같은데 ... 작성하신 이유가 있을까요!? |
||
| @InjectMocks | ||
| private EventGetService eventGetService; | ||
|
|
||
| private Event testEvent; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 친구만 Mock이 아닌 일반 객체로 만든 이유가 있을까요!? 궁금합니다. |
||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| testEvent = ScheduleTestFixture.createEvent(); | ||
| } | ||
|
|
||
| @Test | ||
| void testFind() { | ||
| // given | ||
| when(eventRepository.findById(1L)) | ||
| .thenReturn(Optional.of(testEvent)); | ||
|
|
||
| // when | ||
| Event event = eventGetService.find(1L); | ||
|
|
||
| // then | ||
| assertThat(event).isEqualTo(testEvent); | ||
| verify(eventRepository).findById(1L); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindNotFound() { | ||
| // given | ||
| Long id = 999L; | ||
| when(eventRepository.findById(id)).thenReturn(Optional.empty()); | ||
|
|
||
| // when & then | ||
| // 이벤트가 존재하지 않을 때 예외가 발생하는지 확인 | ||
| assertThatThrownBy(() -> eventGetService.find(id)) | ||
| .isInstanceOf(EventNotFoundException.class); | ||
| verify(eventRepository).findById(id); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setUp 내부 객체 생성 로직도 , Fixture로 처리할 수 있지 않을까요!? 😲❔