public abstract class ModelAndViewAssert
extends java.lang.Object
ModelAndView
objects.
Intended for use with JUnit 4 and TestNG. All assert*()
methods
throw AssertionErrors
.
ModelAndView
Constructor and Description |
---|
ModelAndViewAssert() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
assertAndReturnModelAttributeOfType(ModelAndView mav,
java.lang.String modelName,
java.lang.Class<T> expectedType)
Checks whether the model value under the given
modelName
exists and checks it type, based on the expectedType . |
static void |
assertCompareListModelAttribute(ModelAndView mav,
java.lang.String modelName,
java.util.List expectedList)
Compare each individual entry in a list, without first sorting the lists.
|
static void |
assertModelAttributeAvailable(ModelAndView mav,
java.lang.String modelName)
Assert whether or not a model attribute is available.
|
static void |
assertModelAttributeValue(ModelAndView mav,
java.lang.String modelName,
java.lang.Object expectedValue)
Compare a given
expectedValue to the value from the model
bound under the given modelName . |
static void |
assertModelAttributeValues(ModelAndView mav,
java.util.Map<java.lang.String,java.lang.Object> expectedModel)
Inspect the
expectedModel to see if all elements in the
model appear and are equal. |
static void |
assertSortAndCompareListModelAttribute(ModelAndView mav,
java.lang.String modelName,
java.util.List expectedList,
java.util.Comparator comparator)
Compare each individual entry in a list after having sorted both lists
(optionally using a comparator).
|
static void |
assertViewName(ModelAndView mav,
java.lang.String expectedName)
Check to see if the view name in the ModelAndView matches the given
expectedName . |
public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, java.lang.String modelName, java.lang.Class<T> expectedType)
modelName
exists and checks it type, based on the expectedType
. If the
model entry exists and the type matches, the model value is returned.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 valuepublic static void assertCompareListModelAttribute(ModelAndView mav, java.lang.String modelName, java.util.List expectedList)
mav
- the ModelAndView to test against (never null
)modelName
- name of the object to add to the model (never null
)expectedList
- the expected listpublic static void assertModelAttributeAvailable(ModelAndView mav, java.lang.String modelName)
mav
- the ModelAndView to test against (never null
)modelName
- name of the object to add to the model (never null
)public static void assertModelAttributeValue(ModelAndView mav, java.lang.String modelName, java.lang.Object expectedValue)
expectedValue
to the value from the model
bound under the given modelName
.mav
- the ModelAndView to test against (never null
)modelName
- name of the object to add to the model (never null
)expectedValue
- the model valuepublic static void assertModelAttributeValues(ModelAndView mav, java.util.Map<java.lang.String,java.lang.Object> expectedModel)
expectedModel
to see if all elements in the
model appear and are equal.mav
- the ModelAndView to test against (never null
)expectedModel
- the expected modelpublic static void assertSortAndCompareListModelAttribute(ModelAndView mav, java.lang.String modelName, java.util.List expectedList, java.util.Comparator comparator)
mav
- the ModelAndView to test against (never null
)modelName
- name of the object to add to the model (never null
)expectedList
- the expected listcomparator
- the comparator to use (may be null
). If not
specifying the comparator, both lists will be sorted not using any comparator.public static void assertViewName(ModelAndView mav, java.lang.String expectedName)
expectedName
.mav
- the ModelAndView to test against (never null
)expectedName
- the name of the model value