Consistent Map/Set ordering
Use LinkedHashMaps/Sets wherever exposed to users, and code tests defensively in terms of expected Map/Set ordering. Otherwise, there'll be runtime order differences between JDK 7 and JDK 8 due to internal HashMap/Set implementation differences. Issue: SPR-9639
This commit is contained in:
@@ -16,26 +16,26 @@
|
||||
|
||||
package org.springframework.ui;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
@@ -226,12 +226,12 @@ public final class ModelMapTests {
|
||||
public void testAopCglibProxy() throws Exception {
|
||||
ModelMap map = new ModelMap();
|
||||
ProxyFactory factory = new ProxyFactory();
|
||||
Date date = new Date();
|
||||
factory.setTarget(date);
|
||||
SomeInnerClass val = new SomeInnerClass();
|
||||
factory.setTarget(val);
|
||||
factory.setProxyTargetClass(true);
|
||||
map.addAttribute(factory.getProxy());
|
||||
assertTrue(map.containsKey("date"));
|
||||
assertEquals(date, map.get("date"));
|
||||
assertTrue(map.containsKey("someInnerClass"));
|
||||
assertEquals(val, map.get("someInnerClass"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,11 +288,20 @@ public final class ModelMapTests {
|
||||
}
|
||||
|
||||
|
||||
private static class SomeInnerClass {
|
||||
public static class SomeInnerClass {
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof SomeInnerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return SomeInnerClass.class.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class UKInnerClass {
|
||||
public static class UKInnerClass {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.format.number.NumberFormatter;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -614,8 +615,8 @@ public class DataBinderTests extends TestCase {
|
||||
assertNull(rod.getSomeMap().get("key4"));
|
||||
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
|
||||
assertEquals(2, disallowedFields.length);
|
||||
assertEquals("someMap[key3]", disallowedFields[0]);
|
||||
assertEquals("someMap[key4]", disallowedFields[1]);
|
||||
assertTrue(ObjectUtils.containsElement(disallowedFields, "someMap[key3]"));
|
||||
assertTrue(ObjectUtils.containsElement(disallowedFields, "someMap[key4]"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user