You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/06/21 18:24:28 UTC

[2/2] git commit: Remove meaningless tests for CollectionFactory Inline methods used only once

Remove meaningless tests for CollectionFactory
Inline methods used only once


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/df4202c6
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/df4202c6
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/df4202c6

Branch: refs/heads/master
Commit: df4202c69610d553ee4eba51119f26c3fb4e69a5
Parents: d01ba78
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Jun 21 08:45:32 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Jun 21 08:45:32 2012 -0700

----------------------------------------------------------------------
 .../internal/services/AssetSourceImpl.java         |    5 +-
 .../internal/services/MessagesSourceImpl.java      |   18 +-
 .../internal/services/RenderQueueImpl.java         |   15 +-
 .../ioc/internal/util/CollectionFactory.java       |   19 +--
 .../ioc/internal/util/CollectionFactoryTest.java   |  152 ---------------
 5 files changed, 20 insertions(+), 189 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/df4202c6/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetSourceImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetSourceImpl.java
index bf4846a..6830ec4 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetSourceImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetSourceImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import org.apache.tapestry5.services.AssetSource;
 import java.lang.ref.SoftReference;
 import java.util.Locale;
 import java.util.Map;
+import java.util.WeakHashMap;
 
 @SuppressWarnings("all")
 public class AssetSourceImpl implements AssetSource
@@ -39,7 +40,7 @@ public class AssetSourceImpl implements AssetSource
 
     private final Map<String, Resource> prefixToRootResource = CollectionFactory.newMap();
 
-    private final Map<Resource, SoftReference<Asset>> cache = CollectionFactory.newWeakHashMap();
+    private final Map<Resource, SoftReference<Asset>> cache = new WeakHashMap<Resource, SoftReference<Asset>>();
 
     private final SymbolSource symbolSource;
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/df4202c6/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
index 2d039ec..119bee6 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,10 +14,6 @@
 
 package org.apache.tapestry5.internal.services;
 
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.internal.event.InvalidationEventHubImpl;
 import org.apache.tapestry5.internal.util.MultiKey;
@@ -25,10 +21,15 @@ import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
+import org.apache.tapestry5.ioc.util.CaseInsensitiveMap;
 import org.apache.tapestry5.services.messages.PropertiesFileParser;
 import org.apache.tapestry5.services.pageload.ComponentResourceLocator;
 import org.apache.tapestry5.services.pageload.ComponentResourceSelector;
 
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
 /**
  * A utility class that encapsulates all the logic for reading properties files and assembling {@link Messages} from
  * them, in accordance with extension rules and locale. This represents code that was refactored out of
@@ -69,7 +70,7 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess
     private final Map<String, String> emptyMap = Collections.emptyMap();
 
     public MessagesSourceImpl(boolean productionMode, URLChangeTracker tracker,
-            ComponentResourceLocator resourceLocator, PropertiesFileParser propertiesFileParser)
+                              ComponentResourceLocator resourceLocator, PropertiesFileParser propertiesFileParser)
     {
         super(productionMode);
 
@@ -169,7 +170,7 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess
 
         // Make a copy of the base Map
 
-        Map<String, String> result = CollectionFactory.newCaseInsensitiveMap(base);
+        Map<String, String> result = new CaseInsensitiveMap<String>(base);
 
         // Add or overwrite properties to the copy
 
@@ -208,8 +209,7 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess
         try
         {
             return propertiesFileParser.parsePropertiesFile(resource);
-        }
-        catch (Exception ex)
+        } catch (Exception ex)
         {
             throw new RuntimeException(String.format("Unable to read message catalog from %s: %s", resource, ex), ex);
         }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/df4202c6/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderQueueImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderQueueImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderQueueImpl.java
index b8679c6..79dbbea 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderQueueImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderQueueImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ public class RenderQueueImpl implements RenderQueue
 {
     private static final int INITIAL_QUEUE_DEPTH = 200;
 
-    private final Stack<RenderCommand> queue = CollectionFactory.newStack(INITIAL_QUEUE_DEPTH);
+    private final Stack<RenderCommand> queue = new Stack<RenderCommand>(INITIAL_QUEUE_DEPTH);
 
     private final Stack<ComponentResources> renderingComponents = CollectionFactory.newStack();
 
@@ -72,8 +72,7 @@ public class RenderQueueImpl implements RenderQueue
 
                 command.render(writer, this);
             }
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             String message = String.format("Render queue error in %s: %s", command, InternalUtils.toMessage(ex));
 
@@ -88,10 +87,10 @@ public class RenderQueueImpl implements RenderQueue
         double elapsedSeconds = ((double) elapsedNanos) / 1000000000d;
 
         logger.debug(TapestryMarkers.RENDER_COMMANDS,
-                     String.format("Executed %,d rendering commands (max queue depth: %,d) in %.3f seconds",
-                                   commandCount,
-                                   maxDepth,
-                                   elapsedSeconds));
+                String.format("Executed %,d rendering commands (max queue depth: %,d) in %.3f seconds",
+                        commandCount,
+                        maxDepth,
+                        elapsedSeconds));
     }
 
     public void startComponent(ComponentResources resources)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/df4202c6/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/CollectionFactory.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/CollectionFactory.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/CollectionFactory.java
index c58da46..6711b1a 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/CollectionFactory.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/CollectionFactory.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -86,14 +86,6 @@ public final class CollectionFactory
     }
 
     /**
-     * @since 5.3
-     */
-    public static <K, V> Map<K, V> newWeakHashMap()
-    {
-        return new WeakHashMap<K, V>();
-    }
-
-    /**
      * Contructs and returns a new generic {@link java.util.ArrayList} instance.
      */
     public static <T> List<T> newList()
