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 2013/11/04 23:41:27 UTC

git commit: TAP5-2154: Environment keys with empty associated stacks should not be listed as available

Updated Branches:
  refs/heads/master ed82f71a8 -> 63e49a702


TAP5-2154: Environment keys with empty associated stacks should not be listed as available


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

Branch: refs/heads/master
Commit: 63e49a702a9abc839bdf860ecbb6a9945f5ed96e
Parents: ed82f71
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Nov 4 14:41:23 2013 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Nov 4 14:41:23 2013 -0800

----------------------------------------------------------------------
 .../internal/services/EnvironmentImpl.java      | 14 +++++++---
 .../internal/services/EnvironmentImplTest.java  | 28 +++++++++++++++++++-
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/63e49a70/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
index 016e732..599d4c4 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2011 The Apache Software Foundation
+// Copyright 2006-2013 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.
@@ -16,6 +16,7 @@ package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Mapper;
+import org.apache.tapestry5.func.Predicate;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.OneShotLock;
 import org.apache.tapestry5.ioc.services.ThreadCleanupListener;
@@ -27,6 +28,7 @@ import org.apache.tapestry5.services.Environment;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * A non-threadsafe implementation (expects to use the "perthread" service lifecyle).
@@ -87,11 +89,15 @@ public class EnvironmentImpl implements Environment, ThreadCleanupListener
 
             throw new UnknownValueException(String.format("No object of type %s is available from the Environment.", type.getName()),
                     new AvailableValues("Environmentals",
-                            F.flow(typeToStack.keySet()).map(new Mapper<Class, String>()
+                            F.flow(typeToStack.entrySet()).remove(new Predicate<Entry<Class, LinkedList>>() {
+                              public boolean accept(Entry<Class, LinkedList> element) {
+                                return element.getValue().isEmpty();
+                              }
+                            }).map(new Mapper<Entry<Class, LinkedList>, String>()
                             {
-                                public String map(Class element)
+                                public String map(Entry<Class, LinkedList> element)
                                 {
-                                    return element.getName();
+                                    return element.getKey().getName();
                                 }
                             }).toList()));
         }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/63e49a70/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
index 7036072..a2396c9 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2011 The Apache Software Foundation
+// Copyright 2006-2013 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.
@@ -128,4 +128,30 @@ public class EnvironmentImplTest extends TapestryTestCase
 
         verify();
     }
+    
+    @Test
+    public void peek_required_does_not_list_previouly_available()
+    {
+        Environment e = new EnvironmentImpl();
+        Location l = mockLocation();
+
+        replay();
+
+        e.push(Location.class, l);
+        e.pop(Location.class);
+
+        try
+        {
+            e.peekRequired(Location.class);
+            unreachable();
+        } catch (UnknownValueException ex)
+        {
+            assertEquals(
+                    ex.getMessage(),
+                    "No object of type org.apache.tapestry5.ioc.Location is available from the Environment.");
+            assertFalse(ex.getAvailableValues().getValues().contains("org.apache.tapestry5.ioc.Location"));
+        }
+
+        verify();
+    }
 }