Cant find the get() method in MockMvcResultHandlers

Viewed 2788

I have imported the following:

import org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;

... for a controller test in a Spring Boot project but I cannot find the perform(get(,,,,)) method.

Any suggestions?

2 Answers

Add comments.

import library

Import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;

Check this [link][1].


  [1]: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/MockMvc.html

The perform() method is a static method on: org.springframework.test.web.servlet.request.MockMvcRequestBuilders.

Here's the full signature:

public static MockHttpServletRequestBuilder get(URI uri) {
    return new MockHttpServletRequestBuilder(HttpMethod.GET, uri);
}

And it is used like so:

@Autowired
private MockMvc mockMvc;

mockMvc.perform(MockMvcRequestBuilders.get("/some/uri"))
    .andExpect(MockMvcResultMatchers.status().isOk());
Related