tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r937862 - 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/util/
Date Sun, 25 Apr 2010 19:25:10 GMT
Author: apetrelli
Date: Sun Apr 25 19:25:10 2010
New Revision: 937862

URL: http://svn.apache.org/viewvc?rev=937862&view=rev
Log:
TILESSB-31
Completed tests for tiles-request-api.

Added:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/RemovableKeySetTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/RequestUtilTest.java
  (with props)
Modified:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/RemovableKeySet.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/RemovableKeySet.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/RemovableKeySet.java?rev=937862&r1=937861&r2=937862&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/RemovableKeySet.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/RemovableKeySet.java
Sun Apr 25 19:25:10 2010
@@ -3,7 +3,9 @@ package org.apache.tiles.request.collect
 import static org.apache.tiles.request.util.RequestUtil.*;
 
 import java.util.Collection;
-import java.util.Map;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.Set;
 
 import org.apache.tiles.request.collection.extractor.HasRemovableKeys;
 
@@ -30,9 +32,9 @@ public class RemovableKeySet extends Key
     @SuppressWarnings("unchecked")
     @Override
     public boolean removeAll(Collection<?> c) {
-        Collection<Map.Entry<String, Object>> realCollection = (Collection<java.util.Map.Entry<String,
Object>>) c;
+        Collection<String> realCollection = (Collection<String>) c;
         boolean retValue = false;
-        for (Map.Entry<String, Object> entry : realCollection) {
+        for (String entry : realCollection) {
             retValue |= remove(entry);
         }
         return retValue;
@@ -43,8 +45,16 @@ public class RemovableKeySet extends Key
     public boolean retainAll(Collection<?> c) {
         Collection<String> realCollection = (Collection<String>) c;
         boolean retValue = false;
-        for (String key : realCollection) {
-            retValue |= remove(key);
+        Set<String> keysToRemove = new LinkedHashSet<String>();
+        for (Enumeration<String> keys = request.getKeys(); keys.hasMoreElements();
) {
+            String key = keys.nextElement();
+            if (!realCollection.contains(key)) {
+                retValue = true;
+                keysToRemove.add(key);
+            }
+        }
+        for (String key : keysToRemove) {
+            request.removeValue(key);
         }
         return retValue;
     }

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java?rev=937862&r1=937861&r2=937862&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java
Sun Apr 25 19:25:10 2010
@@ -25,6 +25,7 @@ import static org.apache.tiles.request.u
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -154,15 +155,19 @@ public class ScopeMap extends ReadOnlyEn
         public boolean retainAll(Collection<?> c) {
             Collection<Map.Entry<String, Object>> realCollection = (Collection<java.util.Map.Entry<String,
Object>>) c;
             boolean retValue = false;
+            Set<String> keysToRemove = new LinkedHashSet<String>();
             for (Enumeration<String> keys = context.getKeys(); keys.hasMoreElements();
) {
                 String key = keys.nextElement();
                 Object value = context.getValue(key);
                 Map.Entry<String, Object> entry = new MapEntry<String, Object>(key,
value, false);
                 if (!realCollection.contains(entry)) {
                     retValue = true;
-                    context.removeValue(key);
+                    keysToRemove.add(key);
                 }
             }
+            for (String key: keysToRemove) {
+                context.removeValue(key);
+            }
             return retValue;
         }
     }

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/RemovableKeySetTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/RemovableKeySetTest.java?rev=937862&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/RemovableKeySetTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/RemovableKeySetTest.java
Sun Apr 25 19:25:10 2010
@@ -0,0 +1,109 @@
+/**
+ *
+ */
+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.List;
+
+import org.apache.tiles.request.collection.extractor.HasRemovableKeys;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link RemovableKeySet}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RemovableKeySetTest {
+
+    private HasRemovableKeys<Integer> extractor;
+
+    private RemovableKeySet entrySet;
+
+    /**
+     * Sets up the test.
+     */
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setUp() {
+        extractor = createMock(HasRemovableKeys.class);
+        entrySet = new RemovableKeySet(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.RemovableKeySet#remove(java.lang.Object)}.
+     */
+    @Test
+    public void testRemove() {
+        expect(extractor.getValue("one")).andReturn(1);
+        extractor.removeValue("one");
+
+        replay(extractor);
+        assertTrue(entrySet.remove("one"));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.RemovableKeySet#remove(java.lang.Object)}.
+     */
+    @Test
+    public void testRemoveNoEffect() {
+        expect(extractor.getValue("one")).andReturn(null);
+
+        replay(extractor);
+        assertFalse(entrySet.remove("one"));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.RemovableKeySet#removeAll(java.util.Collection)}.
+     */
+    @Test
+    public void testRemoveAll() {
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
+        extractor.removeValue("one");
+        extractor.removeValue("two");
+
+        replay(extractor);
+        List<String> coll = new ArrayList<String>();
+        coll.add("one");
+        coll.add("two");
+        assertTrue(entrySet.removeAll(coll));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.RemovableKeySet#retainAll(java.util.Collection)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testRetainAll() {
+        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(true);
+        expect(keys.nextElement()).andReturn("three");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        extractor.removeValue("three");
+
+        replay(extractor, keys);
+        List<String> coll = new ArrayList<String>();
+        coll.add("one");
+        coll.add("two");
+        assertTrue(entrySet.retainAll(coll));
+        verify(extractor, keys);
+    }
+
+}

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

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

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java?rev=937862&r1=937861&r2=937862&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java
Sun Apr 25 19:25:10 2010
@@ -42,6 +42,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#add(Object)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testAdd() {
         Map.Entry<String, Object> entry = createMock(Map.Entry.class);
@@ -60,6 +61,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#add(Object)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testAddNoEffect() {
         Map.Entry<String, Object> entry = createMock(Map.Entry.class);
@@ -76,6 +78,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#addAll(java.util.Collection)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testAddAll() {
         Map.Entry<String, Object> entry1 = createMock(Map.Entry.class);
@@ -125,6 +128,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#remove(Object)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testRemove() {
         Map.Entry<String, Object> entry = createMock(Map.Entry.class);
@@ -142,6 +146,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#remove(Object)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testRemoveNoEffect() {
         Map.Entry<String, Object> entry = createMock(Map.Entry.class);
@@ -157,6 +162,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#addAll(java.util.Collection)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testRemoveAll() {
         Map.Entry<String, Object> entry1 = createMock(Map.Entry.class);
@@ -182,6 +188,7 @@ public class ScopeMapEntrySetTest {
     /**
      * Tests {@link Set#addAll(java.util.Collection)}
      */
+    @SuppressWarnings("unchecked")
     @Test
     public void testRetainAll() {
         Enumeration<String> keys = createMock(Enumeration.class);

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/RequestUtilTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/RequestUtilTest.java?rev=937862&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/RequestUtilTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/util/RequestUtilTest.java
Sun Apr 25 19:25:10 2010
@@ -0,0 +1,56 @@
+/**
+ *
+ */
+package org.apache.tiles.request.util;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+
+import org.junit.Test;
+
+/**
+ * Test {@link RequestUtil}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestUtilTest {
+
+    /**
+     * Test method for {@link org.apache.tiles.request.util.RequestUtil#key(java.lang.Object)}.
+     */
+    @Test
+    public void testKey() {
+        assertEquals("1", RequestUtil.key(1));
+        assertEquals("hello", RequestUtil.key("hello"));
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.util.RequestUtil#key(java.lang.Object)}.
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testKeyException() {
+        RequestUtil.key(null);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.util.RequestUtil#enumerationSize(java.util.Enumeration)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testEnumerationSize() {
+        Enumeration<Object> enumeration = createMock(Enumeration.class);
+
+        expect(enumeration.hasMoreElements()).andReturn(true);
+        expect(enumeration.nextElement()).andReturn(1);
+        expect(enumeration.hasMoreElements()).andReturn(true);
+        expect(enumeration.nextElement()).andReturn(1);
+        expect(enumeration.hasMoreElements()).andReturn(false);
+
+        replay(enumeration);
+        assertEquals(2, RequestUtil.enumerationSize(enumeration));
+        verify(enumeration);
+    }
+
+}

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

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



Mime
View raw message