From 7ae3df8911ed621103946ca4c758316ee846a699 Mon Sep 17 00:00:00 2001 From: Uno Kim Date: Sat, 25 Jun 2022 13:12:20 +0900 Subject: [PATCH] =?UTF-8?q?#56=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 | 17 ++++++++++++----- .../controller/MainControllerTest.java | 11 ++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java b/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java index 4fd95e5..0fcd35b 100644 --- a/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java +++ b/src/test/java/com/fastcampus/projectboard/controller/AuthControllerTest.java @@ -1,26 +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.WebMvcTest; +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 org.springframework.test.web.servlet.result.MockMvcResultHandlers; +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.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @DisplayName("View 컨트롤러 - 인증") -@Import(SecurityConfig.class) +@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; } @@ -34,8 +40,9 @@ public void givenNothing_whenTryingToLogIn_thenReturnsLogInView() throws Excepti // When & Then mvc.perform(get("/login")) .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)) - .andDo(MockMvcResultHandlers.print()); + .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)); + then(articleService).shouldHaveNoInteractions(); + then(paginationService).shouldHaveNoInteractions(); } } diff --git a/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java b/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java index 4593a42..1c54c7e 100644 --- a/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java +++ b/src/test/java/com/fastcampus/projectboard/controller/MainControllerTest.java @@ -1,17 +1,18 @@ package com.fastcampus.projectboard.controller; -import com.fastcampus.projectboard.config.SecurityConfig; +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.*; -@Import(SecurityConfig.class) +@DisplayName("View 루트 컨트롤러") +@Import(TestSecurityConfig.class) @WebMvcTest(MainController.class) class MainControllerTest { @@ -21,6 +22,7 @@ public MainControllerTest(@Autowired MockMvc mvc) { this.mvc = mvc; } + @DisplayName("[view][GET] 루트 페이지 -> 게시글 리스트 (게시판) 페이지 Redirection") @Test void givenNothing_whenRequestingRootPage_thenRedirectsToArticlesPage() throws Exception { // Given @@ -29,8 +31,7 @@ void givenNothing_whenRequestingRootPage_thenRedirectsToArticlesPage() throws Ex mvc.perform(get("/")) .andExpect(status().isOk()) .andExpect(view().name("forward:/articles")) - .andExpect(forwardedUrl("/articles")) - .andDo(MockMvcResultHandlers.print()); + .andExpect(forwardedUrl("/articles")); } }