Skip to content

Commit

Permalink
#56 - 문제가 된 테스트 코드 발견 및 수정
Browse files Browse the repository at this point in the history
이 부분은 진작에 개발 끝나고 테스트를 완료했던 코드인데,
어느샌가 옛날 버전으로 돌아가 있다.
정확한 원인은 알 수 없으나, 복구하고 테스트 완료.
전체 테스트 통과함
  • Loading branch information
djkeh committed Jun 25, 2022
1 parent b1332ee commit 7ae3df8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -21,6 +22,7 @@ public MainControllerTest(@Autowired MockMvc mvc) {
this.mvc = mvc;
}

@DisplayName("[view][GET] 루트 페이지 -> 게시글 리스트 (게시판) 페이지 Redirection")
@Test
void givenNothing_whenRequestingRootPage_thenRedirectsToArticlesPage() throws Exception {
// Given
Expand All @@ -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"));
}

}

0 comments on commit 7ae3df8

Please sign in to comment.