-
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.
#92 [feat] : EntertainmentApplicationService 단위 테스트 코드를 작성한다
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...java/kusitms/backend/stadium/application/service/EntertainmentApplicationServiceTest.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package kusitms.backend.stadium.application.service; | ||
|
||
import kusitms.backend.global.exception.CustomException; | ||
import kusitms.backend.stadium.application.EntertainmentApplicationService; | ||
import kusitms.backend.stadium.application.StadiumApplicationService; | ||
import kusitms.backend.stadium.application.dto.response.GetEntertainmentsResponseDto; | ||
import kusitms.backend.stadium.domain.model.Stadium; | ||
import kusitms.backend.stadium.status.EntertainmentErrorStatus; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class EntertainmentApplicationServiceTest { | ||
|
||
@InjectMocks | ||
private EntertainmentApplicationService service; | ||
|
||
@Mock | ||
private StadiumApplicationService stadiumApplicationService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
/** | ||
* 정상적인 스타디움 이름과 boundary 값으로 즐길거리 리스트를 성공적으로 가져오는 테스트. | ||
*/ | ||
@Test | ||
void testGetSuitableEntertainments_Success() { | ||
// Given | ||
String stadiumName = "잠실종합운동장"; | ||
String boundary = "내부"; | ||
Stadium stadium = mock(Stadium.class); | ||
when(stadiumApplicationService.findStadiumByName(stadiumName)).thenReturn(stadium); | ||
when(stadium.getEntertainments()).thenReturn(List.of()); | ||
|
||
// When | ||
GetEntertainmentsResponseDto result = service.getSuitableEntertainments(stadiumName, boundary); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertEquals(0, result.entertainments().size()); | ||
} | ||
|
||
/** | ||
* 유효하지 않은 boundary 값으로 예외를 발생시키는 테스트. | ||
*/ | ||
@Test | ||
void testGetSuitableEntertainments_InvalidBoundary() { | ||
// Given | ||
String stadiumName = "잠실종합운동장"; | ||
String invalidBoundary = "잘못된값"; | ||
Stadium stadium = mock(Stadium.class); | ||
|
||
// When | ||
when(stadiumApplicationService.findStadiumByName(stadiumName)).thenReturn(stadium); | ||
|
||
// Then | ||
CustomException exception = assertThrows(CustomException.class, () -> | ||
service.getSuitableEntertainments(stadiumName, invalidBoundary)); | ||
assertEquals(EntertainmentErrorStatus._BAD_REQUEST_BOUNDARY, exception.getErrorCode()); | ||
} | ||
} |