1. What is the primary purpose of MockMvcTester in Spring MVC testing?
Why: MockMvcTester is introduced to offer AssertJ support, enabling a fluent and type-safe assertion style for testing Spring MVC controllers.
2. Which Spring Framework version introduced MockMvcTester?
Why: MockMvcTester was introduced in Spring Framework 6.2 as part of the org.springframework.test.web.servlet.assertj package.
3. What is the main advantage of using AssertJ over Hamcrest for MockMvc assertions?
Why: AssertJ provides a fluent API that is driven by IDE auto-completion, making tests cleaner and more readable compared to Hamcrest.
4. How do you create a MockMvcTester for full Spring context support?
Why: Use MockMvcTester.from(wac) when you need full Spring context support, including filters and interceptors.
5. How do you create a MockMvcTester for standalone setup without a full Spring context?
Why: Use MockMvcTester.of(controller) for a lightweight standalone setup that skips context initialization.
6. What does MockMvcRequestBuilder implement, allowing it to be used with assertThat()?
Why: MockMvcRequestBuilder implements AssertJ's AssertProvider interface, so it can be passed directly to assertThat().
7. Which package contains MockMvcTester?
Why: MockMvcTester is part of the org.springframework.test.web.servlet.assertj package.
8. What is the benefit of using .exchange() in AssertJ-based MockMvc tests?
Why: Using .exchange() allows you to capture the MvcTestResult first, keeping request setup and assertions clearly separated.
9. In the AssertJ style, how do you assert that the response status is OK?
Why: The AssertJ-based MockMvcTester provides a fluent method .hasStatusOk() to assert the status is 200 OK.
10. How do you assert that the response body contains a specific text using AssertJ?
Why: AssertJ style uses .bodyText().contains("text") to verify the response body content.
11. What is the role of MvcTestResultAssert?
Why: MvcTestResultAssert is an implementation of AssertJ's Assert that provides assertion methods for the test result.
12. Why is MockMvcTester considered a fluent API?
Why: The fluent API style allows you to chain method calls in a readable, expressive manner, improving code clarity.
13. What does MockMvcTester wrap?
Why: MockMvcTester is the entry point that wraps an underlying MockMvc instance to provide AssertJ support.
14. Which annotations are used to enable full Spring context support with MockMvcTester?
Why: To use MockMvcTester.from(wac) with full context, you need @WebAppConfiguration and @ContextConfiguration.
15. What is the advantage of using MockMvcTester.of(controller) over MockMvcTester.from(wac)?
Why: MockMvcTester.of(controller) is a standalone setup that is faster since it does not initialize the full Spring context.
16. What does MockMvcRequestBuilder allow you to do?
Why: MockMvcRequestBuilder is used to construct HTTP requests using a fluent API before executing them.
17. What is the main difference between traditional Hamcrest-based MockMvc tests and AssertJ-based tests?
Why: AssertJ-based tests use assertThat() for assertions, providing a more fluent and consistent style compared to the Hamcrest andExpect() approach.
18. What is the purpose of assertThat(mockMvc.get().uri("/greeting")) in the example?
Why: Passing the request builder to assertThat() creates an assertion object that can then be used to verify the response.
19. Which of the following is NOT a benefit of the AssertJ style mentioned in the tutorial?
Why: The tutorial highlights that AssertJ eliminates the need for multiple static imports from MockMvcResultMatchers.
20. What does MvcTestResult represent?
Why: MvcTestResult encapsulates the outcome of a request execution, which can then be asserted using AssertJ methods.