Consistent use of LinkedHashMaps and independent getAttributeNames Enumeration in Servlet/Portlet mocks

Issue: SPR-10224
This commit is contained in:
Juergen Hoeller 2013-01-30 14:57:36 +01:00
parent 94a88069ac
commit 6a98b40e1c
7 changed files with 24 additions and 23 deletions

View File

@ -30,6 +30,7 @@ import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -294,7 +295,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
checkActive(); checkActive();
return Collections.enumeration(this.attributes.keySet()); return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
} }
public String getCharacterEncoding() { public String getCharacterEncoding() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -50,6 +51,7 @@ public class MockHttpSession implements HttpSession {
public static final String SESSION_COOKIE_NAME = "JSESSION"; public static final String SESSION_COOKIE_NAME = "JSESSION";
private static int nextId = 1; private static int nextId = 1;
private final String id; private final String id;
@ -141,7 +143,7 @@ public class MockHttpSession implements HttpSession {
} }
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
return Collections.enumeration(this.attributes.keySet()); return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
} }
public String[] getValueNames() { public String[] getValueNames() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import javax.el.ELContext; import javax.el.ELContext;
import javax.servlet.Servlet; import javax.servlet.Servlet;
@ -249,7 +250,7 @@ public class MockPageContext extends PageContext {
} }
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
return Collections.enumeration(this.attributes.keySet()); return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.activation.FileTypeMap; import javax.activation.FileTypeMap;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet; import javax.servlet.Servlet;
@ -434,7 +433,7 @@ public class MockServletContext implements ServletContext {
} }
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
return Collections.enumeration(this.attributes.keySet()); return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
} }
public void setAttribute(String name, Object value) { public void setAttribute(String name, Object value) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Vector;
import javax.activation.FileTypeMap; import javax.activation.FileTypeMap;
import javax.portlet.PortletContext; import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher; import javax.portlet.PortletRequestDispatcher;
@ -210,7 +209,7 @@ public class MockPortletContext implements PortletContext {
} }
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
return new Vector<String>(this.attributes.keySet()).elements(); return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
} }
public void setAttribute(String name, Object value) { public void setAttribute(String name, Object value) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,13 +21,12 @@ import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Vector;
import javax.portlet.PortalContext; import javax.portlet.PortalContext;
import javax.portlet.PortletContext; import javax.portlet.PortletContext;
import javax.portlet.PortletMode; import javax.portlet.PortletMode;
@ -332,7 +331,7 @@ public class MockPortletRequest implements PortletRequest {
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
checkActive(); checkActive();
return new Vector<String>(this.attributes.keySet()).elements(); return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
} }
public void setParameters(Map<String, String[]> parameters) { public void setParameters(Map<String, String[]> parameters) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,10 +18,10 @@ package org.springframework.mock.web.portlet;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Vector;
import javax.portlet.PortletContext; import javax.portlet.PortletContext;
import javax.portlet.PortletSession; import javax.portlet.PortletSession;
import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingEvent;
@ -51,9 +51,9 @@ public class MockPortletSession implements PortletSession {
private final PortletContext portletContext; private final PortletContext portletContext;
private final Map<String, Object> portletAttributes = new HashMap<String, Object>(); private final Map<String, Object> portletAttributes = new LinkedHashMap<String, Object>();
private final Map<String, Object> applicationAttributes = new HashMap<String, Object>(); private final Map<String, Object> applicationAttributes = new LinkedHashMap<String, Object>();
private boolean invalid = false; private boolean invalid = false;
@ -92,15 +92,15 @@ public class MockPortletSession implements PortletSession {
} }
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
return new Vector<String>(this.portletAttributes.keySet()).elements(); return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
} }
public Enumeration<String> getAttributeNames(int scope) { public Enumeration<String> getAttributeNames(int scope) {
if (scope == PortletSession.PORTLET_SCOPE) { if (scope == PortletSession.PORTLET_SCOPE) {
return new Vector<String>(this.portletAttributes.keySet()).elements(); return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
} }
else if (scope == PortletSession.APPLICATION_SCOPE) { else if (scope == PortletSession.APPLICATION_SCOPE) {
return new Vector<String>(this.applicationAttributes.keySet()).elements(); return Collections.enumeration(new LinkedHashSet<String>(this.applicationAttributes.keySet()));
} }
return null; return null;
} }