-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] 그리드 application.service 테스트 코드 작성
- Loading branch information
1 parent
fb049e2
commit 299e857
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/test/java/com/kusitms/samsion/common/util/GridTestUtils.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,13 @@ | ||
package com.kusitms.samsion.common.util; | ||
|
||
import com.kusitms.samsion.common.consts.TestConst; | ||
import com.kusitms.samsion.domain.grid.domain.entity.Grid; | ||
import com.kusitms.samsion.domain.user.domain.entity.User; | ||
|
||
public class GridTestUtils { | ||
|
||
public static Grid getMockGrid(User mockUser) { | ||
Grid mockGrid = new Grid(TestConst.TEST_GRID_IMG_URL, mockUser); | ||
return mockGrid; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/kusitms/samsion/domain/grid/application/service/GridGetUseCaseTest.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,51 @@ | ||
package com.kusitms.samsion.domain.grid.application.service; | ||
|
||
import com.kusitms.samsion.common.util.GridTestUtils; | ||
import com.kusitms.samsion.common.util.UserTestUtils; | ||
import com.kusitms.samsion.common.util.UserUtils; | ||
import com.kusitms.samsion.domain.grid.application.dto.response.GridInfoResponse; | ||
import com.kusitms.samsion.domain.grid.domain.entity.Grid; | ||
import com.kusitms.samsion.domain.grid.domain.service.GridQueryService; | ||
import com.kusitms.samsion.domain.user.domain.entity.User; | ||
import org.assertj.core.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.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@DisplayName("GridGetUseCase 테스트") | ||
public class GridGetUseCaseTest { | ||
|
||
@Mock | ||
UserUtils userUtils; | ||
@Mock | ||
GridQueryService gridQueryService; | ||
GridGetUseCase gridGetUseCase; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
gridGetUseCase = new GridGetUseCase(userUtils, gridQueryService); | ||
} | ||
|
||
@Test | ||
void 그리드를_조회한다() { | ||
//given | ||
User mockUser = UserTestUtils.getMockUser(); | ||
Grid mockGrid = GridTestUtils.getMockGrid(mockUser); | ||
given(userUtils.getUser()).willReturn(mockUser); | ||
given(gridQueryService.findGridByUserId(mockUser.getId())).willReturn(mockGrid); | ||
|
||
//when | ||
GridInfoResponse gridInfoResponse = gridGetUseCase.getGrid(); | ||
|
||
//then | ||
Assertions.assertThat(gridInfoResponse).isNotNull(); | ||
Assertions.assertThat(gridInfoResponse.getGridCheckList().size()).isEqualTo(59); | ||
Assertions.assertThat(gridInfoResponse.getGridImageUrl()).isEqualTo(mockGrid.getGridImageUrl()); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/kusitms/samsion/domain/grid/application/service/StampGetUseCaseTest.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,54 @@ | ||
package com.kusitms.samsion.domain.grid.application.service; | ||
|
||
import com.kusitms.samsion.common.slice.ListResponse; | ||
import com.kusitms.samsion.common.util.GridTestUtils; | ||
import com.kusitms.samsion.common.util.UserTestUtils; | ||
import com.kusitms.samsion.common.util.UserUtils; | ||
import com.kusitms.samsion.domain.grid.application.dto.response.StampResponse; | ||
import com.kusitms.samsion.domain.grid.domain.entity.Grid; | ||
import com.kusitms.samsion.domain.grid.domain.service.GridQueryService; | ||
import com.kusitms.samsion.domain.user.domain.entity.User; | ||
import org.assertj.core.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.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@DisplayName("StampGetUseCase 테스트") | ||
public class StampGetUseCaseTest { | ||
|
||
@Mock | ||
UserUtils userUtils; | ||
@Mock | ||
GridQueryService gridQueryService; | ||
StampGetUseCase stampGetUseCase; | ||
|
||
@BeforeEach | ||
void setUp() { stampGetUseCase = new StampGetUseCase(userUtils, gridQueryService); } | ||
|
||
@Test | ||
void 스탬프를_조회한다() { | ||
//given | ||
User mockUser = UserTestUtils.getMockUser(); | ||
Grid mockGrid = GridTestUtils.getMockGrid(mockUser); | ||
List<Grid> stampList = new ArrayList<>(); | ||
stampList.add(mockGrid); | ||
given(userUtils.getUser()).willReturn(mockUser); | ||
given(gridQueryService.findStampByUserId(mockUser.getId())).willReturn(stampList); | ||
|
||
//when | ||
ListResponse<StampResponse> stampResponseListResponse = stampGetUseCase.getStampList(); | ||
|
||
//then | ||
Assertions.assertThat(stampResponseListResponse).isNotNull(); | ||
Assertions.assertThat(stampResponseListResponse.getContent().get(0).getImageUrl()).isEqualTo(mockGrid.getGridImageUrl()); | ||
} | ||
} |