Skip to content

Commit

Permalink
test: 현재 시간 및 이벤트 객체 주입조건 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eckrin committed Aug 12, 2024
1 parent 41113d4 commit 48415a3
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ public class ArrivalEventMaxCountSchedulerTest extends ArrivalEventMaxCountSched
@Test
@DisplayName("이벤트 최대인원 세팅 스케줄러 동작 테스트 (성공 - Mysql에 데이터가 존재하는 경우)")
public void setArrivalEventCountSuccess_Data_Exists() {
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
LocalDateTime endOfDay = startOfDay.plusDays(1).minusNanos(1);
// given
EventType arrivalType = EventType.builder()
.id(1L)
.type("arrival")
.build();

when(eventTypeRepository.findById(1L))
.thenReturn(Optional.ofNullable(EventType.builder()
.id(1L)
.type("arrival")
.build())
);
when(eventRepository.findFirstByEventTypeAndStartAtBetween(any(), any(), any()))
.thenReturn(Optional.ofNullable(arrivalType));
when(eventRepository.findFirstByEventTypeAndStartAtBetween(arrivalType, startOfDay, endOfDay))
.thenReturn(Event.builder()
.id(1L)
.title("셀토스 선착순 이벤트")
.description("The 2025 셀토스 출시 기념 선착순 이벤트")
.startAt(LocalDateTime.now())
.endAt(LocalDateTime.now().plusDays(5))
.build()
);
when(eventRewardRepository.countByEvent(any()))
Expand All @@ -46,12 +54,13 @@ public void setArrivalEventCountSuccess_Data_Exists() {
@DisplayName("이벤트 최대인원 세팅 스케줄러 동작 테스트 (성공 - Mysql에 데이터가 존재하지 않는 경우)")
public void setArrivalEventCountSuccess_Data_Not_Exists() {
// given
EventType arrivalType = EventType.builder()
.id(1L)
.type("arrival")
.build();

when(eventTypeRepository.findById(1L))
.thenReturn(Optional.ofNullable(EventType.builder()
.id(1L)
.type("arrival")
.build())
);
.thenReturn(Optional.ofNullable(arrivalType));
when(eventRepository.findFirstByEventTypeAndStartAtBetween(any(), any(), any()))
.thenReturn(null);
when(eventRewardRepository.countByEvent(any()))
Expand Down

0 comments on commit 48415a3

Please sign in to comment.