Skip to content

Commit

Permalink
Merge pull request #172 from nhnacademy-be4-ckin/fix/tag
Browse files Browse the repository at this point in the history
[FIX] Test Code Code smell 제거
  • Loading branch information
dduneon authored Mar 24, 2024
2 parents 6a986b7 + 58761d3 commit 1c71f51
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/test/java/store/ckin/api/tag/controller/TagControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
Expand All @@ -25,17 +27,12 @@
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc;
import store.ckin.api.common.domain.PageInfo;
Expand Down Expand Up @@ -82,7 +79,7 @@ void getAllTagListTest() throws Exception {
PagedResponse<List<TagResponseDto>> expected = new PagedResponse<>(allElements, pageInfo);
given(tagService.readTagList(PageRequest.of(0, 5))).willReturn(expected);

// when
// when then
mockMvc.perform(get("/api/tags")
.queryParam("page", "0")
.queryParam("size", "5")
Expand All @@ -109,6 +106,8 @@ void getAllTagListTest() throws Exception {
)

));

verify(tagService, times(1)).readTagList(any());
}

@Test
Expand Down Expand Up @@ -149,6 +148,7 @@ void saveTagTest_Failed_AlreadyExist() throws Exception {
).andDo(document("tag/saveTag/already-exist",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())));
verify(tagService, times(1)).createTag(any());
}


Expand All @@ -170,6 +170,7 @@ void saveTagTest_Success() throws Exception {
requestFields(
fieldWithPath("tagName").description("저장할 태그 이름")
)));
verify(tagService, times(1)).createTag(any());
}

@Test
Expand Down Expand Up @@ -210,6 +211,7 @@ void updateTagTest_Success() throws Exception {
fieldWithPath("tagId").description("태그 수정을 위한 태그 아이디"),
fieldWithPath("tagName").description("태그 수정을 위한 태그 이름")
)));
verify(tagService, times(1)).updateTag(any());
}

@Test
Expand Down Expand Up @@ -249,6 +251,7 @@ void deleteTagTest_Failed_TagNotFoundException() throws Exception {
.andDo(document("tag/deleteTag/not-found",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())));
verify(tagService, times(1)).deleteTag(any());
}

@Test
Expand All @@ -269,5 +272,6 @@ void deleteTagTest_Success() throws Exception {
requestFields(
fieldWithPath("tagId").description("삭제를 위한 태그 아이디")
)));
verify(tagService, times(1)).deleteTag(any());
}
}

0 comments on commit 1c71f51

Please sign in to comment.