Complete the code to annotate the test class for Spring MVC controller testing.
@[1](UserController.class) public class UserControllerTest { // test methods }
The @WebMvcTest annotation is used to test Spring MVC controllers specifically.
Complete the code to inject the MockMvc object for testing HTTP requests.
@Autowired
private [1] mockMvc;MockMvc is used to perform HTTP requests in Spring MVC tests.
Fix the error in the test method to perform a GET request and expect status 200.
mockMvc.perform(get("/users")) .andExpect([1].isOk());
The status() method is used to check the HTTP status in MockMvc tests.
Fill both blanks to mock a service bean and inject it into the test.
@[1] private UserService [2];
@MockBean creates a mock of the service bean, and userService is the variable name injected.
Fill all three blanks to perform a POST request with JSON content and expect a created status.
mockMvc.perform(post("/users") .contentType([1]) .content([2])) .andExpect(status().[3]());
Use MediaType.APPLICATION_JSON for JSON content type, provide JSON string as content, and expect HTTP 201 with isCreated().