Inflearn brand logo image

인프런 커뮤니티 질문&답변

에코노님의 프로필 이미지
에코노

작성한 질문수

스프링 부트 개념과 활용

스프링 웹 MVC 2부: HttpMessageConverters

test 파일을 실행시켰는데 이러한 type error가 왜 뜨는건가요?

작성

·

816

0

package econovation.demospringmvc.user;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultMatcher;

import static net.bytebuddy.matcher.ElementMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(SpringRunner.class)
@WebMvcTest(UserController.class)
public class UserControllerTest {

@Autowired
MockMvc mockMvc;

@Test
public void hello() throws Exception{
mockMvc.perform(get("/hello"))
.andExpect(
status().isOk())
.andExpect(
content().string("hello"));
}

@Test
public void createUser_JSON() throws Exception {
String userJson =
"";
mockMvc.perform(post("/users/create")
.contentType(MediaType.
APPLICATION_JSON_UTF8)
.accept(MediaType.
APPLICATION_JSON_UTF8)
.content(userJson))
.andExpect(
status().isOk())
.andExpect(
jsonPath("$.username",is(equalTo("keesun"))))
.andExpect(
jsonPath("$.password",is(equalTo("123"))));

}
}


Error:(40, 32) java: incompatible types:
org.springframework.test.web.servlet.result.
JsonPathResultMatchers cannot be converted to
org.springframework.test.web.servlet.ResultMatcher

답변 1

4

백기선님의 프로필 이미지
백기선
지식공유자

jsonPath 뒤에 사용한 is 라는 matcher 메소드가 ByteBuddy에서 온거네요. 그거 말고 hemcrest가 제공하는 Matchers에 들어있는걸 써보세요.

에코노님의 프로필 이미지
에코노

작성한 질문수

질문하기