-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FU-191 refactor: 멤버 객체를 setUp()메서드를 통해 각 테스트에 제공하도록 변경
- Loading branch information
1 parent
c722a07
commit ddc7e6c
Showing
1 changed file
with
19 additions
and
32 deletions.
There are no files selected for viewing
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,63 +1,58 @@ | ||
package com.foru.freebe.schedule.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.time.LocalTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
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.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import com.foru.freebe.member.entity.Member; | ||
import com.foru.freebe.member.entity.Role; | ||
import com.foru.freebe.member.repository.MemberRepository; | ||
import com.foru.freebe.schedule.dto.BaseScheduleDto; | ||
import com.foru.freebe.schedule.entity.BaseSchedule; | ||
import com.foru.freebe.schedule.entity.DayOfWeek; | ||
import com.foru.freebe.schedule.entity.OperationStatus; | ||
import com.foru.freebe.schedule.repository.BaseScheduleRepository; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class BaseScheduleServiceTest { | ||
|
||
@Mock | ||
private BaseScheduleRepository baseScheduleRepository; | ||
|
||
@Mock | ||
private MemberRepository memberRepository; | ||
|
||
@InjectMocks | ||
private BaseScheduleService baseScheduleService; | ||
|
||
private Member photographer; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
photographer = Member.builder(1L, Role.PHOTOGRAPHER, "John Doe", "[email protected]", | ||
"1234567890").build(); | ||
} | ||
|
||
@DisplayName("기본 단일스케줄 시간 변경") | ||
@Test | ||
void updateScheduleForTime() { | ||
// given | ||
Member photographer = createNewMember(); | ||
|
||
BaseSchedule existingBaseSchedule = new BaseSchedule(photographer, DayOfWeek.FRIDAY, LocalTime.of(9, 0, 0), | ||
BaseSchedule existingBaseSchedule = new BaseSchedule(photographer, DayOfWeek.FRIDAY, | ||
LocalTime.of(9, 0, 0), | ||
LocalTime.of(15, 0, 0), OperationStatus.ACTIVE); | ||
|
||
BaseScheduleDto baseScheduleDto = new BaseScheduleDto().builder() | ||
BaseScheduleDto baseScheduleDto = BaseScheduleDto.builder() | ||
.dayOfWeek(DayOfWeek.FRIDAY) | ||
.startTime(LocalTime.of(9, 0, 0)) | ||
.endTime(LocalTime.of(21, 0, 0)) | ||
.operationStatus(OperationStatus.ACTIVE) | ||
.build(); | ||
|
||
when(baseScheduleRepository.findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), photographer.getId())).thenReturn(existingBaseSchedule); | ||
when(baseScheduleRepository.findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), | ||
photographer.getId())).thenReturn(existingBaseSchedule); | ||
|
||
//when | ||
baseScheduleService.updateSchedule(baseScheduleDto, photographer); | ||
|
@@ -67,26 +62,27 @@ void updateScheduleForTime() { | |
Assertions.assertEquals(LocalTime.of(21, 0), existingBaseSchedule.getEndTime()); | ||
Assertions.assertEquals(OperationStatus.ACTIVE, existingBaseSchedule.getOperationStatus()); | ||
|
||
verify(baseScheduleRepository, times(1)).findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), photographer.getId()); | ||
verify(baseScheduleRepository, times(1)) | ||
.findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), photographer.getId()); | ||
} | ||
|
||
@DisplayName("기본 단일스케줄 활성화 변경") | ||
@Test | ||
void updateScheduleForActivation() { | ||
// when | ||
Member photographer = createNewMember(); | ||
|
||
BaseSchedule existingBaseSchedule = new BaseSchedule(photographer, DayOfWeek.FRIDAY, LocalTime.of(9, 0, 0), | ||
BaseSchedule existingBaseSchedule = new BaseSchedule(photographer, DayOfWeek.FRIDAY, | ||
LocalTime.of(9, 0, 0), | ||
LocalTime.of(15, 0, 0), OperationStatus.ACTIVE); | ||
|
||
BaseScheduleDto baseScheduleDto = new BaseScheduleDto().builder() | ||
BaseScheduleDto baseScheduleDto = BaseScheduleDto.builder() | ||
.dayOfWeek(DayOfWeek.FRIDAY) | ||
.startTime(LocalTime.of(9, 0, 0)) | ||
.endTime(LocalTime.of(15, 0, 0)) | ||
.operationStatus(OperationStatus.INACTIVE) | ||
.build(); | ||
|
||
when(baseScheduleRepository.findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), photographer.getId())).thenReturn(existingBaseSchedule); | ||
when(baseScheduleRepository.findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), | ||
photographer.getId())).thenReturn(existingBaseSchedule); | ||
|
||
// when | ||
baseScheduleService.updateSchedule(baseScheduleDto, photographer); | ||
|
@@ -99,11 +95,6 @@ void updateScheduleForActivation() { | |
verify(baseScheduleRepository, times(1)).findByDayOfWeekAndPhotographerId(baseScheduleDto.getDayOfWeek(), photographer.getId()); | ||
} | ||
|
||
private Member createNewMember() { | ||
return new Member(1L, Role.PHOTOGRAPHER, "John Doe", "[email protected]", | ||
"1234567890", "1980", "0724", "Male", "johndoe"); | ||
} | ||
|
||
private BaseScheduleDto createBaseScheduleDto(DayOfWeek dayOfWeek, LocalTime startTime, LocalTime endTime, OperationStatus operationStatus) { | ||
return BaseScheduleDto.builder() | ||
.dayOfWeek(dayOfWeek) | ||
|
@@ -112,8 +103,4 @@ private BaseScheduleDto createBaseScheduleDto(DayOfWeek dayOfWeek, LocalTime sta | |
.operationStatus(operationStatus) | ||
.build(); | ||
} | ||
|
||
|
||
|
||
|
||
} |