Class ModelAndViewAssert
java.lang.Object
org.springframework.test.web.ModelAndViewAssert
A collection of assertions intended to simplify testing scenarios dealing
with Spring Web MVC 
ModelAndView objects.
Intended for use with JUnit 4 and TestNG. All assert*() methods
throw AssertionErrors.
- Since:
- 2.5
- Author:
- Sam Brannen, Alef Arendsen, Bram Smeets
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T> TassertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) Checks whether the model value under the givenmodelNameexists and checks its type, based on theexpectedType.static voidassertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) Compare each individual entry in a list, without first sorting the lists.static voidassertModelAttributeAvailable(ModelAndView mav, String modelName) Assert whether a model attribute is available.static voidassertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) Compare a givenexpectedValueto the value from the model bound under the givenmodelName.static voidassertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) Inspect theexpectedModelto see if all elements in the model appear and are equal.static voidassertSortAndCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList, Comparator comparator) Compare each individual entry in a list after having sorted both lists (optionally using a comparator).static voidassertViewName(ModelAndView mav, String expectedName) Check to see if the view name in the ModelAndView matches the givenexpectedName.
- 
Constructor Details- 
ModelAndViewAssertpublic ModelAndViewAssert()
 
- 
- 
Method Details- 
assertAndReturnModelAttributeOfTypepublic static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) Checks whether the model value under the givenmodelNameexists and checks its type, based on theexpectedType. If the model entry exists and the type matches, the model value is returned.- Parameters:
- mav- the ModelAndView to test against (never- null)
- modelName- name of the object to add to the model (never- null)
- expectedType- expected type of the model value
- Returns:
- the model value
 
- 
assertCompareListModelAttributepublic static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) Compare each individual entry in a list, without first sorting the lists.- Parameters:
- mav- the ModelAndView to test against (never- null)
- modelName- name of the object to add to the model (never- null)
- expectedList- the expected list
 
- 
assertModelAttributeAvailableAssert whether a model attribute is available.- Parameters:
- mav- the ModelAndView to test against (never- null)
- modelName- name of the object to add to the model (never- null)
 
- 
assertModelAttributeValuepublic static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) Compare a givenexpectedValueto the value from the model bound under the givenmodelName.- Parameters:
- mav- the ModelAndView to test against (never- null)
- modelName- name of the object to add to the model (never- null)
- expectedValue- the model value
 
- 
assertModelAttributeValuesInspect theexpectedModelto see if all elements in the model appear and are equal.- Parameters:
- mav- the ModelAndView to test against (never- null)
- expectedModel- the expected model
 
- 
assertSortAndCompareListModelAttributepublic static void assertSortAndCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList, Comparator comparator) Compare each individual entry in a list after having sorted both lists (optionally using a comparator).- Parameters:
- mav- the ModelAndView to test against (never- null)
- modelName- name of the object to add to the model (never- null)
- expectedList- the expected list
- comparator- the comparator to use (may be- null). If not specifying the comparator, both lists will be sorted not using any comparator.
 
- 
assertViewNameCheck to see if the view name in the ModelAndView matches the givenexpectedName.- Parameters:
- mav- the ModelAndView to test against (never- null)
- expectedName- the name of the model value
 
 
-