tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r937783 - in /tiles/sandbox/trunk/tiles-request/tiles-request-api/src: main/java/org/apache/tiles/request/collection/ test/java/org/apache/tiles/request/collection/
Date Sun, 25 Apr 2010 11:29:04 GMT
Author: apetrelli
Date: Sun Apr 25 11:29:03 2010
New Revision: 937783

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

Added:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/KeySetTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java
  (with props)
Modified:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java?rev=937783&r1=937782&r2=937783&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java
Sun Apr 25 11:29:03 2010
@@ -51,7 +51,7 @@ public class AddableParameterMap extends
 
     /** {@inheritDoc} */
     public Set<Map.Entry<String, String>> entrySet() {
-        return new HeaderEntrySet();
+        return new ParameterEntrySet();
     }
 
     /** {@inheritDoc} */
@@ -71,7 +71,7 @@ public class AddableParameterMap extends
     }
 
 
-    private class HeaderEntrySet extends ParameterMap.HeaderEntrySet {
+    private class ParameterEntrySet extends ParameterMap.ParameterEntrySet {
 
         @Override
         public boolean add(java.util.Map.Entry<String, String> e) {

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java?rev=937783&r1=937782&r2=937783&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java
Sun Apr 25 11:29:03 2010
@@ -67,19 +67,19 @@ public class ParameterMap extends Abstra
 
     /** {@inheritDoc} */
     public boolean containsValue(Object value) {
-        Iterator<String> values = values().iterator();
-        while (values.hasNext()) {
-            if (value.equals(values.next())) {
-                return (true);
+        String realValue = (String) value;
+        for (Enumeration<String> keysIt = request.getKeys(); keysIt.hasMoreElements();
) {
+            if (realValue.equals(request.getValue(keysIt.nextElement()))) {
+                return true;
             }
         }
-        return (false);
+        return false;
     }
 
 
     /** {@inheritDoc} */
     public Set<Map.Entry<String, String>> entrySet() {
-        return new HeaderEntrySet();
+        return new ParameterEntrySet();
     }
 
 
@@ -127,11 +127,11 @@ public class ParameterMap extends Abstra
 
     /** {@inheritDoc} */
     public Collection<String> values() {
-        return new HeaderValuesCollection();
+        return new ParameterMapValuesCollection();
     }
 
 
-    class HeaderEntrySet implements Set<Map.Entry<String, String>> {
+    class ParameterEntrySet implements Set<Map.Entry<String, String>> {
 
         @Override
         public boolean add(java.util.Map.Entry<String, String> e) {
@@ -251,7 +251,7 @@ public class ParameterMap extends Abstra
         }
     }
 
-    private class HeaderValuesCollection implements Collection<String> {
+    private class ParameterMapValuesCollection implements Collection<String> {
 
         @Override
         public boolean add(String e) {
@@ -277,12 +277,14 @@ public class ParameterMap extends Abstra
         @Override
         public boolean containsAll(Collection<?> c) {
             Collection<String> realCollection = (Collection<String>) c;
-            for (String value : realCollection) {
-                if (!containsValue(value)) {
-                    return false;
+            List<String> valueList = new ArrayList<String>(realCollection);
+            for (Enumeration<String> keysEnum = request.getKeys(); keysEnum.hasMoreElements();
) {
+                valueList.remove(request.getValue(keysEnum.nextElement()));
+                if (valueList.isEmpty()) {
+                    return true;
                 }
             }
-            return true;
+            return false;
         }
 
         @Override

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/KeySetTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/KeySetTest.java?rev=937783&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/KeySetTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/KeySetTest.java
Sun Apr 25 11:29:03 2010
@@ -0,0 +1,271 @@
+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.Set;
+
+import org.apache.tiles.request.collection.extractor.HasKeys;
+import org.junit.Before;
+import org.junit.Test;
+
+public class KeySetTest {
+
+
+    private HasKeys<Integer> extractor;
+
+    private Set<String> entrySet;
+
+    /**
+     * Sets up the test.
+     */
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setUp() {
+        extractor = createMock(HasKeys.class);
+        entrySet = new KeySet(extractor);
+    }
+
+    /**
+     * 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)}.
+     */
+    @Test
+    public void testContains() {
+        expect(extractor.getValue("one")).andReturn(1);
+
+        replay(extractor);
+        assertTrue(entrySet.contains("one"));
+        verify(extractor);
+    }
+
+    /**
+     * Tests {@link Set#contains(Object)}.
+     */
+    @Test
+    public void testContainsFalse() {
+        expect(extractor.getValue("one")).andReturn(null);
+
+        replay(extractor);
+        assertFalse(entrySet.contains("one"));
+        verify(extractor);
+    }
+
+    /**
+     * Tests {@link Set#containsAll(Object)}.
+     */
+    @Test
+    public void testContainsAll() {
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(1);
+
+        replay(extractor);
+        List<String> coll = new ArrayList<String>();
+        coll.add("one");
+        coll.add("two");
+        assertTrue(entrySet.containsAll(coll));
+        verify(extractor);
+    }
+
+    /**
+     * Tests {@link Set#containsAll(Object)}.
+     */
+    @Test
+    public void testContainsAllFalse() {
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(null);
+
+        replay(extractor);
+        List<String> coll = new ArrayList<String>();
+        coll.add("one");
+        coll.add("two");
+        assertFalse(entrySet.containsAll(coll));
+        verify(extractor);
+    }
+
+    /**
+     * 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#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(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");
+
+        replay(extractor, keys, values2);
+        Iterator<String> entryIt = entrySet.iterator();
+        assertTrue(entryIt.hasNext());
+        assertEquals("two", 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);
+        replay(extractor, keys, values1, values2);
+        assertArrayEquals(new String[] {"one", "two"}, 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);
+
+        replay(extractor, keys, values1, values2);
+        String[] realArray = new String[2];
+        assertArrayEquals(new String[] {"one", "two"}, 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/KeySetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/KeySetTest.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/ParameterMapEntrySetTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java?rev=937783&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java
Sun Apr 25 11:29:03 2010
@@ -0,0 +1,289 @@
+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.HasKeys;
+import org.apache.tiles.request.util.MapEntry;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ParameterMap#entrySet()}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ParameterMapEntrySetTest {
+    private HasKeys<String> extractor;
+
+    private ParameterMap map;
+
+    private Set<Map.Entry<String, String>> entrySet;
+
+    /**
+     * Sets up the test.
+     */
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setUp() {
+        extractor = createMock(HasKeys.class);
+        map = new ParameterMap(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("value2");
+
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, entry, values2);
+        assertTrue(entrySet.contains(entry));
+        verify(extractor, entry, values2);
+    }
+
+    /**
+     * Tests {@link Set#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAll() {
+        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("value1");
+        expect(entry2.getKey()).andReturn("two");
+        expect(entry2.getValue()).andReturn("value2");
+
+        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, 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, entry1, entry2);
+    }
+
+    /**
+     * Tests {@link Set#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAllFalse() {
+        Map.Entry<String, String> entry1 = createMock(Map.Entry.class);
+
+        expect(entry1.getKey()).andReturn("one");
+        expect(entry1.getValue()).andReturn("value4");
+
+        expect(extractor.getValue("one")).andReturn("value1");
+
+        replay(extractor, entry1);
+        List<Map.Entry<String, String>> coll = new ArrayList<Map.Entry<String,String>>();
+        coll.add(entry1);
+        assertFalse(entrySet.containsAll(coll));
+        verify(extractor, 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);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        Iterator<Map.Entry<String, String>> entryIt = entrySet.iterator();
+        assertTrue(entryIt.hasNext());
+        MapEntry<String, String> entry = new MapEntry<String, String>(
+                "two", "value2", false);
+        assertEquals(entry, entryIt.next());
+        verify(extractor, keys);
+    }
+
+    /**
+     * 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.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        MapEntry<String, String>[] entryArray = new MapEntry[2];
+        entryArray[0] = new MapEntry<String, String>("one", "value1", false);
+        entryArray[1] = new MapEntry<String, String>("two", "value2", 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.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        MapEntry<String, String>[] entryArray = new MapEntry[2];
+        entryArray[0] = new MapEntry<String, String>("one", "value1", false);
+        entryArray[1] = new MapEntry<String, String>("two", "value2", false);
+
+        replay(extractor, keys, values1, values2);
+        MapEntry<String, String>[] realArray = new MapEntry[2];
+        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/ParameterMapEntrySetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.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/ParameterMapTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java?rev=937783&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java
Sun Apr 25 11:29:03 2010
@@ -0,0 +1,202 @@
+/**
+ *
+ */
+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.apache.tiles.request.collection.extractor.HasKeys;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ParameterMap}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ParameterMapTest {
+
+    private HasKeys<String> extractor;
+
+    private ParameterMap map;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(EnumeratedValuesExtractor.class);
+        map = new ParameterMap(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#clear()}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testClear() {
+        map.clear();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#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.ParameterMap#containsValue(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValue() {
+        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(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        assertTrue(map.containsValue("value2"));
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#containsValue(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValueFalse() {
+        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);
+
+        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        assertFalse(map.containsValue("value3"));
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#get(java.lang.Object)}.
+     */
+    @Test
+    public void testGet() {
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor);
+        assertEquals("value2", map.get("two"));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#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.ParameterMap#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.ParameterMap#keySet()}.
+     */
+    @Test
+    public void testKeySet() {
+        replay(extractor);
+        assertTrue(map.keySet() instanceof KeySet);
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#put(java.lang.String,
java.lang.String[])}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testPut() {
+        map.put("one", "value1");
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#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.ParameterMap#remove(java.lang.Object)}.
+     */
+    @Test(expected=UnsupportedOperationException.class)
+    public void testRemove() {
+        map.remove("one");
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#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/ParameterMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.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/ParameterMapValuesCollectionTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java?rev=937783&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java
Sun Apr 25 11:29:03 2010
@@ -0,0 +1,308 @@
+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.apache.tiles.request.collection.extractor.HasKeys;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ParameterMap#values()}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ParameterMapValuesCollectionTest {
+    private HasKeys<String> extractor;
+
+    private ParameterMap map;
+
+    private Collection<String> coll;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(EnumeratedValuesExtractor.class);
+        map = new ParameterMap(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() {
+        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(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        assertTrue(coll.contains("value2"));
+        verify(extractor, keys);
+    }
+
+    /**
+     * Tests {@link Collection#contains(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsValueFalse() {
+        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);
+
+        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        assertFalse(coll.contains("value3"));
+        verify(extractor, keys);
+    }
+
+    /**
+     * Tests {@link Collection#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAll() {
+        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(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        List<String> coll = new ArrayList<String>();
+        coll.add("value1");
+        coll.add("value2");
+        assertTrue(this.coll.containsAll(coll));
+        verify(extractor, keys);
+    }
+
+    /**
+     * Tests {@link Collection#containsAll(Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testContainsAllFalse() {
+        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);
+
+        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        List<String> coll = new ArrayList<String>();
+        coll.add("value3");
+        assertFalse(this.coll.containsAll(coll));
+        verify(extractor, keys);
+    }
+
+    /**
+     * 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);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        replay(extractor, keys);
+        Iterator<String> entryIt = coll.iterator();
+        assertTrue(entryIt.hasNext());
+        assertEquals("value2", entryIt.next());
+        verify(extractor, keys);
+    }
+
+    /**
+     * 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);
+
+        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.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        String[] entryArray = new String[] {"value1", "value2"};
+
+        replay(extractor, keys);
+        assertArrayEquals(entryArray, coll.toArray());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link Collection#toArray(Object[])}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testToArrayTArray() {
+        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);
+
+        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("two")).andReturn("value2");
+
+        String[] entryArray = new String[] {"value1", "value2"};
+
+        replay(extractor, keys);
+        String[] realArray = new String[2];
+        assertArrayEquals(entryArray, coll.toArray(realArray));
+        verify(extractor, keys);
+    }
+}

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

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



Mime
View raw message