Class ModelResultMatchers
java.lang.Object
org.springframework.test.web.servlet.result.ModelResultMatchers
Factory for assertions on the model.
An instance of this class is typically accessed via
MockMvcResultMatchers.model()
.
- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Sam Brannen
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAssert a model attribute value.<T> ResultMatcher
Assert a model attribute value with the given HamcrestMatcher
.attributeDoesNotExist
(String... names) Assert the given model attributes do not exist.attributeErrorCount
(String name, int expectedCount) Assert the given model attribute(s) have errors.attributeExists
(String... names) Assert the given model attributes exist.attributeHasErrors
(String... names) Assert the given model attribute(s) have errors.attributeHasFieldErrorCode
(String name, String fieldName, String error) Assert a field error code for a model attribute using exact String match.attributeHasFieldErrorCode
(String name, String fieldName, Matcher<? super String> matcher) Assert a field error code for a model attribute using aMatcher
.attributeHasFieldErrors
(String name, String... fieldNames) Assert the given model attribute field(s) have errors.attributeHasNoErrors
(String... names) Assert the given model attribute(s) do not have errors.errorCount
(int expectedCount) Assert the total number of errors in the model.Assert the model has errors.Assert the model has no errors.size
(int size) Assert the number of model attributes.
-
Constructor Details
-
ModelResultMatchers
protected ModelResultMatchers()Protected constructor. UseMockMvcResultMatchers.model()
.
-
-
Method Details
-
attribute
Assert a model attribute value with the given HamcrestMatcher
. -
attribute
Assert a model attribute value. -
attributeExists
Assert the given model attributes exist. -
attributeDoesNotExist
Assert the given model attributes do not exist. -
attributeErrorCount
Assert the given model attribute(s) have errors. -
attributeHasErrors
Assert the given model attribute(s) have errors. -
attributeHasNoErrors
Assert the given model attribute(s) do not have errors. -
attributeHasFieldErrors
Assert the given model attribute field(s) have errors. -
attributeHasFieldErrorCode
Assert a field error code for a model attribute using exact String match.- Since:
- 4.1
-
attributeHasFieldErrorCode
public ResultMatcher attributeHasFieldErrorCode(String name, String fieldName, Matcher<? super String> matcher) Assert a field error code for a model attribute using aMatcher
.- Since:
- 4.1
-
errorCount
Assert the total number of errors in the model. -
hasErrors
Assert the model has errors. -
hasNoErrors
Assert the model has no errors. -
size
Assert the number of model attributes.
-