Skip to content

Commit

Permalink
[feat] 그리드 application.service 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
isprogrammingfun committed May 24, 2023
1 parent fb049e2 commit 299e857
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/java/com/kusitms/samsion/common/util/GridTestUtils.java
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;
}
}
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());
}
}
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());
}
}

0 comments on commit 299e857

Please sign in to comment.