Package org.springframework.test.web.servlet.result

# Class ModelResultMatchers

java.lang.Object
org.springframework.test.web.servlet.result.ModelResultMatchers

public class ModelResultMatchers extends Object
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

Constructors
Modifier
Constructor
Description
`protected`
`ModelResultMatchers()`
Protected constructor.

## Method Summary

Modifier and Type
Method
Description
`ResultMatcher`
`attribute(String name, Object value)`
Assert a model attribute value.
`<T> ResultMatcher`
`attribute(String name, Matcher<? super T> matcher)`
Assert a model attribute value with the given Hamcrest `Matcher`.
`ResultMatcher`
`attributeDoesNotExist(String... names)`
Assert the given model attributes do not exist.
`ResultMatcher`
`attributeErrorCount(String name, int expectedCount)`
Assert the given model attribute(s) have errors.
`ResultMatcher`
`attributeExists(String... names)`
Assert the given model attributes exist.
`ResultMatcher`
`attributeHasErrors(String... names)`
Assert the given model attribute(s) have errors.
`ResultMatcher`
`attributeHasFieldErrorCode(String name, String fieldName, String error)`
Assert a field error code for a model attribute using exact String match.
`ResultMatcher`
`attributeHasFieldErrorCode(String name, String fieldName, Matcher<? super String> matcher)`
Assert a field error code for a model attribute using a `Matcher`.
`ResultMatcher`
`attributeHasFieldErrors(String name, String... fieldNames)`
Assert the given model attribute field(s) have errors.
`ResultMatcher`
`attributeHasNoErrors(String... names)`
Assert the given model attribute(s) do not have errors.
`ResultMatcher`
`errorCount(int expectedCount)`
Assert the total number of errors in the model.
`ResultMatcher`
`hasErrors()`
Assert the model has errors.
`ResultMatcher`
`hasNoErrors()`
Assert the model has no errors.
`ResultMatcher`
`size(int size)`
Assert the number of model attributes.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ModelResultMatchers

protected ModelResultMatchers()
Protected constructor. Use `MockMvcResultMatchers.model()`.

## Method Details

### attribute

public <T> ResultMatcher attribute(String name, Matcher<? super T> matcher)
Assert a model attribute value with the given Hamcrest `Matcher`.

### attribute

public ResultMatcher attribute(String name, @Nullable Object value)
Assert a model attribute value.

### attributeExists

public ResultMatcher attributeExists(String... names)
Assert the given model attributes exist.

### attributeDoesNotExist

public ResultMatcher attributeDoesNotExist(String... names)
Assert the given model attributes do not exist.

### attributeErrorCount

public ResultMatcher attributeErrorCount(String name, int expectedCount)
Assert the given model attribute(s) have errors.

### attributeHasErrors

public ResultMatcher attributeHasErrors(String... names)
Assert the given model attribute(s) have errors.

### attributeHasNoErrors

public ResultMatcher attributeHasNoErrors(String... names)
Assert the given model attribute(s) do not have errors.

### attributeHasFieldErrors

public ResultMatcher attributeHasFieldErrors(String name, String... fieldNames)
Assert the given model attribute field(s) have errors.

### attributeHasFieldErrorCode

public ResultMatcher attributeHasFieldErrorCode(String name, String fieldName, String error)
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 a `Matcher`.

Since:
  4.1

### errorCount

public ResultMatcher errorCount(int expectedCount)
Assert the total number of errors in the model.

### hasErrors

public ResultMatcher hasErrors()
Assert the model has errors.

### hasNoErrors

public ResultMatcher hasNoErrors()
Assert the model has no errors.

### size

public ResultMatcher size(int size)
Assert the number of model attributes.