类 ModelAndViewAssert


  • public abstract class ModelAndViewAssert
    extends Object
    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.

    从以下版本开始:
    2.5
    作者:
    Sam Brannen, Alef Arendsen, Bram Smeets
    另请参阅:
    ModelAndView
    • 方法详细资料

      • assertAndReturnModelAttributeOfType

        public static <T> T assertAndReturnModelAttributeOfType​(ModelAndView mav,
                                                                String modelName,
                                                                Class<T> expectedType)
        Checks whether the model value under the given 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 - 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
        返回:
        the model value
      • assertCompareListModelAttribute

        public static void assertCompareListModelAttribute​(ModelAndView mav,
                                                           String modelName,
                                                           List expectedList)
        Compare each individual entry in a list, without first sorting the lists.
        参数:
        mav - ModelAndView to test against (never null)
        modelName - name of the object to add to the model (never null)
        expectedList - the expected list
      • assertModelAttributeAvailable

        public static void assertModelAttributeAvailable​(ModelAndView mav,
                                                         String modelName)
        Assert whether or not a model attribute is available.
        参数:
        mav - ModelAndView to test against (never null)
        modelName - name of the object to add to the model (never null)
      • assertModelAttributeValue

        public static void assertModelAttributeValue​(ModelAndView mav,
                                                     String modelName,
                                                     Object expectedValue)
        Compare a given expectedValue to the value from the model bound under the given modelName.
        参数:
        mav - ModelAndView to test against (never null)
        modelName - name of the object to add to the model (never null)
        expectedValue - the model value
      • assertModelAttributeValues

        public static void assertModelAttributeValues​(ModelAndView mav,
                                                      Map<String,​Object> expectedModel)
        Inspect the expectedModel to see if all elements in the model appear and are equal.
        参数:
        mav - ModelAndView to test against (never null)
        expectedModel - the expected model
      • assertSortAndCompareListModelAttribute

        public 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).
        参数:
        mav - 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.
      • assertViewName

        public static void assertViewName​(ModelAndView mav,
                                          String expectedName)
        Check to see if the view name in the ModelAndView matches the given expectedName.
        参数:
        mav - ModelAndView to test against (never null)
        expectedName - the name of the model value