1. What is the main benefit of using Spring MVC test support to test a controller?
Why: Spring MVC test support lets you send mock requests to controllers and check the responses. No real web server is needed, so tests run fast.
2. What is the typical purpose of an HTTP PUT request?
Why:PUT is normally used to create a resource, or fully replace an existing one, at the URL that is given in the request.
3. Which HTTP header tells the server the format of the data sent in the request body?
Why:Content-Type describes the format of the request body, for example JSON or XML. In a test, you set it so the controller knows how to read the body.
4. Which HTTP header tells the server what response format the client wants?
Why: The Accept header tells the server which media types the client can handle in the response.
5. Which annotation tells Spring MVC to convert the request body into a method parameter?
Why:@RequestBody binds the whole request body to a method parameter, such as a Java object or a map.
6. Which component converts a JSON or XML request body into a Java object in Spring MVC?
Why: An HttpMessageConverter reads the request body and turns it into a Java object. It also writes Java objects back to the response body. A matching library for JSON or XML must be on the classpath.
7. Which media type is used for form data sent in a request body as name-value pairs?
Why: Form data is sent with the media type application/x-www-form-urlencoded, as name-value pairs.
8. Which request body is a correct form-encoded value for two fields: id with value 3, and content with value hello?
Why: In form encoding, each field is written as name=value, and the pairs are joined with &.
9. A controller method uses @RequestBody to receive all form fields. Which parameter type can hold them, including fields with several values?
@PutMapping("/{id}")
@ResponseBody
public String update(@RequestBody ??? formParams) { ... }
Why:MultiValueMap<String, String> stores each field name with a list of values, so it fits form data well.
10. What does the consumes attribute of @PutMapping do?
Why:consumes narrows the mapping so the method only handles requests whose Content-Type matches. This helps pick the right method for JSON, XML or form data.
11. A client sends a request with a content type that no controller method accepts. Which HTTP status does Spring MVC usually return?
Why: When the request content type does not match what the handler methods accept, Spring MVC responds with 415 Unsupported Media Type.
12. Which annotation can load a web application context for a JUnit 5 Spring MVC test class?
Why:@SpringJUnitWebConfig loads a web application context for a JUnit 5 test. The test can then create mock request objects from that context.
13. Which Spring class gives you an AssertJ-style API to test MVC controllers without a running server?
Why:MockMvcTester is built on mock MVC support. It lets you send mock requests and check results with AssertJ assertions.
14. A controller method has @ResponseBody and returns a String. How does Spring MVC treat the returned value?
Why: With @ResponseBody, the returned value is written straight to the response body. It is not used as a view name. In a test, you can compare the response body text with the expected text.