consistent use of model name Strings
This commit is contained in:
parent
e3cc9237c4
commit
c8e23290ca
|
@ -55,7 +55,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* @param expectedType expected type of the model value
|
||||
* @return the model value
|
||||
*/
|
||||
protected Object assertAndReturnModelAttributeOfType(ModelAndView mav, Object modelName, Class expectedType) {
|
||||
protected <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) {
|
||||
try {
|
||||
return ModelAndViewAssert.assertAndReturnModelAttributeOfType(mav, modelName, expectedType);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* <code>null</code>)
|
||||
* @param expectedList the expected list
|
||||
*/
|
||||
protected void assertCompareListModelAttribute(ModelAndView mav, Object modelName, List expectedList) {
|
||||
protected void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
|
||||
try {
|
||||
ModelAndViewAssert.assertCompareListModelAttribute(mav, modelName, expectedList);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
*/
|
||||
protected void assertModelAttributeAvailable(ModelAndView mav, Object modelName) {
|
||||
protected void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
|
||||
try {
|
||||
ModelAndViewAssert.assertModelAttributeAvailable(mav, modelName);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* <code>null</code>)
|
||||
* @param expectedValue the model value
|
||||
*/
|
||||
protected void assertModelAttributeValue(ModelAndView mav, Object modelName, Object expectedValue) {
|
||||
protected void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
|
||||
try {
|
||||
ModelAndViewAssert.assertModelAttributeValue(mav, modelName, expectedValue);
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* @param mav ModelAndView to test against (never <code>null</code>)
|
||||
* @param expectedModel the expected model
|
||||
*/
|
||||
protected void assertModelAttributeValues(ModelAndView mav, Map expectedModel) {
|
||||
protected void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) {
|
||||
try {
|
||||
ModelAndViewAssert.assertModelAttributeValues(mav, expectedModel);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
|
|||
* any comparator.
|
||||
*/
|
||||
protected void assertSortAndCompareListModelAttribute(
|
||||
ModelAndView mav, Object modelName, List expectedList, Comparator comparator) {
|
||||
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
|
||||
try {
|
||||
ModelAndViewAssert.assertSortAndCompareListModelAttribute(mav, modelName, expectedList, comparator);
|
||||
}
|
||||
|
|
|
@ -52,14 +52,11 @@ public abstract class ModelAndViewAssert {
|
|||
* @return the model value
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, Object modelName, Class<T> expectedType)
|
||||
throws AssertionError {
|
||||
|
||||
public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
assertCondition(mav.getModel() != null, "Model is null");
|
||||
Object obj = mav.getModel().get(modelName);
|
||||
assertCondition(obj != null, "Model attribute with name '" + modelName + "' is null");
|
||||
|
||||
assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '" +
|
||||
expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'");
|
||||
return (T) obj;
|
||||
|
@ -72,11 +69,9 @@ public abstract class ModelAndViewAssert {
|
|||
* <code>null</code>)
|
||||
* @param expectedList the expected list
|
||||
*/
|
||||
public static void assertCompareListModelAttribute(ModelAndView mav, Object modelName, List expectedList)
|
||||
throws AssertionError {
|
||||
|
||||
public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
List modelList = (List) assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size() +
|
||||
"' while size of expected list is '" + expectedList.size() + "'");
|
||||
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName +
|
||||
|
@ -89,7 +84,7 @@ public abstract class ModelAndViewAssert {
|
|||
* @param modelName name of the object to add to the model (never
|
||||
* <code>null</code>)
|
||||
*/
|
||||
public static void assertModelAttributeAvailable(ModelAndView mav, Object modelName) throws AssertionError {
|
||||
public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
assertCondition(mav.getModel() != null, "Model is null");
|
||||
assertCondition(mav.getModel().containsKey(modelName), "Model attribute with name '" + modelName +
|
||||
|
@ -104,7 +99,7 @@ public abstract class ModelAndViewAssert {
|
|||
* <code>null</code>)
|
||||
* @param expectedValue the model value
|
||||
*/
|
||||
public static void assertModelAttributeValue(ModelAndView mav, Object modelName, Object expectedValue) {
|
||||
public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class);
|
||||
assertCondition(modelValue.equals(expectedValue), "Model value with name '" + modelName +
|
||||
|
@ -156,7 +151,7 @@ public abstract class ModelAndViewAssert {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void assertSortAndCompareListModelAttribute(
|
||||
ModelAndView mav, Object modelName, List expectedList, Comparator comparator) {
|
||||
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
|
||||
|
||||
assertCondition(mav != null, "ModelAndView is null");
|
||||
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
|
@ -214,17 +209,19 @@ public abstract class ModelAndViewAssert {
|
|||
}
|
||||
}
|
||||
|
||||
private static void appendNonMatchingSetsErrorMessage(Set<String> assertionSet, Set<String> incorrectSet, StringBuilder buf) {
|
||||
private static void appendNonMatchingSetsErrorMessage(
|
||||
Set<String> assertionSet, Set<String> incorrectSet, StringBuilder sb) {
|
||||
|
||||
Set<String> tempSet = new HashSet<String>();
|
||||
tempSet.addAll(incorrectSet);
|
||||
tempSet.removeAll(assertionSet);
|
||||
|
||||
if (tempSet.size() > 0) {
|
||||
buf.append("Set has too many elements:\n");
|
||||
sb.append("Set has too many elements:\n");
|
||||
for (Object element : tempSet) {
|
||||
buf.append('-');
|
||||
buf.append(element);
|
||||
buf.append('\n');
|
||||
sb.append('-');
|
||||
sb.append(element);
|
||||
sb.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,11 +230,11 @@ public abstract class ModelAndViewAssert {
|
|||
tempSet.removeAll(incorrectSet);
|
||||
|
||||
if (tempSet.size() > 0) {
|
||||
buf.append("Set is missing elements:\n");
|
||||
sb.append("Set is missing elements:\n");
|
||||
for (Object element : tempSet) {
|
||||
buf.append('-');
|
||||
buf.append(element);
|
||||
buf.append('\n');
|
||||
sb.append('-');
|
||||
sb.append(element);
|
||||
sb.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue