tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r937627 - in /tiles/sandbox/trunk/tiles-request/tiles-request-api/src: main/java/org/apache/tiles/request/collection/ main/java/org/apache/tiles/request/util/ test/java/org/apache/tiles/request/collection/ test/java/org/apache/tiles/request...
Date Sat, 24 Apr 2010 13:34:36 GMT
Author: apetrelli
Date: Sat Apr 24 13:34:36 2010
New Revision: 937627

URL: http://svn.apache.org/viewvc?rev=937627&view=rev
Log:
TILESSB-31
Fixed something, added more tests.

Added:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java   (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java   (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java   (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java   (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java   (with props)
Modified:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/HeaderValuesMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryTest.java

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/HeaderValuesMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/HeaderValuesMap.java?rev=937627&r1=937626&r2=937627&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/HeaderValuesMap.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/HeaderValuesMap.java Sat Apr 24 13:34:36 2010
@@ -33,6 +33,7 @@ import java.util.Set;
 
 import org.apache.tiles.request.collection.extractor.EnumeratedValuesExtractor;
 import org.apache.tiles.request.util.MapEntry;
+import org.apache.tiles.request.util.MapEntryArrayValues;
 
 
 /**
@@ -189,21 +190,6 @@ public class HeaderValuesMap implements 
      * @param enumeration The enumeration to convert.
      * @return The corresponding array.
      */
-    private String[] enumeration2array(Enumeration<String> enumeration) {
-        List<String> list1 = new ArrayList<String>();
-        while (enumeration.hasMoreElements()) {
-            list1.add(enumeration.nextElement());
-        }
-
-        return list1.toArray(new String[list1.size()]);
-    }
-
-    /**
-     * Converts the content of a string enumeration to an array of strings.
-     *
-     * @param enumeration The enumeration to convert.
-     * @return The corresponding array.
-     */
     private Set<String> enumeration2set(Enumeration<String> enumeration) {
         Set<String> retValue = new HashSet<String>();
         while (enumeration.hasMoreElements()) {
@@ -332,7 +318,7 @@ public class HeaderValuesMap implements 
         private MapEntry<String, String[]> extractNextEntry(
                 Enumeration<String> names) {
             String name = names.nextElement();
-            return new MapEntry<String, String[]>(name, getHeaderValues(name), false);
+            return new MapEntryArrayValues<String, String>(name, getHeaderValues(name), false);
         }
 
         private class HeadersEntrySetIterator implements Iterator<Map.Entry<String, String[]>> {
@@ -440,6 +426,21 @@ public class HeaderValuesMap implements 
             return entries;
         }
 
+        /**
+         * Converts the content of a string enumeration to an array of strings.
+         *
+         * @param enumeration The enumeration to convert.
+         * @return The corresponding array.
+         */
+        private String[] enumeration2array(Enumeration<String> enumeration) {
+            List<String> list1 = new ArrayList<String>();
+            while (enumeration.hasMoreElements()) {
+                list1.add(enumeration.nextElement());
+            }
+
+            return list1.toArray(new String[list1.size()]);
+        }
+
         private class HeaderValuesCollectionIterator implements Iterator<String[]> {
 
             private Enumeration<String> namesEnumeration = request.getKeys();

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java?rev=937627&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java Sat Apr 24 13:34:36 2010
@@ -0,0 +1,97 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.util;
+
+
+import java.util.Map;
+
+
+/**
+ * <p>Map.Entry implementation that can be constructed to either be read-only
+ * or not.</p>
+ *
+ * @version $Rev$ $Date$
+ * @param <K> The key type.
+ * @param <V> The value type.
+ */
+
+public class MapEntryArrayValues<K, V> extends MapEntry<K, V[]> {
+
+    public MapEntryArrayValues(K key, V[] value, boolean modifiable) {
+        super(key, value, modifiable);
+    }
+
+
+    /**
+     * <p>Returns the hashcode for this entry.</p>
+     *
+     * @return The and'ed hashcode of the key and value
+     */
+    @Override
+    public int hashCode() {
+        int valueHash = 0;
+        V[] value = getValue();
+        if (value != null) {
+            for (int i = 0; i < value.length; i++) {
+                valueHash += value[i].hashCode();
+            }
+        }
+
+        return (this.getKey() == null ? 0 : this.getKey().hashCode())
+                ^ valueHash;
+    }
+
+    /**
+     * <p>Determines if this entry is equal to the passed object.</p>
+     *
+     * @param o The object to test
+     * @return True if equal, else false
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public boolean equals(Object o) {
+        if (o != null && o instanceof Map.Entry) {
+            Map.Entry<K, V[]> entry = (Map.Entry<K, V[]>) o;
+            if (this.getKey() == null ? entry.getKey() == null : this
+                    .getKey().equals(entry.getKey())) {
+                V[] values = getValue();
+                V[] otherValues = entry.getValue();
+                if (values != null) {
+                    if (otherValues != null) {
+                        if (values.length == otherValues.length) {
+                            boolean same = true;
+                            for (int i = 0; i < values.length && same; i++) {
+                                same = values[i] == null ? otherValues[i] == null
+                                        : values[i].equals(otherValues[i]);
+                            }
+                            return same;
+                        }
+                    } else {
+                        return false;
+                    }
+                } else {
+                    return otherValues == null;
+                }
+            }
+        }
+        return false;
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/util/MapEntryArrayValues.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java?rev=937627&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java Sat Apr 24 13:34:36 2010
@@ -0,0 +1,390 @@
+package org.apache.tiles.request.collection;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tiles.request.collection.extractor.EnumeratedValuesExtractor;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link HeaderValuesMap#values()}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeaderValuesCollectionTest {
+
+
+    private EnumeratedValuesExtractor extractor;
+
+    private HeaderValuesMap map;
+
+    private Collection<String[]> coll;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(EnumeratedValuesExtractor.class);
+        map = new HeaderValuesMap(extractor);
+        coll = map.values();
+    }
+
+    /**
+     * Tests {@link Collection#add(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testAdd() {
+        coll.add(null);
+    }
+
+    /**
+     * Tests {@link Collection#addAll(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testAddAll() {
+        coll.addAll(null);
+    }
+
+    /**
+     * Tests {@link Collection#clear(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testClear() {
+        coll.clear();
+    }
+
+    /**
+     * Tests {@link Collection#contains(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValue() {
+        assertFalse(map.containsValue(1));
+
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values1, values2);
+        assertTrue(coll.contains(new String[] {"value2", "value3"}));
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Tests {@link Collection#contains(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValueFalse() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values1, values2);
+        assertFalse(coll.contains(new String[] {"value2", "value4"}));
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Tests {@link Collection#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAll() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys).times(2);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValues("one")).andReturn(values1).times(2);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values1, values2);
+        List<String[]> coll = new ArrayList<String[]>();
+        coll.add(new String[] {"value1"});
+        coll.add(new String[] {"value2", "value3"});
+        assertTrue(this.coll.containsAll(coll));
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Tests {@link Collection#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAllFalse() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+
+        replay(extractor, keys, values1, values2);
+        List<String[]> coll = new ArrayList<String[]>();
+        coll.add(new String[] {"value4"});
+        assertFalse(this.coll.containsAll(coll));
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Test method for {@link Collection#isEmpty()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testIsEmpty() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+
+        replay(extractor, keys);
+        assertFalse(coll.isEmpty());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link Collection#iterator()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testIterator() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values2);
+        Iterator<String[]> entryIt = coll.iterator();
+        assertTrue(entryIt.hasNext());
+        assertArrayEquals(new String[] { "value2", "value3" }, entryIt.next());
+        verify(extractor, keys, values2);
+    }
+
+    /**
+     * Test method for {@link Collection#iterator()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test(expected=UnsupportedOperationException.class)
+    public void testIteratorRemove() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+
+        try {
+            replay(extractor, keys);
+            coll.iterator().remove();
+        } finally {
+            verify(extractor, keys);
+        }
+    }
+
+    /**
+     * Tests {@link Collection#remove(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRemove() {
+        coll.remove(null);
+    }
+
+    /**
+     * Tests {@link Collection#removeAll(java.util.Collection)}
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRemoveAll() {
+        coll.removeAll(null);
+    }
+
+    /**
+     * Tests {@link Collection#retainAll(java.util.Collection)}
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRetainAll() {
+        coll.retainAll(null);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#size()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testSize() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys);
+        assertEquals(2, coll.size());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link Collection#toArray()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testToArray() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        String[][] entryArray = new String[2][];
+        entryArray[0] = new String[] {"value1"};
+        entryArray[1] = new String[] {"value2", "value3"};
+
+        replay(extractor, keys, values1, values2);
+        assertArrayEquals(entryArray, coll.toArray());
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Test method for {@link Collection#toArray(Object[])}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testToArrayTArray() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        String[][] entryArray = new String[2][];
+        entryArray[0] = new String[] {"value1"};
+        entryArray[1] = new String[] {"value2", "value3"};
+        String[][] realArray = new String[2][];
+
+        replay(extractor, keys, values1, values2);
+        assertArrayEquals(entryArray, coll.toArray(realArray));
+        verify(extractor, keys, values1, values2);
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesCollectionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java?rev=937627&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java Sat Apr 24 13:34:36 2010
@@ -0,0 +1,328 @@
+package org.apache.tiles.request.collection;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tiles.request.collection.extractor.EnumeratedValuesExtractor;
+import org.apache.tiles.request.util.MapEntryArrayValues;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HeaderValuesMapEntrySetTest {
+
+
+    private EnumeratedValuesExtractor extractor;
+
+    private HeaderValuesMap map;
+
+    private Set<Map.Entry<String, String[]>> entrySet;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(EnumeratedValuesExtractor.class);
+        map = new HeaderValuesMap(extractor);
+        entrySet = map.entrySet();
+    }
+
+    /**
+     * Tests {@link Set#add(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testAdd() {
+        entrySet.add(null);
+    }
+
+    /**
+     * Tests {@link Set#addAll(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testAddAll() {
+        entrySet.addAll(null);
+    }
+
+    /**
+     * Tests {@link Set#clear(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testClear() {
+        entrySet.clear();
+    }
+
+    /**
+     * Tests {@link Set#contains(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContains() {
+        Map.Entry<String, String[]> entry = createMock(Map.Entry.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(entry.getKey()).andReturn("two");
+        expect(entry.getValue()).andReturn(new String[] {"value2", "value3"});
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, entry, values2);
+        assertTrue(entrySet.contains(entry));
+        verify(extractor, entry, values2);
+    }
+
+    /**
+     * Tests {@link Set#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAll() {
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+        Map.Entry<String, String[]> entry1 = createMock(Map.Entry.class);
+        Map.Entry<String, String[]> entry2 = createMock(Map.Entry.class);
+
+        expect(entry1.getKey()).andReturn("one");
+        expect(entry1.getValue()).andReturn(new String[] {"value1"});
+        expect(entry2.getKey()).andReturn("two");
+        expect(entry2.getValue()).andReturn(new String[] {"value2", "value3"});
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, values1, values2, entry1, entry2);
+        List<Map.Entry<String, String[]>> coll = new ArrayList<Map.Entry<String,String[]>>();
+        coll.add(entry1);
+        coll.add(entry2);
+        assertTrue(entrySet.containsAll(coll));
+        verify(extractor, values1, values2, entry1, entry2);
+    }
+
+    /**
+     * Tests {@link Set#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAllFalse() {
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Map.Entry<String, String[]> entry1 = createMock(Map.Entry.class);
+
+        expect(entry1.getKey()).andReturn("one");
+        expect(entry1.getValue()).andReturn(new String[] {"value4"});
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+
+        replay(extractor, values1, entry1);
+        List<Map.Entry<String, String[]>> coll = new ArrayList<Map.Entry<String,String[]>>();
+        coll.add(entry1);
+        assertFalse(entrySet.containsAll(coll));
+        verify(extractor, values1, entry1);
+    }
+
+    /**
+     * Test method for {@link Set#isEmpty()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testIsEmpty() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+
+        replay(extractor, keys);
+        assertFalse(entrySet.isEmpty());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link Set#iterator()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testIterator() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values2);
+        Iterator<Map.Entry<String, String[]>> entryIt = entrySet.iterator();
+        assertTrue(entryIt.hasNext());
+        MapEntryArrayValues<String, String> entry = new MapEntryArrayValues<String, String>(
+                "two", new String[] { "value2", "value3" }, false);
+        assertEquals(entry, entryIt.next());
+        verify(extractor, keys, values2);
+    }
+
+    /**
+     * Test method for {@link Set#iterator()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test(expected=UnsupportedOperationException.class)
+    public void testIteratorRemove() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+
+        try {
+            replay(extractor, keys);
+            entrySet.iterator().remove();
+        } finally {
+            verify(extractor, keys);
+        }
+    }
+
+    /**
+     * Tests {@link Set#remove(Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRemove() {
+        entrySet.remove(null);
+    }
+
+    /**
+     * Tests {@link Set#removeAll(java.util.Collection)}
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRemoveAll() {
+        entrySet.removeAll(null);
+    }
+
+    /**
+     * Tests {@link Set#retainAll(java.util.Collection)}
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRetainAll() {
+        entrySet.retainAll(null);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#size()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testSize() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys);
+        assertEquals(2, entrySet.size());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link Set#toArray()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testToArray() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        MapEntryArrayValues<String, String>[] entryArray = new MapEntryArrayValues[2];
+        entryArray[0] = new MapEntryArrayValues<String, String>("one", new String[] {"value1"}, false);
+        entryArray[1] = new MapEntryArrayValues<String, String>("two", new String[] {"value2", "value3"}, false);
+
+        replay(extractor, keys, values1, values2);
+        assertArrayEquals(entryArray, entrySet.toArray());
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Test method for {@link Set#toArray(Object[])}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testToArrayTArray() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        MapEntryArrayValues<String, String>[] entryArray = new MapEntryArrayValues[2];
+        entryArray[0] = new MapEntryArrayValues<String, String>("one", new String[] {"value1"}, false);
+        entryArray[1] = new MapEntryArrayValues<String, String>("two", new String[] {"value2", "value3"}, false);
+        MapEntryArrayValues<String, String>[] realArray = new MapEntryArrayValues[2];
+
+        replay(extractor, keys, values1, values2);
+        assertArrayEquals(entryArray, entrySet.toArray(realArray));
+        verify(extractor, keys, values1, values2);
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapEntrySetTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java?rev=937627&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java Sat Apr 24 13:34:36 2010
@@ -0,0 +1,319 @@
+/**
+ *
+ */
+package org.apache.tiles.request.collection;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+
+import org.apache.tiles.request.collection.extractor.EnumeratedValuesExtractor;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link HeaderValuesMap}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeaderValuesMapTest {
+
+    private EnumeratedValuesExtractor extractor;
+
+    private HeaderValuesMap map;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(EnumeratedValuesExtractor.class);
+        map = new HeaderValuesMap(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#hashCode()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testHashCode() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values1, values2);
+        assertEquals(("one".hashCode() ^ "value1".hashCode()) +
+                ("two".hashCode() ^ ("value2".hashCode() + "value3".hashCode())),
+                map.hashCode());
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#clear()}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testClear() {
+        map.clear();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#containsKey(java.lang.Object)}.
+     */
+    @Test
+    public void testContainsKey() {
+        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn(null);
+
+        replay(extractor);
+        assertTrue(map.containsKey("one"));
+        assertFalse(map.containsKey("two"));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#containsValue(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValue() {
+        assertFalse(map.containsValue(1));
+
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values1, values2);
+        assertTrue(map.containsValue(new String[] {"value2", "value3"}));
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#containsValue(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValueFalse() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys, values1, values2);
+        assertFalse(map.containsValue(new String[] {"value2", "value4"}));
+        verify(extractor, keys, values1, values2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#equals(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testEqualsObject() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> values1 = createMock(Enumeration.class);
+        Enumeration<String> values2 = createMock(Enumeration.class);
+        EnumeratedValuesExtractor otherExtractor = createMock(EnumeratedValuesExtractor.class);
+        Enumeration<String> otherValues1 = createMock(Enumeration.class);
+        Enumeration<String> otherValues2 = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("one")).andReturn(values1);
+        expect(values1.hasMoreElements()).andReturn(true);
+        expect(values1.nextElement()).andReturn("value1");
+        expect(values1.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        expect(otherExtractor.getValues("one")).andReturn(otherValues1);
+        expect(otherValues1.hasMoreElements()).andReturn(true);
+        expect(otherValues1.nextElement()).andReturn("value1");
+        expect(otherValues1.hasMoreElements()).andReturn(false);
+
+        expect(otherExtractor.getValues("two")).andReturn(otherValues2);
+        expect(otherValues2.hasMoreElements()).andReturn(true);
+        expect(otherValues2.nextElement()).andReturn("value2");
+        expect(otherValues2.hasMoreElements()).andReturn(true);
+        expect(otherValues2.nextElement()).andReturn("value3");
+        expect(otherValues2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, otherExtractor, keys, values1, values2, otherValues1, otherValues2);
+        HeaderValuesMap otherMap = new HeaderValuesMap(otherExtractor);
+        assertTrue(map.equals(otherMap));
+        verify(extractor, otherExtractor, keys, values1, values2, otherValues1, otherValues2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#get(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testGet() {
+        Enumeration<String> values2 = createMock(Enumeration.class);
+
+        expect(extractor.getValues("two")).andReturn(values2);
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value2");
+        expect(values2.hasMoreElements()).andReturn(true);
+        expect(values2.nextElement()).andReturn("value3");
+        expect(values2.hasMoreElements()).andReturn(false);
+
+        replay(extractor, values2);
+        assertArrayEquals(new String[] {"value2", "value3"}, map.get("two"));
+        verify(extractor, values2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#isEmpty()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testIsEmpty() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+
+        replay(extractor, keys);
+        assertFalse(map.isEmpty());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#isEmpty()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testIsEmptyTrue() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys);
+        assertTrue(map.isEmpty());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#keySet()}.
+     */
+    @Test
+    public void testKeySet() {
+        replay(extractor);
+        assertTrue(map.keySet() instanceof KeySet);
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#put(java.lang.String, java.lang.String[])}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testPut() {
+        map.put("one", new String[] {"value1", "value2"});
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#putAll(java.util.Map)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testPutAll() {
+        map.putAll(new HashMap<String, String[]>());
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#remove(java.lang.Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRemove() {
+        map.remove("one");
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.HeaderValuesMap#size()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testSize() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        replay(extractor, keys);
+        assertEquals(2, map.size());
+        verify(extractor, keys);
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/HeaderValuesMapTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java?rev=937627&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java Sat Apr 24 13:34:36 2010
@@ -0,0 +1,78 @@
+/**
+ *
+ */
+package org.apache.tiles.request.util;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * Tests {@link MapEntryArrayValues}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MapEntryArrayValuesTest {
+
+    /**
+     * Test method for {@link org.apache.tiles.request.util.MapEntryArrayValues#hashCode()}.
+     */
+    @Test
+    public void testHashCode() {
+        MapEntryArrayValues<String, String> entry = new MapEntryArrayValues<String, String>(
+                "key", new String[] { "value1", "value2" }, false);
+        assertEquals("key".hashCode() ^ ("value1".hashCode() + "value2".hashCode()), entry.hashCode());
+        entry = new MapEntryArrayValues<String, String>(
+                null, new String[] { "value1", "value2" }, false);
+        assertEquals(0 ^ ("value1".hashCode() + "value2".hashCode()), entry.hashCode());
+        entry = new MapEntryArrayValues<String, String>(
+                "key", null, false);
+        assertEquals("key".hashCode() ^ 0, entry.hashCode());
+        entry = new MapEntryArrayValues<String, String>(
+                null, null, false);
+        assertEquals(0 ^ 0, entry.hashCode());
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.util.MapEntryArrayValues#equals(java.lang.Object)}.
+     */
+    @Test
+    public void testEqualsObject() {
+        MapEntryArrayValues<String, String> entry = new MapEntryArrayValues<String, String>(
+                "key", new String[] { "value1", "value2" }, false);
+        assertFalse(entry.equals(null));
+        assertFalse(entry.equals("whatever"));
+        MapEntryArrayValues<String, String> entry2 = new MapEntryArrayValues<String, String>(
+                "key", new String[] { "value1", "value2" }, false);
+        assertTrue(entry.equals(entry2));
+        entry2 = new MapEntryArrayValues<String, String>(
+                "key", null, false);
+        assertFalse(entry.equals(entry2));
+        entry2 = new MapEntryArrayValues<String, String>("key2", new String[] {
+                "value1", "value2" }, false);
+        assertFalse(entry.equals(entry2));
+        entry2 = new MapEntryArrayValues<String, String>("key", new String[] {
+                "value1", "value3" }, false);
+        assertFalse(entry.equals(entry2));
+        entry = new MapEntryArrayValues<String, String>(null, new String[] {
+                "value1", "value2" }, false);
+        entry2 = new MapEntryArrayValues<String, String>(null, new String[] {
+                "value1", "value2" }, false);
+        assertTrue(entry.equals(entry2));
+        entry = new MapEntryArrayValues<String, String>("key", null, false);
+        entry2 = new MapEntryArrayValues<String, String>("key", null, false);
+        assertTrue(entry.equals(entry2));
+        entry2 = new MapEntryArrayValues<String, String>("key", new String[] {
+                "value1", "value2" }, false);
+        assertFalse(entry.equals(entry2));
+        entry = new MapEntryArrayValues<String, String>(null, new String[] {
+                null, "value2" }, false);
+        entry2 = new MapEntryArrayValues<String, String>(null, new String[] {
+                null, "value2" }, false);
+        assertTrue(entry.equals(entry2));
+        entry2 = new MapEntryArrayValues<String, String>(null, new String[] {
+                "value1", "value2" }, false);
+        assertFalse(entry.equals(entry2));
+    }
+
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryArrayValuesTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryTest.java?rev=937627&r1=937626&r2=937627&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryTest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/MapEntryTest.java Sat Apr 24 13:34:36 2010
@@ -84,10 +84,10 @@ public class MapEntryTest {
         assertFalse(entry.equals(entry2));
         entry = new MapEntry<String, String>(null, "value", false);
         entry2 = new MapEntry<String, String>(null, "value", false);
-        assertTrue(entry.equals(entry));
+        assertTrue(entry.equals(entry2));
         entry = new MapEntry<String, String>("key", null, false);
         entry2 = new MapEntry<String, String>("key", null, false);
-        assertTrue(entry.equals(entry));
+        assertTrue(entry.equals(entry2));
     }
 
 }



Mime
View raw message