Skip to content

Commit c1bf380

Browse files
committed
refactor(controller-test): ControllerTestSupport 리팩토링
- 컨트롤러 테스트시 print() 일괄 적용 - print()시 한글 깨짐 현상 해결
1 parent 18cd3d8 commit c1bf380

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/com/somemore/support/ControllerTestSupport.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package com.somemore.support;
22

33

4+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
5+
46
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import org.junit.jupiter.api.BeforeEach;
58
import org.springframework.beans.factory.annotation.Autowired;
69
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
710
import org.springframework.boot.test.context.SpringBootTest;
811
import org.springframework.test.context.ActiveProfiles;
912
import org.springframework.test.web.servlet.MockMvc;
13+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
14+
import org.springframework.web.context.WebApplicationContext;
15+
import org.springframework.web.filter.CharacterEncodingFilter;
1016

1117
@ActiveProfiles("test")
1218
@SpringBootTest
@@ -16,6 +22,17 @@ public abstract class ControllerTestSupport {
1622
@Autowired
1723
protected MockMvc mockMvc;
1824

25+
@Autowired
26+
private WebApplicationContext ctx;
27+
1928
@Autowired
2029
protected ObjectMapper objectMapper;
30+
31+
@BeforeEach
32+
public void setup() {
33+
this.mockMvc = MockMvcBuilders.webAppContextSetup(ctx)
34+
.addFilters(new CharacterEncodingFilter("UTF-8", true))
35+
.alwaysDo(print())
36+
.build();
37+
}
2138
}

0 commit comments

Comments
 (0)