You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/07/27 17:39:30 UTC

svn commit: r979753 - in /myfaces/test/trunk: test12/src/main/java/org/apache/myfaces/test/mock/ test20/src/test/java/org/apache/myfaces/test/mock/

Author: jakobk
Date: Tue Jul 27 15:39:30 2010
New Revision: 979753

URL: http://svn.apache.org/viewvc?rev=979753&view=rev
Log:
MYFACESTEST-21 Update AbstractAttributeMap and replace MockScopeMap with _ScopeMap (copied Maps from core trunk)

Removed:
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockApplicationMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockRequestMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockSessionMap.java
Modified:
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java
    myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java Tue Jul 27 15:39:30 2010
@@ -20,8 +20,8 @@ package org.apache.myfaces.test.mock;
 
 import java.util.AbstractMap;
 import java.util.AbstractSet;
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
@@ -29,49 +29,46 @@ import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
 
-
 /**
  * Helper Map implementation for use with different Attribute Maps.
- *
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * 
+ * @author Anton Koinov (latest modification by $Author: jakobk $)
+ * @version $Revision: 979229 $ $Date: 2010-07-26 12:26:53 +0200 (Mo, 26 Jul 2010) $
  */
-abstract class _AbstractAttributeMap
-    extends AbstractMap
+public abstract class _AbstractAttributeMap<V> extends AbstractMap<String, V>
 {
-    private Set              _keySet;
-    private Collection       _values;
-    private Set              _entrySet;
+    private Set<String> _keySet;
+    private Collection<V> _values;
+    private Set<Entry<String, V>> _entrySet;
 
+    @Override
     public void clear()
     {
-        List names = new ArrayList();
-        for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
-        {
-            names.add(e.nextElement());
-        }
+        final List<String> names = Collections.list(getAttributeNames());
 
-        for (Iterator it = names.iterator(); it.hasNext();)
+        for (String name : names)
         {
-            removeAttribute((String) it.next());
+            removeAttribute(name);
         }
     }
 
-    public boolean containsKey(Object key)
+    @Override
+    public final boolean containsKey(final Object key)
     {
         return getAttribute(key.toString()) != null;
     }
 
-    public boolean containsValue(Object findValue)
+    @Override
+    public boolean containsValue(final Object findValue)
     {
         if (findValue == null)
         {
             return false;
         }
 
-        for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
+        for (final Enumeration<String> e = getAttributeNames(); e.hasMoreElements();)
         {
-            Object value = getAttribute((String) e.nextElement());
+            final Object value = getAttribute(e.nextElement());
             if (findValue.equals(value))
             {
                 return true;
@@ -81,55 +78,61 @@ abstract class _AbstractAttributeMap
         return false;
     }
 
-    public Set entrySet()
+    @Override
+    public Set<Entry<String, V>> entrySet()
     {
         return (_entrySet != null) ? _entrySet : (_entrySet = new EntrySet());
     }
 
-    public Object get(Object key)
+    @Override
+    public V get(final Object key)
     {
         return getAttribute(key.toString());
     }
 
+    @Override
     public boolean isEmpty()
     {
         return !getAttributeNames().hasMoreElements();
     }
 
-    public Set keySet()
+    @Override
+    public Set<String> keySet()
     {
         return (_keySet != null) ? _keySet : (_keySet = new KeySet());
     }
 
-    public Object put(Object key, Object value)
+    @Override
+    public final V put(final String key, final V value)
     {
-        String key_ = key.toString();
-        Object retval = getAttribute(key_);
-        setAttribute(key_, value);
+        final V retval = getAttribute(key);
+        setAttribute(key, value);
         return retval;
     }
 
-    public void putAll(Map t)
+    @Override
+    public void putAll(final Map<? extends String, ? extends V> t)
     {
-        for (Iterator it = t.entrySet().iterator(); it.hasNext();)
+        for (final Entry<? extends String, ? extends V> entry : t.entrySet())
         {
-            Entry entry = (Entry) it.next();
-            setAttribute(entry.getKey().toString(), entry.getValue());
+            setAttribute(entry.getKey(), entry.getValue());
         }
     }
 
-    public Object remove(Object key)
+    @Override
+    public final V remove(final Object key)
     {
-        String key_ = key.toString();
-        Object retval = getAttribute(key_);
+        final String key_ = key.toString();
+        final V retval = getAttribute(key_);
         removeAttribute(key_);
         return retval;
     }
 
+    @Override
     public int size()
     {
         int size = 0;
-        for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
+        for (final Enumeration<String> e = getAttributeNames(); e.hasMoreElements();)
         {
             size++;
             e.nextElement();
@@ -137,104 +140,141 @@ abstract class _AbstractAttributeMap
         return size;
     }
 
-    public Collection values()
+    @Override
+    public Collection<V> values()
     {
         return (_values != null) ? _values : (_values = new Values());
     }
 
+    abstract protected V getAttribute(String key);
 
-    abstract protected Object getAttribute(String key);
-
-    abstract protected void setAttribute(String key, Object value);
+    abstract protected void setAttribute(String key, V value);
 
     abstract protected void removeAttribute(String key);
 
-    abstract protected Enumeration getAttributeNames();
+    abstract protected Enumeration<String> getAttributeNames();
 
-
-    private class KeySet extends AbstractSet
+    private abstract class AbstractAttributeSet<E> extends AbstractSet<E>
     {
-        public Iterator iterator()
-        {
-            return new KeyIterator();
-        }
-
+        @Override
         public boolean isEmpty()
         {
             return _AbstractAttributeMap.this.isEmpty();
         }
 
+        @Override
         public int size()
         {
             return _AbstractAttributeMap.this.size();
         }
 
-        public boolean contains(Object o)
+        @Override
+        public void clear()
         {
-            return _AbstractAttributeMap.this.containsKey(o);
+            _AbstractAttributeMap.this.clear();
+        }
+    }
+
+    private final class KeySet extends AbstractAttributeSet<String>
+    {
+        @Override
+        public Iterator<String> iterator()
+        {
+            return new KeyIterator();
         }
 
-        public boolean remove(Object o)
+        @Override
+        public boolean contains(final Object o)
         {
-            return _AbstractAttributeMap.this.remove(o) != null;
+            return _AbstractAttributeMap.this.containsKey(o);
         }
 
-        public void clear()
+        @Override
+        public boolean remove(final Object o)
         {
-            _AbstractAttributeMap.this.clear();
+            return _AbstractAttributeMap.this.remove(o) != null;
         }
+
     }
 
-    private class KeyIterator
-        implements Iterator
+    private abstract class AbstractAttributeIterator<E> implements Iterator<E>
     {
-        protected final Enumeration _e = getAttributeNames();
-        protected Object            _currentKey;
+        // We use a copied version of the Enumeration from getAttributeNames()
+        // here, because directly using it might cause a ConcurrentModificationException
+        // when performing remove(). Note that we can do this since the Enumeration
+        // from getAttributeNames() will contain exactly the attribute names from the time
+        // getAttributeNames() was called and it will not be updated if attributes are 
+        // removed or added.
+        protected final Iterator<String> _i = Collections.list(getAttributeNames()).iterator();
+        protected String _currentKey;
 
         public void remove()
         {
-            // remove() may cause ConcurrentModificationException.
-            // We could throw an exception here, but not throwing an exception
-            //   allows one call to remove() to succeed
             if (_currentKey == null)
             {
-                throw new NoSuchElementException(
-                    "You must call next() at least once");
+                throw new NoSuchElementException("You must call next() at least once");
             }
             _AbstractAttributeMap.this.remove(_currentKey);
         }
 
         public boolean hasNext()
         {
-            return _e.hasMoreElements();
+            return _i.hasNext();
         }
 
-        public Object next()
+        public E next()
+        {
+            return getValue(_currentKey = _i.next());
+        }
+
+        protected abstract E getValue(String attributeName);
+    }
+
+    private final class KeyIterator extends AbstractAttributeIterator<String>
+    {
+        @Override
+        protected String getValue(final String attributeName)
         {
-            return _currentKey = _e.nextElement();
+            return attributeName;
         }
     }
 
-    private class Values extends KeySet
+    private class Values extends AbstractAttributeSet<V>
     {
-        public Iterator iterator()
+        @Override
+        public Iterator<V> iterator()
         {
             return new ValuesIterator();
         }
 
-        public boolean contains(Object o)
+        @Override
+        public boolean contains(final Object o)
         {
-            return _AbstractAttributeMap.this.containsValue(o);
+            if (o == null)
+            {
+                return false;
+            }
+
+            for (final Iterator<V> it = iterator(); it.hasNext();)
+            {
+                if (o.equals(it.next()))
+                {
+                    return true;
+                }
+            }
+
+            return false;
         }
 
-        public boolean remove(Object o)
+        @Override
+        public boolean remove(final Object o)
         {
             if (o == null)
             {
                 return false;
             }
 
-            for (Iterator it = iterator(); it.hasNext();)
+            for (final Iterator<V> it = iterator(); it.hasNext();)
             {
                 if (o.equals(it.next()))
                 {
@@ -247,30 +287,35 @@ abstract class _AbstractAttributeMap
         }
     }
 
-    private class ValuesIterator extends KeyIterator
+    private class ValuesIterator extends AbstractAttributeIterator<V>
     {
-        public Object next()
+        @Override
+        protected V getValue(final String attributeName)
         {
-            super.next();
-            return _AbstractAttributeMap.this.get(_currentKey);
+            return _AbstractAttributeMap.this.get(attributeName);
         }
     }
 
-    private class EntrySet extends KeySet
+    private final class EntrySet extends AbstractAttributeSet<Entry<String, V>>
     {
-        public Iterator iterator() {
+        @Override
+        public Iterator<Entry<String, V>> iterator()
+        {
             return new EntryIterator();
         }
 
-        public boolean contains(Object o) {
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean contains(final Object o)
+        {
             if (!(o instanceof Entry))
             {
                 return false;
             }
 
-            Entry entry = (Entry) o;
-            Object key = entry.getKey();
-            Object value = entry.getValue();
+            final Entry<String, V> entry = (Entry<String, V>)o;
+            final Object key = entry.getKey();
+            final Object value = entry.getValue();
             if (key == null || value == null)
             {
                 return false;
@@ -279,73 +324,93 @@ abstract class _AbstractAttributeMap
             return value.equals(_AbstractAttributeMap.this.get(key));
         }
 
-        public boolean remove(Object o) {
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean remove(final Object o)
+        {
             if (!(o instanceof Entry))
             {
                 return false;
             }
 
-            Entry entry = (Entry) o;
-            Object key = entry.getKey();
-            Object value = entry.getValue();
-            if (key == null || value == null
-                || !value.equals(_AbstractAttributeMap.this.get(key)))
+            final Entry<String, V> entry = (Entry<String, V>)o;
+            final Object key = entry.getKey();
+            final Object value = entry.getValue();
+            if (key == null || value == null || !value.equals(_AbstractAttributeMap.this.get(key)))
             {
                 return false;
             }
 
-            return _AbstractAttributeMap.this.remove(((Entry) o).getKey()) != null;
+            return _AbstractAttributeMap.this.remove(((Entry<String, V>)o).getKey()) != null;
         }
     }
 
     /**
-     * Not very efficient since it generates a new instance of <code>Entry</code>
-     * for each element and still internaly uses the <code>KeyIterator</code>.
-     * It is more efficient to use the <code>KeyIterator</code> directly.
+     * Not very efficient since it generates a new instance of <code>Entry</code> for each element and still internaly
+     * uses the <code>KeyIterator</code>. It is more efficient to use the <code>KeyIterator</code> directly.
      */
-    private class EntryIterator extends KeyIterator
+    private final class EntryIterator extends AbstractAttributeIterator<Entry<String, V>>
     {
-        public Object next()
+        @Override
+        protected Entry<String, V> getValue(final String attributeName)
         {
-            super.next();
             // Must create new Entry every time--value of the entry must stay
             // linked to the same attribute name
-            return new EntrySetEntry(_currentKey);
+            return new EntrySetEntry(attributeName);
         }
     }
 
-    private class EntrySetEntry implements Entry
+    private final class EntrySetEntry implements Entry<String, V>
     {
-        private final Object _currentKey;
+        private final String _currentKey;
 
-        public EntrySetEntry(Object currentKey)
+        public EntrySetEntry(final String currentKey)
         {
             _currentKey = currentKey;
         }
 
-        public Object getKey()
+        public String getKey()
         {
             return _currentKey;
         }
 
-        public Object getValue()
+        public V getValue()
         {
             return _AbstractAttributeMap.this.get(_currentKey);
         }
 
-        public Object setValue(Object value)
+        public V setValue(final V value)
         {
             return _AbstractAttributeMap.this.put(_currentKey, value);
         }
 
-        public int hashCode() {
-            return _currentKey == null ? 0 : _currentKey.hashCode();
+        @Override
+        public int hashCode()
+        {
+            int result = 1;
+            result = 31 * result + ((_currentKey == null) ? 0 : _currentKey.hashCode());
+            return result;
         }
 
-        public boolean equals(Object obj) {
-            if (!(obj instanceof EntrySetEntry))
+        @Override
+        public boolean equals(final Object obj)
+        {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
                 return false;
-            return _currentKey != null && _currentKey.equals(obj);
+            final EntrySetEntry other = (EntrySetEntry)obj;
+            if (_currentKey == null)
+            {
+                if (other._currentKey != null)
+                    return false;
+            }
+            else if (!_currentKey.equals(other._currentKey))
+                return false;
+            return true;
         }
+
     }
 }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java Tue Jul 27 15:39:30 2010
@@ -18,10 +18,7 @@
  */
 package org.apache.myfaces.test.mock;
 
-import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
@@ -30,58 +27,54 @@ import javax.servlet.ServletContext;
 /**
  * ServletContext attributes as a Map.
  *
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: slessard $)
+ * @version $Revision: 701829 $ $Date: 2008-10-05 19:06:02 +0200 (So, 05 Okt 2008) $
  */
-class _ApplicationMap extends _AbstractAttributeMap
+public final class _ApplicationMap extends _AbstractAttributeMap<Object>
 {
     final ServletContext _servletContext;
 
-    _ApplicationMap(ServletContext servletContext)
+    _ApplicationMap(final ServletContext servletContext)
     {
         _servletContext = servletContext;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected Object getAttribute(final String key)
     {
         return _servletContext.getAttribute(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final Object value)
     {
         _servletContext.setAttribute(key, value);
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         _servletContext.removeAttribute(key);
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _servletContext.getAttributeNames();
     }
 
-    public void putAll(Map t)
+
+    @Override
+    public void putAll(final Map<? extends String, ? extends Object> t)
     {
-        for (Iterator it = t.entrySet().iterator(); it.hasNext();)
-        {
-            Map.Entry entry = (Map.Entry) it.next();
-            _servletContext.setAttribute((String)entry.getKey(), entry.getValue());
-        }
+        throw new UnsupportedOperationException();
     }
 
+
+    @Override
     public void clear()
     {
-        List names = new ArrayList();
-        for (Enumeration e = _servletContext.getAttributeNames(); e.hasMoreElements();)
-        {
-            String name = (String) e.nextElement();
-            names.add(name);
-        }
-        for (int i = 0; i < names.size(); i++)
-        {
-            _servletContext.removeAttribute((String) names.get(i));
-        }
+        throw new UnsupportedOperationException();
     }
 }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java Tue Jul 27 15:39:30 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.test.mock;
 
 import java.util.Enumeration;
 import java.util.Map;
+import java.util.NoSuchElementException;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
@@ -29,49 +30,37 @@ import javax.servlet.http.HttpServletReq
  *
  * @author Dimitry D'hondt
  * @author Anton Koinov
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @version $Revision: 701829 $ $Date: 2008-10-05 19:06:02 +0200 (So, 05 Okt 2008) $
  */
-class _CookieMap extends _AbstractAttributeMap
+public final class _CookieMap extends _AbstractAttributeMap<Object>
 {
     private static final Cookie[] EMPTY_ARRAY = new Cookie[0];
 
-    final HttpServletRequest _httpServletRequest;
+    private final HttpServletRequest _httpServletRequest;
 
-    _CookieMap(HttpServletRequest httpServletRequest)
+    _CookieMap(final HttpServletRequest httpServletRequest)
     {
         _httpServletRequest = httpServletRequest;
     }
 
+    @Override
     public void clear()
     {
         throw new UnsupportedOperationException(
             "Cannot clear HttpRequest Cookies");
     }
 
-    public boolean containsKey(Object key)
-    {
-        Cookie[] cookies = _httpServletRequest.getCookies();
-        if (cookies == null) return false;
-        for (int i = 0, len = cookies.length; i < len; i++)
-        {
-            if (cookies[i].getName().equals(key))
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    public boolean containsValue(Object findValue)
+    @Override
+    public boolean containsValue(final Object findValue)
     {
         if (findValue == null)
         {
             return false;
         }
 
-        Cookie[] cookies = _httpServletRequest.getCookies();
-        if (cookies == null) return false;
+        final Cookie[] cookies = _httpServletRequest.getCookies();
+        if (cookies == null)
+            return false;
         for (int i = 0, len = cookies.length; i < len; i++)
         {
             if (findValue.equals(cookies[i]))
@@ -83,28 +72,32 @@ class _CookieMap extends _AbstractAttrib
         return false;
     }
 
+    @Override
     public boolean isEmpty()
     {
-        Cookie[] cookies = _httpServletRequest.getCookies();
+        final Cookie[] cookies = _httpServletRequest.getCookies();
         return cookies == null || cookies.length == 0;
     }
 
+    @Override
     public int size()
     {
-        Cookie[] cookies = _httpServletRequest.getCookies();
+        final Cookie[] cookies = _httpServletRequest.getCookies();
         return cookies == null ? 0 : cookies.length;
     }
 
-    public void putAll(Map t)
+    @Override
+    public void putAll(final Map<? extends String, ? extends Object> t)
     {
         throw new UnsupportedOperationException();
     }
 
-
-    protected Object getAttribute(String key)
+    @Override
+    protected Object getAttribute(final String key)
     {
-        Cookie[] cookies = _httpServletRequest.getCookies();
-        if (cookies == null) return null;
+        final Cookie[] cookies = _httpServletRequest.getCookies();
+        if (cookies == null)
+            return null;
         for (int i = 0, len = cookies.length; i < len; i++)
         {
             if (cookies[i].getName().equals(key))
@@ -116,45 +109,36 @@ class _CookieMap extends _AbstractAttrib
         return null;
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final Object value)
     {
-        if (_httpServletRequest instanceof MockHttpServletRequest)
-        {
-            ((MockHttpServletRequest) _httpServletRequest).addCookie((Cookie) value);
-        }
-        else
-        {
-            throw new UnsupportedOperationException(
-                "Cannot set HttpRequest Cookies");
-        }
+        throw new UnsupportedOperationException(
+            "Cannot set HttpRequest Cookies");
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         throw new UnsupportedOperationException(
             "Cannot remove HttpRequest Cookies");
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    protected Enumeration<String> getAttributeNames()
     {
-        Cookie[] cookies = _httpServletRequest.getCookies();
-        if (cookies == null)
-        {
-            return new CookieNameEnumeration(EMPTY_ARRAY);
-        }
-        else
-        {
-            return new CookieNameEnumeration(cookies);
-        }
+        final Cookie[] cookies = _httpServletRequest.getCookies();
+
+        return cookies == null ? new CookieNameEnumeration(EMPTY_ARRAY) : new CookieNameEnumeration(cookies);
+  
     }
 
-    private static class CookieNameEnumeration implements Enumeration
+    private static class CookieNameEnumeration implements Enumeration<String>
     {
         private final Cookie[] _cookies;
         private final int _length;
         private int _index;
 
-        public CookieNameEnumeration(Cookie[] cookies)
+        public CookieNameEnumeration(final Cookie[] cookies)
         {
             _cookies = cookies;
             _length = cookies.length;
@@ -165,8 +149,12 @@ class _CookieMap extends _AbstractAttrib
             return _index < _length;
         }
 
-        public Object nextElement()
+        public String nextElement()
         {
+            if (!hasMoreElements())
+            {
+                throw new NoSuchElementException();
+            }
             return _cookies[_index++].getName();
         }
     }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java Tue Jul 27 15:39:30 2010
@@ -18,12 +18,8 @@
  */
 package org.apache.myfaces.test.mock;
 
-import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import javax.servlet.ServletContext;
 
@@ -31,44 +27,55 @@ import javax.servlet.ServletContext;
 /**
  * ServletContext init parameters as Map.
  * 
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: slessard $)
+ * @version $Revision: 701829 $ $Date: 2008-10-05 19:06:02 +0200 (So, 05 Okt 2008) $
  */
-class _InitParameterMap extends _AbstractAttributeMap
+public final class _InitParameterMap extends _AbstractAttributeMap<String>
 {
-    final ServletContext _servletContext;
+    private final ServletContext _servletContext;
 
-    _InitParameterMap(ServletContext servletContext)
+    _InitParameterMap(final ServletContext servletContext)
     {
         _servletContext = servletContext;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected String getAttribute(final String key)
     {
         return _servletContext.getInitParameter(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final String value)
     {
-        if (_servletContext instanceof MockServletContext)
-        {
-            ((MockServletContext)_servletContext).addInitParameter(key, (String) value);
-        }
-        else
-        {
-            throw new UnsupportedOperationException(
-                "Cannot set ServletContext InitParameter");
-        }
+        throw new UnsupportedOperationException(
+            "Cannot set ServletContext InitParameter");
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         throw new UnsupportedOperationException(
             "Cannot remove ServletContext InitParameter");
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _servletContext.getInitParameterNames();
     }
+    
+    @Override
+    public void putAll(final Map<? extends String, ? extends String> t)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    @Override
+    public void clear()
+    {
+        throw new UnsupportedOperationException();
+    }
 }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java Tue Jul 27 15:39:30 2010
@@ -27,44 +27,55 @@ import javax.servlet.http.HttpServletReq
 /**
  * HttpServletRequest headers as Map.
  * 
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: slessard $)
+ * @version $Revision: 698799 $ $Date: 2008-09-25 04:03:47 +0200 (Do, 25 Sep 2008) $
  */
-class _RequestHeaderMap extends _AbstractAttributeMap
+public final class _RequestHeaderMap extends _AbstractAttributeMap<String>
 {
     private final HttpServletRequest _httpServletRequest;
 
-    _RequestHeaderMap(HttpServletRequest httpServletRequest)
+    _RequestHeaderMap(final HttpServletRequest httpServletRequest)
     {
         _httpServletRequest = httpServletRequest;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected String getAttribute(final String key)
     {
         return _httpServletRequest.getHeader(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final String value)
     {
-        if (_httpServletRequest instanceof MockHttpServletRequest)
-        {
-            ((MockHttpServletRequest)_httpServletRequest).addHeader(key, (String)value);
-        }
-        else
-        {
-            throw new UnsupportedOperationException(
-                "Cannot set HttpServletRequest Header");
-        }
+        throw new UnsupportedOperationException(
+            "Cannot set HttpServletRequest Header");
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         throw new UnsupportedOperationException(
             "Cannot remove HttpServletRequest Header");
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _httpServletRequest.getHeaderNames();
     }
+
+    @Override
+    public void putAll(final Map<? extends String, ? extends String> t)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    @Override
+    public void clear()
+    {
+        throw new UnsupportedOperationException();
+    }    
 }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java Tue Jul 27 15:39:30 2010
@@ -26,19 +26,27 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
-class _RequestHeaderValuesMap extends _AbstractAttributeMap
+/**
+ * HttpServletRequest header values (multi-value headers) as Map of String[].
+ * 
+ * @author Anton Koinov (latest modification by $Author: slessard $)
+ * @version $Revision: 701829 $ $Date: 2008-10-05 19:06:02 +0200 (So, 05 Okt 2008) $
+ */
+public final class _RequestHeaderValuesMap extends _AbstractAttributeMap<String[]>
 {
     private final HttpServletRequest _httpServletRequest;
-    private final Map _valueCache = new HashMap();
+    private final Map<String, String[]> _valueCache = new HashMap<String, String[]>();
 
     _RequestHeaderValuesMap(final HttpServletRequest httpServletRequest)
     {
         _httpServletRequest = httpServletRequest;
     }
 
-    protected Object getAttribute(final String key)
+    @Override
+    @SuppressWarnings("unchecked")
+    protected String[] getAttribute(final String key)
     {
-        String[] ret = (String[])_valueCache.get(key);
+        String[] ret = _valueCache.get(key);
         if (ret == null)
         {
             _valueCache.put(key, ret = toArray(_httpServletRequest.getHeaders(key)));
@@ -47,30 +55,34 @@ class _RequestHeaderValuesMap extends _A
         return ret;
     }
 
-    protected void setAttribute(final String key, final Object value)
+    @Override
+    protected void setAttribute(final String key, final String[] value)
     {
         throw new UnsupportedOperationException("Cannot set HttpServletRequest HeaderValues");
     }
 
+    @Override
     protected void removeAttribute(final String key)
     {
         throw new UnsupportedOperationException("Cannot remove HttpServletRequest HeaderValues");
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _httpServletRequest.getHeaderNames();
     }
 
-    private String[] toArray(Enumeration e)
+    private String[] toArray(Enumeration<String> e)
     {
-        List ret = new ArrayList();
+        List<String> ret = new ArrayList<String>();
 
         while (e.hasMoreElements())
         {
             ret.add(e.nextElement());
         }
 
-        return (String[]) ret.toArray(new String[ret.size()]);
+        return ret.toArray(new String[ret.size()]);
     }
-}
+}
\ No newline at end of file

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java Tue Jul 27 15:39:30 2010
@@ -27,35 +27,53 @@ import javax.servlet.ServletRequest;
 /**
  * ServletRequest attributes Map.
  * 
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: slessard $)
+ * @version $Revision: 698799 $ $Date: 2008-09-25 04:03:47 +0200 (Do, 25 Sep 2008) $
  */
-class _RequestMap extends _AbstractAttributeMap
+public final class _RequestMap extends _AbstractAttributeMap<Object>
 {
     final ServletRequest _servletRequest;
 
-    _RequestMap(ServletRequest servletRequest)
+    _RequestMap(final ServletRequest servletRequest)
     {
         _servletRequest = servletRequest;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected Object getAttribute(final String key)
     {
         return _servletRequest.getAttribute(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final Object value)
     {
         _servletRequest.setAttribute(key, value);
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         _servletRequest.removeAttribute(key);
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _servletRequest.getAttributeNames();
-    }   
+    }
+
+    @Override
+    public void putAll(final Map<? extends String, ? extends Object> t)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    @Override
+    public void clear()
+    {
+        throw new UnsupportedOperationException();
+    }    
 }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java Tue Jul 27 15:39:30 2010
@@ -25,43 +25,41 @@ import javax.servlet.ServletRequest;
 /**
  * ServletRequest parameters as Map.
  * 
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: lu4242 $)
+ * @version $Revision: 695059 $ $Date: 2008-09-14 01:10:53 +0200 (So, 14 Sep 2008) $
  */
-class _RequestParameterMap extends _AbstractAttributeMap
+public final class _RequestParameterMap extends _AbstractAttributeMap<String>
 {
     private final ServletRequest _servletRequest;
 
-    _RequestParameterMap(ServletRequest servletRequest)
+    _RequestParameterMap(final ServletRequest servletRequest)
     {
         _servletRequest = servletRequest;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected String getAttribute(final String key)
     {
         return _servletRequest.getParameter(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final String value)
     {
-        if( _servletRequest instanceof MockHttpServletRequest)
-        {
-            ((MockHttpServletRequest)_servletRequest).addParameter(key, (String)value);
-        }
-        else
-        {
-            throw new UnsupportedOperationException(
-                "Cannot set ServletRequest Parameter");
-        }
+        throw new UnsupportedOperationException(
+            "Cannot set ServletRequest Parameter");
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         throw new UnsupportedOperationException(
             "Cannot remove ServletRequest Parameter");
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _servletRequest.getParameterNames();
     }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java Tue Jul 27 15:39:30 2010
@@ -25,37 +25,42 @@ import javax.servlet.ServletRequest;
 /**
  * ServletRequest multi-value parameters as Map.
  * 
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: lu4242 $)
+ * @version $Revision: 695059 $ $Date: 2008-09-14 01:10:53 +0200 (So, 14 Sep 2008) $
  */
-class _RequestParameterValuesMap extends _AbstractAttributeMap
+public final class _RequestParameterValuesMap extends _AbstractAttributeMap<String[]>
 {
     private final ServletRequest _servletRequest;
 
-    _RequestParameterValuesMap(ServletRequest servletRequest)
+    _RequestParameterValuesMap(final ServletRequest servletRequest)
     {
         _servletRequest = servletRequest;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected String[] getAttribute(final String key)
     {
         return _servletRequest.getParameterValues(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final String[] value)
     {
         throw new UnsupportedOperationException(
             "Cannot set ServletRequest ParameterValues");
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
         throw new UnsupportedOperationException(
             "Cannot remove ServletRequest ParameterValues");
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
         return _servletRequest.getParameterNames();
     }
-}
\ No newline at end of file
+}

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java Tue Jul 27 15:39:30 2010
@@ -28,61 +28,60 @@ import javax.servlet.http.HttpSession;
 /**
  * HttpSession attibutes as Map.
  *
- * @author Anton Koinov (latest modification by $Author: grantsmith $)
- * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ * @author Anton Koinov (latest modification by $Author: jakobk $)
+ * @version $Revision: 979229 $ $Date: 2010-07-26 12:26:53 +0200 (Mo, 26 Jul 2010) $
  */
-class _SessionMap extends _AbstractAttributeMap
+public final class _SessionMap extends _AbstractAttributeMap<Object>
 {
     private final HttpServletRequest _httpRequest;
 
-    _SessionMap(HttpServletRequest httpRequest)
+    _SessionMap(final HttpServletRequest httpRequest)
     {
         _httpRequest = httpRequest;
     }
 
-    protected Object getAttribute(String key)
+    @Override
+    protected Object getAttribute(final String key)
     {
-        HttpSession httpSession = getSession();
-        return (httpSession == null)
-            ? null : httpSession.getAttribute(key.toString());
+        final HttpSession httpSession = _getSession();
+        return (httpSession == null) ? null : httpSession.getAttribute(key);
     }
 
-    protected void setAttribute(String key, Object value)
+    @Override
+    protected void setAttribute(final String key, final Object value)
     {
         _httpRequest.getSession(true).setAttribute(key, value);
     }
 
-    protected void removeAttribute(String key)
+    @Override
+    protected void removeAttribute(final String key)
     {
-        HttpSession httpSession = getSession();
+        final HttpSession httpSession = _getSession();
         if (httpSession != null)
         {
             httpSession.removeAttribute(key);
         }
     }
 
-    protected Enumeration getAttributeNames()
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<String> getAttributeNames()
     {
-        HttpSession httpSession = getSession();
-        return (httpSession == null)
-            ? _NullEnumeration.instance()
-            : httpSession.getAttributeNames();
+        final HttpSession httpSession = _getSession();
+        return (httpSession == null) ? _NullEnumeration.instance() : httpSession.getAttributeNames();
     }
 
-    private HttpSession getSession()
-    {
-        return _httpRequest.getSession(false);
-    }
-
-
-    public void putAll(Map t)
+    @Override
+    public void putAll(final Map<? extends String, ? extends Object> t)
     {
         throw new UnsupportedOperationException();
     }
-
-
-    public void clear()
+    
+    // we can use public void clear() from super-class
+    
+    private HttpSession _getSession()
     {
-        throw new UnsupportedOperationException();
+        return _httpRequest.getSession(false);
     }
-}
\ No newline at end of file
+
+}

Modified: myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java?rev=979753&r1=979752&r2=979753&view=diff
==============================================================================
--- myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java (original)
+++ myfaces/test/trunk/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java Tue Jul 27 15:39:30 2010
@@ -65,7 +65,7 @@ public class MockPartialViewContextTestC
         PartialViewContext pvContext = factory.getPartialViewContext(facesContext);
         assertFalse(pvContext.isAjaxRequest());
 
-        facesContext.getExternalContext().getRequestHeaderMap().put("Faces-Request", "partial/ajax");
+        externalContext.addRequestHeader("Faces-Request", "partial/ajax");
 
         pvContext = factory.getPartialViewContext(facesContext);
         assertTrue(pvContext.isAjaxRequest());