-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wonie
committed
Jan 24, 2025
1 parent
201ea93
commit ef6dc76
Showing
2 changed files
with
94 additions
and
94 deletions.
There are no files selected for viewing
40 changes: 20 additions & 20 deletions
40
...lendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package gg.calendar.api.user.utils.controller.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
public class TestFixtures { | ||
public static FortyTwoEventResponse createTestEvent(String name, String kind, LocalDateTime beginAt) { | ||
FortyTwoEventResponse response = new FortyTwoEventResponse() { | ||
}; // 익명 클래스 선언 끝 | ||
|
||
ReflectionTestUtils.setField(response, "name", name); | ||
ReflectionTestUtils.setField(response, "kind", kind); | ||
ReflectionTestUtils.setField(response, "beginAt", beginAt); | ||
ReflectionTestUtils.setField(response, "endAt", beginAt.plusHours(2)); | ||
ReflectionTestUtils.setField(response, "description", "Sample description"); | ||
|
||
return response; | ||
} | ||
} | ||
// package gg.calendar.api.user.utils.controller.response; | ||
// | ||
// import java.time.LocalDateTime; | ||
// | ||
// import org.springframework.test.util.ReflectionTestUtils; | ||
// | ||
// public class TestFixtures { | ||
// public static FortyTwoEventResponse createTestEvent(String name, String kind, LocalDateTime beginAt) { | ||
// FortyTwoEventResponse response = new FortyTwoEventResponse() { | ||
// }; // 익명 클래스 선언 끝 | ||
// | ||
// ReflectionTestUtils.setField(response, "name", name); | ||
// ReflectionTestUtils.setField(response, "kind", kind); | ||
// ReflectionTestUtils.setField(response, "beginAt", beginAt); | ||
// ReflectionTestUtils.setField(response, "endAt", beginAt.plusHours(2)); | ||
// ReflectionTestUtils.setField(response, "description", "Sample description"); | ||
// | ||
// return response; | ||
// } | ||
// } |
148 changes: 74 additions & 74 deletions
148
...lendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
package gg.calendar.api.user.utils.service; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
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 gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; | ||
import gg.calendar.api.user.utils.controller.response.TestFixtures; | ||
import gg.data.calendar.PublicSchedule; | ||
import gg.repo.calendar.PublicScheduleRepository; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class FortyTwoEventServiceTest { | ||
|
||
@Mock | ||
private FortyTwoEventApiClient fortyTwoEventClient; | ||
|
||
@Mock | ||
private PublicScheduleRepository publicScheduleRepository; | ||
|
||
@InjectMocks | ||
private FortyTwoEventService fortyTwoEventService; | ||
|
||
private FortyTwoEventResponse sample; | ||
private LocalDateTime now; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
now = LocalDateTime.now(); | ||
sample = createSampleEvent("Test", "event", now); | ||
} | ||
|
||
@Test | ||
@DisplayName("새로운 이벤트 저장 성공") | ||
void checkAndSaveEvent() { | ||
//given | ||
when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); | ||
when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(false); | ||
|
||
//when | ||
fortyTwoEventService.checkEvent(); | ||
|
||
//then | ||
verify(publicScheduleRepository, times(1)).save(any(PublicSchedule.class)); | ||
} | ||
|
||
@Test | ||
@DisplayName("이미 있는 이벤트 저장하지 않음") | ||
void checkAndNotSaveEvent() { | ||
//given | ||
when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); | ||
when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(true); | ||
|
||
//when | ||
fortyTwoEventService.checkEvent(); | ||
|
||
//then | ||
verify(publicScheduleRepository, times(0)).save(any(PublicSchedule.class)); | ||
} | ||
|
||
private FortyTwoEventResponse createSampleEvent(String name, String kind, LocalDateTime begin) { | ||
FortyTwoEventResponse testEvent = TestFixtures.createTestEvent(name, kind, begin); | ||
return testEvent; | ||
} | ||
} | ||
// package gg.calendar.api.user.utils.service; | ||
// | ||
// import static org.mockito.Mockito.*; | ||
// | ||
// import java.time.LocalDateTime; | ||
// import java.util.Arrays; | ||
// | ||
// import org.junit.jupiter.api.BeforeEach; | ||
// import org.junit.jupiter.api.DisplayName; | ||
// 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 gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; | ||
// import gg.calendar.api.user.utils.controller.response.TestFixtures; | ||
// import gg.data.calendar.PublicSchedule; | ||
// import gg.repo.calendar.PublicScheduleRepository; | ||
// | ||
// @ExtendWith(MockitoExtension.class) | ||
// class FortyTwoEventServiceTest { | ||
// | ||
// @Mock | ||
// private FortyTwoEventApiClient fortyTwoEventClient; | ||
// | ||
// @Mock | ||
// private PublicScheduleRepository publicScheduleRepository; | ||
// | ||
// @InjectMocks | ||
// private FortyTwoEventService fortyTwoEventService; | ||
// | ||
// private FortyTwoEventResponse sample; | ||
// private LocalDateTime now; | ||
// | ||
// @BeforeEach | ||
// void setUp() { | ||
// now = LocalDateTime.now(); | ||
// sample = createSampleEvent("Test", "event", now); | ||
// } | ||
// | ||
// @Test | ||
// @DisplayName("새로운 이벤트 저장 성공") | ||
// void checkAndSaveEvent() { | ||
// //given | ||
// when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); | ||
// when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(false); | ||
// | ||
// //when | ||
// fortyTwoEventService.checkEvent(); | ||
// | ||
// //then | ||
// verify(publicScheduleRepository, times(1)).save(any(PublicSchedule.class)); | ||
// } | ||
// | ||
// @Test | ||
// @DisplayName("이미 있는 이벤트 저장하지 않음") | ||
// void checkAndNotSaveEvent() { | ||
// //given | ||
// when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); | ||
// when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(true); | ||
// | ||
// //when | ||
// fortyTwoEventService.checkEvent(); | ||
// | ||
// //then | ||
// verify(publicScheduleRepository, times(0)).save(any(PublicSchedule.class)); | ||
// } | ||
// | ||
// private FortyTwoEventResponse createSampleEvent(String name, String kind, LocalDateTime begin) { | ||
// FortyTwoEventResponse testEvent = TestFixtures.createTestEvent(name, kind, begin); | ||
// return testEvent; | ||
// } | ||
// } |