This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/commons-ognl.git
The following commit(s) were added to refs/heads/trunk by this push: new d819159 enhance MethodPermCacheTest new fc7b81e Merge pull request #3 from sullis/enhance-MethodPermCacheTest d819159 is described below commit d819159cc41f01ae26fb0f0671338c1ae4b2c133 Author: Sean Sullivan <ssulli...@gilt.com> AuthorDate: Mon Jun 18 09:08:16 2018 -0700 enhance MethodPermCacheTest --- .../commons/ognl/internal/MethodPermCacheTest.java | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/commons/ognl/internal/MethodPermCacheTest.java b/src/test/java/org/apache/commons/ognl/internal/MethodPermCacheTest.java index 829ffb3..af7a77e 100644 --- a/src/test/java/org/apache/commons/ognl/internal/MethodPermCacheTest.java +++ b/src/test/java/org/apache/commons/ognl/internal/MethodPermCacheTest.java @@ -34,21 +34,35 @@ import java.security.Permission; * Date: 10/17/11 * Time: 12:13 AM */ -public class MethodPermCacheTest -{ - private SecurityManager securityManager =new DummySecurityManager(); +public class MethodPermCacheTest { + private SecurityManager allowAllSecurityManager = new AllowAllSecurityManager(); + private SecurityManager denyAllSecurityManager = new DenyAllSecurityManager(); + + private Cache<Method, Boolean> createCache(SecurityManager securityManager) { + return new ConcurrentHashMapCache<Method, Boolean>(new MethodPermCacheEntryFactory(securityManager) ); + } - Cache<Method, Boolean> cache = - new ConcurrentHashMapCache<Method, Boolean>( new MethodPermCacheEntryFactory( securityManager ) ); @Test - public void testGetPublicMethod( ) + public void testGetPublicMethod_returnsTrue( ) throws CacheException, NoSuchMethodException { + Cache<Method, Boolean> cache = createCache(allowAllSecurityManager); + Method method = Root.class.getMethod( "getArray"); Assert.assertTrue( cache.get( method ) ); } - private class DummySecurityManager + @Test + public void testGetPublicMethod_returnsFalse( ) + throws CacheException, NoSuchMethodException + { + Cache<Method, Boolean> cache = createCache(denyAllSecurityManager); + Method method = Root.class.getMethod( "getArray"); + + Assert.assertFalse( cache.get( method ) ); + } + + private class AllowAllSecurityManager extends SecurityManager { @Override @@ -56,4 +70,14 @@ public class MethodPermCacheTest { } } + + private class DenyAllSecurityManager + extends SecurityManager + { + @Override + public void checkPermission( Permission perm ) + { + throw new SecurityException("Denied."); + } + } }