From 3c59cd889ffc06c780b9b689460b4f94533a16d6 Mon Sep 17 00:00:00 2001 From: Lee Min Woo Date: Sun, 14 Aug 2022 23:58:17 +0900 Subject: [PATCH] =?UTF-8?q?#48=20-=20=EB=AC=B8=EC=A0=9C=EA=B0=80=20?= =?UTF-8?q?=EB=90=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B0=9C=EA=B2=AC=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이 부분은 진작에 개발 끝나고 테스트를 완료했던 코드인데, 어느샌가 옛날 버전으로 돌아가 있다. 정확한 원인은 알 수 없으나, 복구하고 테스트 완료. 전체 테스트 통과함 --- .../controller/AuthControllerTest.java | 28 ++++++++++++------- .../controller/MainControllerTest.java | 15 +++++----- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java b/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java index 916f3c5..795602b 100644 --- a/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java +++ b/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java @@ -1,27 +1,32 @@ package com.fastcampus.projectboard.controller; -import com.fastcampus.projectboard.config.SecurityConfig; +import com.fastcampus.projectboard.config.TestSecurityConfig; +import com.fastcampus.projectboard.service.ArticleService; +import com.fastcampus.projectboard.service.PaginationService; import org.junit.jupiter.api.DisplayName; - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; +import static org.mockito.BDDMockito.then; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @DisplayName("View 컨트롤러 - 인증") -@AutoConfigureMockMvc -@SpringBootTest +@Import(TestSecurityConfig.class) +@WebMvcTest(Void.class) public class AuthControllerTest { private final MockMvc mvc; + @MockBean private ArticleService articleService; + @MockBean private PaginationService paginationService; + public AuthControllerTest(@Autowired MockMvc mvc) { this.mvc = mvc; } @@ -30,11 +35,14 @@ public AuthControllerTest(@Autowired MockMvc mvc) { @DisplayName("[view][GET] 로그인 페이지 - 정상 호출") @Test public void givenNothing_whenTryingToLogIn_thenReturnsLogInView() throws Exception { - //Given + // Given - //When & Then + // When & Then mvc.perform(get("/login")) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)); + then(articleService).shouldHaveNoInteractions(); + then(paginationService).shouldHaveNoInteractions(); } -} + +} \ No newline at end of file diff --git a/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java b/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java index fc3eded..1e857e9 100644 --- a/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java +++ b/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java @@ -1,17 +1,17 @@ package com.fastcampus.projectboard.controller; import com.fastcampus.projectboard.config.TestSecurityConfig; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.context.annotation.Import; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -//@DisplayName("View 컨트롤러 - 게시글") +@DisplayName("View 루트 컨트롤러") @Import(TestSecurityConfig.class) @WebMvcTest(MainController.class) class MainControllerTest { @@ -22,15 +22,16 @@ public MainControllerTest(@Autowired MockMvc mvc) { this.mvc = mvc; } + @DisplayName("[view][GET] 루트 페이지 -> 게시글 리스트 (게시판) 페이지 Redirection") @Test void givenNothing_whenRequestingRootPage_thenRedirectsToArticlesPage() throws Exception { - //Given + // Given - //When & Then + // When & Then mvc.perform(get("/")) .andExpect(status().isOk()) .andExpect(view().name("forward:/articles")) - .andExpect(forwardedUrl("/articles")) - .andDo(MockMvcResultHandlers.print()); + .andExpect(forwardedUrl("/articles")); } -} + +} \ No newline at end of file