tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r937008 - in /tiles/sandbox/trunk/tiles-request/tiles-request-api/src: main/java/org/apache/tiles/request/collection/ test/java/org/apache/tiles/request/collection/ test/java/org/apache/tiles/request/scope/
Date Thu, 22 Apr 2010 18:58:04 GMT
Author: apetrelli
Date: Thu Apr 22 18:58:04 2010
New Revision: 937008

URL: http://svn.apache.org/viewvc?rev=937008&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/
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AbstractEnumerationMapTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AddableParameterMapTest.java
  (with props)
Modified:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AbstractEnumerationMap.java
    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/test/java/org/apache/tiles/request/scope/ReflectionContextResolverTest.java

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AbstractEnumerationMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AbstractEnumerationMap.java?rev=937008&r1=937007&r2=937008&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AbstractEnumerationMap.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AbstractEnumerationMap.java
Thu Apr 22 18:58:04 2010
@@ -1,7 +1,9 @@
 package org.apache.tiles.request.collection;
 
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.tiles.request.collection.extractor.HasKeys;
 
@@ -19,15 +21,21 @@ public abstract class AbstractEnumeratio
     public boolean equals(Object o) {
         HasKeys<V> otherRequest = ((AbstractEnumerationMap<V>) o).request;
         boolean retValue = true;
+        Set<String> otherKeys = new HashSet<String>();
+        for (Enumeration<String> attribs = otherRequest.getKeys(); attribs
+                .hasMoreElements();) {
+            otherKeys.add(attribs.nextElement());
+        }
         for (Enumeration<String> attribs = request.getKeys(); attribs
                 .hasMoreElements()
                 && retValue;) {
             String parameterName = attribs.nextElement();
             retValue = request.getValue(parameterName).equals(
                     otherRequest.getValue(parameterName));
+            otherKeys.remove(parameterName);
         }
 
-        return retValue;
+        return retValue && otherKeys.isEmpty();
     }
 
     /** {@inheritDoc} */

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=937008&r1=937007&r2=937008&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
Thu Apr 22 18:58:04 2010
@@ -21,7 +21,6 @@
 package org.apache.tiles.request.collection;
 
 import java.util.Collection;
-import java.util.Enumeration;
 import java.util.Map;
 import java.util.Set;
 
@@ -55,29 +54,11 @@ public class AddableParameterMap extends
         return new HeaderEntrySet();
     }
 
