Skip to content

Rename AssertableMockMvc to MvcTester and review assertions structure #32712

@snicoll

Description

@snicoll

When we perform a request with MockMvc, we get a MvcResult that contains all the elements we need to assert that the processing of the request went well, such as:

  • The request and the response
  • What handler handled the request, and the ModelAndView if any
  • A resolved exception if the processing failed and an exception handled handled it

AssertableMvcResult expands on the latter by providing the unresolved exception as well, rather than throwing a checked exception as MockMvc does.

This class can then be fed to AssertJ and we can then navigate on various pieces of the result:

assertThat(result).hasStatusOk()
assertThat(result).body()...
assertThat(result).headers()...
assertThat(result).cookies()...
assertThat(result).model()...
assertThat(result).handler()...

There are two things we'd like to explore here:

  1. We want users to assign the result of perform so that they can run multiple asserts against the result. The name AssertableMvcResult is a bit off putting so we should consider renaming it
  2. If we did then we should investigate the possiblity of exposing a MvcResult than extending MvcResult. This may allow us to navigate to more structured part of the result, such as:
assertThat(result.body())...
assertThat(result.headers())...

paging @philwebb and @simonbasle who helped me brainstorm on this.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions