Consistent use of StringUtils.toStringArray
(cherry picked from commit 6d11b40)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import javax.servlet.http.HttpSessionBindingListener;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
|
||||
@@ -168,7 +169,7 @@ public class MockHttpSession implements HttpSession {
|
||||
@Override
|
||||
public String[] getValueNames() {
|
||||
assertIsValid();
|
||||
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
|
||||
return StringUtils.toStringArray(this.attributes.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,9 +54,6 @@ public abstract class ModelAndViewAssert {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) {
|
||||
if (mav == null) {
|
||||
fail("ModelAndView is null");
|
||||
}
|
||||
Map<String, Object> model = mav.getModel();
|
||||
Object obj = model.get(modelName);
|
||||
if (obj == null) {
|
||||
@@ -75,7 +72,6 @@ public abstract class ModelAndViewAssert {
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
|
||||
assertTrue("ModelAndView is null", mav != null);
|
||||
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" +
|
||||
expectedList.size() + "'", expectedList.size() == modelList.size());
|
||||
@@ -89,9 +85,6 @@ public abstract class ModelAndViewAssert {
|
||||
* @param modelName name of the object to add to the model (never {@code null})
|
||||
*/
|
||||
public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
|
||||
if (mav == null) {
|
||||
fail("ModelAndView is null");
|
||||
}
|
||||
Map<String, Object> model = mav.getModel();
|
||||
assertTrue("Model attribute with name '" + modelName + "' is not available", model.containsKey(modelName));
|
||||
}
|
||||
@@ -104,7 +97,6 @@ public abstract class ModelAndViewAssert {
|
||||
* @param expectedValue the model value
|
||||
*/
|
||||
public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
|
||||
assertTrue("ModelAndView is null", mav != null);
|
||||
Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class);
|
||||
assertTrue("Model value with name '" + modelName + "' is not the same as the expected value which was '" +
|
||||
expectedValue + "'", modelValue.equals(expectedValue));
|
||||
@@ -117,9 +109,6 @@ public abstract class ModelAndViewAssert {
|
||||
* @param expectedModel the expected model
|
||||
*/
|
||||
public static void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) {
|
||||
if (mav == null) {
|
||||
fail("ModelAndView is null");
|
||||
}
|
||||
Map<String, Object> model = mav.getModel();
|
||||
|
||||
if (!model.keySet().equals(expectedModel.keySet())) {
|
||||
@@ -157,9 +146,7 @@ public abstract class ModelAndViewAssert {
|
||||
public static void assertSortAndCompareListModelAttribute(
|
||||
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
|
||||
|
||||
assertTrue("ModelAndView is null", mav != null);
|
||||
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
|
||||
|
||||
assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" +
|
||||
expectedList.size() + "'", expectedList.size() == modelList.size());
|
||||
|
||||
@@ -177,9 +164,6 @@ public abstract class ModelAndViewAssert {
|
||||
* @param expectedName the name of the model value
|
||||
*/
|
||||
public static void assertViewName(ModelAndView mav, String expectedName) {
|
||||
if (mav == null) {
|
||||
fail("ModelAndView is null");
|
||||
}
|
||||
assertTrue("View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'",
|
||||
ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user