-
-    /** {@inheritDoc} */
-    @Override
-    public boolean equals(Object o) {
-        EnumeratedValuesExtractor otherRequest = ((AddableParameterMap) o).request;
-        boolean retValue = true;
-        synchronized (request) {
-            for (Enumeration<String> attribs = request.getKeys(); attribs
-                    .hasMoreElements()
-                    && retValue;) {
-                String parameterName = attribs.nextElement();
-                retValue = request.getValue(parameterName).equals(
-                        otherRequest.getValue(parameterName));
-            }
-        }
-
-        return retValue;
-    }
-
     /** {@inheritDoc} */
     public String put(String key, String value) {
+        String oldValue = request.getValue(key);
         request.setValue(key, value);
-        return value;
+        return oldValue;
     }
 
 

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AbstractEnumerationMapTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AbstractEnumerationMapTest.java?rev=937008&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AbstractEnumerationMapTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AbstractEnumerationMapTest.java
Thu Apr 22 18:58:04 2010
@@ -0,0 +1,141 @@
+/**
+ *
+ */
+package org.apache.tiles.request.collection;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+
+import org.apache.tiles.request.collection.extractor.HasKeys;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link AbstractEnumerationMap}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractEnumerationMapTest {
+
+    private HasKeys<Integer> request;
+
+    private AbstractEnumerationMap<Integer> map;
+
+    /**
+     * Sets up the test.
+     */
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setUp() {
+        request = createMock(HasKeys.class);
+        map = createMockBuilder(AbstractEnumerationMap.class).withConstructor(
+                request).createMock();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.AbstractEnumerationMap#hashCode()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testHashCode() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(request.getKeys()).andReturn(keys);
+
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("first");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("second");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        Integer value1 = 1;
+
+        expect(request.getValue("first")).andReturn(value1);
+        expect(request.getValue("second")).andReturn(null);
+
+        replay(request, map, keys);
+        assertEquals(("first".hashCode() ^ value1.hashCode())
+                + ("second".hashCode() ^ 0), map.hashCode());
+        verify(request, map, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.AbstractEnumerationMap#equals(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testEqualsObject() {
+        HasKeys<Integer> otherRequest = createMock(HasKeys.class);
+        AbstractEnumerationMap<Integer> otherMap = createMockBuilder(
+                AbstractEnumerationMap.class).withConstructor(otherRequest)
+                .createMock();
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> otherKeys = createMock(Enumeration.class);
+
+        expect(request.getKeys()).andReturn(keys);
+        expect(otherRequest.getKeys()).andReturn(otherKeys);
+
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("first");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("second");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(request.getValue("first")).andReturn(1);
+        expect(request.getValue("second")).andReturn(2);
+
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("first");
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("second");
+        expect(otherKeys.hasMoreElements()).andReturn(false);
+
+        expect(otherRequest.getValue("first")).andReturn(1);
+        expect(otherRequest.getValue("second")).andReturn(2);
+
+        replay(request, map, otherRequest, otherMap, keys, otherKeys);
+        assertTrue(map.equals(otherMap));
+        verify(request, map, otherRequest, otherMap, keys, otherKeys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.AbstractEnumerationMap#equals(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testEqualsObjectFalse() {
+        HasKeys<Integer> otherRequest = createMock(HasKeys.class);
+        AbstractEnumerationMap<Integer> otherMap = createMockBuilder(
+                AbstractEnumerationMap.class).withConstructor(otherRequest)
+                .createMock();
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> otherKeys = createMock(Enumeration.class);
+
+        expect(request.getKeys()).andReturn(keys);
+        expect(otherRequest.getKeys()).andReturn(otherKeys);
+
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("first");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("second");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(request.getValue("first")).andReturn(1);
+        expect(request.getValue("second")).andReturn(2);
+
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("first");
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("second");
+        expect(otherKeys.hasMoreElements()).andReturn(false);
+
+        expect(otherRequest.getValue("first")).andReturn(1);
+        expect(otherRequest.getValue("second")).andReturn(3);
+
+        replay(request, map, otherRequest, otherMap, keys, otherKeys);
+        assertFalse(map.equals(otherMap));
+        verify(request, map, otherRequest, otherMap, keys, otherKeys);
+    }
+}

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

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AbstractEnumerationMapTest.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/AddableParameterMapTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AddableParameterMapTest.java?rev=937008&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AddableParameterMapTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/AddableParameterMapTest.java
Thu Apr 22 18:58:04 2010
@@ -0,0 +1,90 @@
+/**
+ *
+ */
+package org.apache.tiles.request.collection;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+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.MapEntry;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link AddableParameterMap}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AddableParameterMapTest {
+
+    private AddableParameterMap map;
+
+    private EnumeratedValuesExtractor extractor;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(EnumeratedValuesExtractor.class);
+        map = new AddableParameterMap(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.AddableParameterMap#entrySet()}.
+     */
+    @Test
+    public void testEntrySet() {
+        Set<Map.Entry<String, String>> entrySet = map.entrySet();
+        MapEntry<String, String> entry1 = new MapEntry<String, String>("one",
"value1", false);
+        MapEntry<String, String> entry2 = new MapEntry<String, String>("two",
"value2", false);
+        List<Map.Entry<String, String>> entries = new ArrayList<Map.Entry<String,String>>(2);
+        entries.add(entry1);
+        entries.add(entry2);
+
+        extractor.setValue("one", "value1");
+        expectLastCall().times(2);
+        extractor.setValue("two", "value2");
+        replay(extractor);
+        entrySet.add(entry1);
+        entrySet.addAll(entries);
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.AddableParameterMap#put(java.lang.String,
java.lang.String)}.
+     */
+    @Test
+    public void testPut() {
+        expect(extractor.getValue("one")).andReturn(null);
+        extractor.setValue("one", "value1");
+
+        replay(extractor);
+        assertNull(map.put("one", "value1"));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.AddableParameterMap#putAll(java.util.Map)}.
+     */
+    @Test
+    public void testPutAll() {
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("one", "value1");
+        map.put("two", "value2");
+
+        extractor.setValue("one", "value1");
+        extractor.setValue("two", "value2");
+
+        replay(extractor);
+        this.map.putAll(map);
+        verify(extractor);
+    }
+}

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

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

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/scope/ReflectionContextResolverTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/scope/ReflectionContextResolverTest.java?rev=937008&r1=937007&r2=937008&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/scope/ReflectionContextResolverTest.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/scope/ReflectionContextResolverTest.java
Thu Apr 22 18:58:04 2010
@@ -153,6 +153,7 @@ public class ReflectionContextResolverTe
             return threeScope;
         }
 
+        @SuppressWarnings("unused")
         private Map<String, Object> getPrivateScope() {
             return null;
         }



Mime
View raw message