작성
·
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에 들어있는걸 써보세요.