@@ -52,14 +52,11 @@ public abstract class ModelAndViewAssert {
52
52
* @return the model value
53
53
*/
54
54
@ SuppressWarnings ("unchecked" )
55
- public static <T > T assertAndReturnModelAttributeOfType (ModelAndView mav , Object modelName , Class <T > expectedType )
56
- throws AssertionError {
57
-
55
+ public static <T > T assertAndReturnModelAttributeOfType (ModelAndView mav , String modelName , Class <T > expectedType ) {
58
56
assertCondition (mav != null , "ModelAndView is null" );
59
57
assertCondition (mav .getModel () != null , "Model is null" );
60
58
Object obj = mav .getModel ().get (modelName );
61
59
assertCondition (obj != null , "Model attribute with name '" + modelName + "' is null" );
62
-
63
60
assertCondition (expectedType .isAssignableFrom (obj .getClass ()), "Model attribute is not of expected type '" +
64
61
expectedType .getName () + "' but rather of type '" + obj .getClass ().getName () + "'" );
65
62
return (T ) obj ;
@@ -72,11 +69,9 @@ public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, Object
72
69
* <code>null</code>)
73
70
* @param expectedList the expected list
74
71
*/
75
- public static void assertCompareListModelAttribute (ModelAndView mav , Object modelName , List expectedList )
76
- throws AssertionError {
77
-
72
+ public static void assertCompareListModelAttribute (ModelAndView mav , String modelName , List expectedList ) {
78
73
assertCondition (mav != null , "ModelAndView is null" );
79
- List modelList = ( List ) assertAndReturnModelAttributeOfType (mav , modelName , List .class );
74
+ List modelList = assertAndReturnModelAttributeOfType (mav , modelName , List .class );
80
75
assertCondition (expectedList .size () == modelList .size (), "Size of model list is '" + modelList .size () +
81
76
"' while size of expected list is '" + expectedList .size () + "'" );
82
77
assertCondition (expectedList .equals (modelList ), "List in model under name '" + modelName +
@@ -89,7 +84,7 @@ public static void assertCompareListModelAttribute(ModelAndView mav, Object mode
89
84
* @param modelName name of the object to add to the model (never
90
85
* <code>null</code>)
91
86
*/
92
- public static void assertModelAttributeAvailable (ModelAndView mav , Object modelName ) throws AssertionError {
87
+ public static void assertModelAttributeAvailable (ModelAndView mav , String modelName ) {
93
88
assertCondition (mav != null , "ModelAndView is null" );
94
89
assertCondition (mav .getModel () != null , "Model is null" );
95
90
assertCondition (mav .getModel ().containsKey (modelName ), "Model attribute with name '" + modelName +
@@ -104,7 +99,7 @@ public static void assertModelAttributeAvailable(ModelAndView mav, Object modelN
104
99
* <code>null</code>)
105
100
* @param expectedValue the model value
106
101
*/
107
- public static void assertModelAttributeValue (ModelAndView mav , Object modelName , Object expectedValue ) {
102
+ public static void assertModelAttributeValue (ModelAndView mav , String modelName , Object expectedValue ) {
108
103
assertCondition (mav != null , "ModelAndView is null" );
109
104
Object modelValue = assertAndReturnModelAttributeOfType (mav , modelName , Object .class );
110
105
assertCondition (modelValue .equals (expectedValue ), "Model value with name '" + modelName +
@@ -156,7 +151,7 @@ public static void assertModelAttributeValues(ModelAndView mav, Map<String, Obje
156
151
*/
157
152
@ SuppressWarnings ("unchecked" )
158
153
public static void assertSortAndCompareListModelAttribute (
159
- ModelAndView mav , Object modelName , List expectedList , Comparator comparator ) {
154
+ ModelAndView mav , String modelName , List expectedList , Comparator comparator ) {
160
155
161
156
assertCondition (mav != null , "ModelAndView is null" );
162
157
List modelList = assertAndReturnModelAttributeOfType (mav , modelName , List .class );
@@ -214,17 +209,19 @@ private static void assertCondition(boolean condition, String message) {
214
209
}
215
210
}
216
211
217
- private static void appendNonMatchingSetsErrorMessage (Set <String > assertionSet , Set <String > incorrectSet , StringBuilder buf ) {
212
+ private static void appendNonMatchingSetsErrorMessage (
213
+ Set <String > assertionSet , Set <String > incorrectSet , StringBuilder sb ) {
214
+
218
215
Set <String > tempSet = new HashSet <String >();
219
216
tempSet .addAll (incorrectSet );
220
217
tempSet .removeAll (assertionSet );
221
218
222
219
if (tempSet .size () > 0 ) {
223
- buf .append ("Set has too many elements:\n " );
220
+ sb .append ("Set has too many elements:\n " );
224
221
for (Object element : tempSet ) {
225
- buf .append ('-' );
226
- buf .append (element );
227
- buf .append ('\n' );
222
+ sb .append ('-' );
223
+ sb .append (element );
224
+ sb .append ('\n' );
228
225
}
229
226
}
230
227
@@ -233,11 +230,11 @@ private static void appendNonMatchingSetsErrorMessage(Set<String> assertionSet,
233
230
tempSet .removeAll (incorrectSet );
234
231
235
232
if (tempSet .size () > 0 ) {
236
- buf .append ("Set is missing elements:\n " );
233
+ sb .append ("Set is missing elements:\n " );
237
234
for (Object element : tempSet ) {
238
- buf .append ('-' );
239
- buf .append (element );
240
- buf .append ('\n' );
235
+ sb .append ('-' );
236
+ sb .append (element );
237
+ sb .append ('\n' );
241
238
}
242
239
}
243
240
}
0 commit comments