@@ -139,18 +131,9 @@ public final class CollectionFactory
         return new Stack<T>();
     }
 
-    public static <T> Stack<T> newStack(int initialSize)
-    {
-        return new Stack<T>(initialSize);
-    }
-
     public static <V> Map<String, V> newCaseInsensitiveMap()
     {
         return new CaseInsensitiveMap<V>();
     }
 
-    public static <V> Map<String, V> newCaseInsensitiveMap(Map<String, ? extends V> map)
-    {
-        return new CaseInsensitiveMap<V>(map);
-    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/df4202c6/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/CollectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/CollectionFactoryTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/CollectionFactoryTest.java
deleted file mode 100644
index a452bd6..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/CollectionFactoryTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2006, 2007 The Apache Software Foundation
-//
-// Licensed 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.tapestry5.ioc.internal.util;
-
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.*;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import java.util.*;
-import static java.util.Arrays.asList;
-
-public class CollectionFactoryTest extends Assert
-{
-
-    @Test
-    public void new_map()
-    {
-        Map<String, Class> map = newMap();
-
-        assertTrue(map instanceof HashMap);
-    }
-
-    @Test
-    public void copy_map()
-    {
-        Map<String, Class> map = newMap();
-
-        map.put("this", CollectionFactoryTest.class);
-
-        Map<String, Class> copy = CollectionFactory.newMap(map);
-
-        assertEquals(copy, map);
-
-        map.put("other", Map.class);
-
-        assertFalse(copy.equals(map));
-    }
-
-    @Test
-    public void new_set()
-    {
-        Set<String> set = newSet();
-
-        assertTrue(set instanceof HashSet);
-    }
-
-    @Test
-    public void copy_set()
-    {
-        List<String> start = asList("fred", "barney");
-
-        Set<String> set = newSet(start);
-
-        assertEquals(set.size(), 2);
-        assertTrue(set.contains("fred"));
-        assertTrue(set.contains("barney"));
-    }
-
-    @Test
-    public void set_from_varargs()
-    {
-        Set<String> set = newSet("fred", "barney");
-
-        assertEquals(set.size(), 2);
-        assertTrue(set.contains("fred"));
-        assertTrue(set.contains("barney"));
-    }
-
-    @Test
-    public void new_list()
-    {
-        List<String> list = newList();
-
-        assertTrue(list instanceof ArrayList);
-    }
-
-    @Test
-    public void new_list_copy()
-    {
-        List<String> start = Arrays.asList("Fred", "Barney", "Wilma");
-        List<String> copy = newList(start);
-
-        assertNotSame(copy, start);
-        assertEquals(copy, start);
-    }
-
-    @Test
-    public void new_list_from_elements()
-    {
-        List<String> list = newList("Fred", "Barney");
-
-        assertEquals(list.size(), 2);
-        assertEquals(list.get(0), "Fred");
-        assertEquals(list.get(1), "Barney");
-    }
-
-    private static final int THREAD_COUNT = 20;
-
-    @Test
-    public void new_threadsafe_list() throws Exception
-    {
-        final List<String> threadNames = CollectionFactory.newThreadSafeList();
-
-        List<Thread> threads = CollectionFactory.newList();
-
-        Runnable r = new Runnable()
-        {
-            public void run()
-            {
-                String name = Thread.currentThread().getName();
-                threadNames.add(name);
-            }
-        };
-
-        for (int i = 0; i < THREAD_COUNT; i++)
-        {
-            Thread t = new Thread(r);
-            threads.add(t);
-        }
-
-        // Start all the threads at the same time.
-
-        for (Thread t : threads)
-        {
-            t.start();
-        }
-
-        // Wait for all threads to complete
-
-        for (Thread t : threads)
-        {
-            t.join();
-        }
-
-        // Make sure they all executed. If the list was not thread safe, highly unlikely this
-        // would work.
-
-        assertEquals(threadNames.size(), THREAD_COUNT);
-    }
-}