-
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] : StadiumApplicationService 단위 테스트 코드를 작성한다
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/test/java/kusitms/backend/stadium/application/service/StadiumApplicationServiceTest.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,74 @@ | ||
package kusitms.backend.stadium.application.service; | ||
|
||
import kusitms.backend.global.exception.CustomException; | ||
import kusitms.backend.stadium.application.StadiumApplicationService; | ||
import kusitms.backend.stadium.application.dto.response.GetStadiumInfosResponseDto; | ||
import kusitms.backend.stadium.domain.enums.StadiumInfo; | ||
import kusitms.backend.stadium.domain.enums.StadiumStatusType; | ||
import kusitms.backend.stadium.domain.service.StadiumDomainService; | ||
import kusitms.backend.stadium.status.StadiumErrorStatus; | ||
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.when; | ||
|
||
class StadiumApplicationServiceTest { | ||
|
||
@InjectMocks | ||
private StadiumApplicationService stadiumApplicationService; | ||
|
||
@Mock | ||
private StadiumDomainService stadiumDomainService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
/** | ||
* 정상적인 경기장 이름으로 경기장 정보를 가져오는 테스트. | ||
*/ | ||
@Test | ||
void testGetStadiumInfos_Success() { | ||
// Given | ||
String stadiumName = "잠실종합운동장"; | ||
StadiumInfo stadiumInfo = StadiumInfo.LG_HOME; | ||
StadiumStatusType[] stadiumStatusTypes = new StadiumStatusType[0]; | ||
List<GetStadiumInfosResponseDto.ZoneInfo> zoneInfos = List.of(); | ||
|
||
when(stadiumDomainService.getStadiumInfoByName(stadiumName)).thenReturn(stadiumInfo); | ||
when(stadiumDomainService.getStatusTypesByName(stadiumName)).thenReturn(stadiumStatusTypes); | ||
when(stadiumDomainService.getZonesNameAndColorFromStadium(stadiumStatusTypes)).thenReturn(zoneInfos); | ||
|
||
// When | ||
GetStadiumInfosResponseDto result = stadiumApplicationService.getStadiumInfos(stadiumName); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertEquals(stadiumInfo.getImgUrl(), result.imgUrl()); | ||
assertEquals(0, result.zones().size()); | ||
} | ||
|
||
/** | ||
* 잘못된 경기장 이름으로 예외를 발생시키는 테스트. | ||
*/ | ||
@Test | ||
void testGetStadiumInfos_InvalidStadiumName() { | ||
// Given | ||
String invalidStadiumName = "잘못된경기장"; | ||
|
||
when(stadiumDomainService.getStadiumInfoByName(invalidStadiumName)) | ||
.thenThrow(new CustomException(StadiumErrorStatus._NOT_FOUND_STADIUM)); | ||
|
||
// When & Then | ||
CustomException exception = assertThrows(CustomException.class, () -> | ||
stadiumApplicationService.getStadiumInfos(invalidStadiumName)); | ||
assertEquals(StadiumErrorStatus._NOT_FOUND_STADIUM, exception.getErrorCode()); | ||
} | ||
} |