This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5341-classloaders in repository https://gitbox.apache.org/repos/asf/struts.git
commit dfb33b6287dc93c3a40ba006b111674fcf0b51dd Author: Kusal Kithul-Godage <g...@kusal.io> AuthorDate: Tue Aug 29 09:36:12 2023 +1000 WW-5341 Clean up OgnlUtilTest --- .../com/opensymphony/xwork2/ognl/OgnlUtil.java | 3 +- .../com/opensymphony/xwork2/ognl/OgnlUtilTest.java | 65 +++++++++++----------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java index c8639a1e6..25e7082e8 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java @@ -101,8 +101,7 @@ public class OgnlUtil { @Deprecated public OgnlUtil() { // Instantiate default Expression and BeanInfo caches (factories must be non-null). - this(new DefaultOgnlExpressionCacheFactory<>(), - new DefaultOgnlBeanInfoCacheFactory<>()); + this(new DefaultOgnlExpressionCacheFactory<>(), new DefaultOgnlBeanInfoCacheFactory<>()); } /** diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java index 736889886..3dbcbdafd 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java @@ -238,7 +238,9 @@ public class OgnlUtilTest extends XWorkTestCase { // Method expression which executes with success try { ognlUtil.callMethod("getBar()", context, foo); - assertTrue("Successfully executed method expression must have been cached", ognlUtil.expressionCacheSize() == 1); + assertEquals("Successfully executed method expression must have been cached", + 1, + ognlUtil.expressionCacheSize()); } catch (Exception ex) { fail("Method expression execution should have succeeded here. Exception: " + ex); } @@ -541,7 +543,7 @@ public class OgnlUtilTest extends XWorkTestCase { assertEquals(b1.getSomethingElse(), b2.getSomethingElse()); // id properties did not - assertEquals(b2.getId(), new Long(2)); + assertEquals(b2.getId(), Long.valueOf(2)); } @@ -959,8 +961,8 @@ public class OgnlUtilTest extends XWorkTestCase { assertNotNull(beans); assertEquals(22, beans.size()); assertEquals("Hello Santa", beans.get("title")); - assertEquals(new Long("123"), beans.get("ALong")); - assertEquals(new Integer("44"), beans.get("number")); + assertEquals(Long.valueOf("123"), beans.get("ALong")); + assertEquals(Integer.valueOf("44"), beans.get("number")); assertEquals(bar, beans.get("bar")); assertEquals(Boolean.TRUE, beans.get("useful")); } @@ -971,7 +973,7 @@ public class OgnlUtilTest extends XWorkTestCase { Map<String, Object> beans = ognlUtil.getBeanMap(bar); assertEquals(2, beans.size()); - assertEquals(new Integer("1"), beans.get("id")); + assertEquals(Integer.valueOf("1"), beans.get("id")); assertEquals("There is no read method for bar", beans.get("bar")); } @@ -1345,13 +1347,13 @@ public class OgnlUtilTest extends XWorkTestCase { public void testDefaultOgnlUtilAlternateConstructorArguments() { // Code coverage test for the OgnlUtil alternate constructor method, and verify expected behaviour. try { - OgnlUtil basicOgnlUtil = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<String, Object>(), null); + OgnlUtil basicOgnlUtil = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), null); fail("null beanInfoCacheFactory should result in exception"); } catch (IllegalArgumentException iaex) { // expected result } try { - OgnlUtil basicOgnlUtil = new OgnlUtil(null, new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>()); + OgnlUtil basicOgnlUtil = new OgnlUtil(null, new DefaultOgnlBeanInfoCacheFactory<>()); fail("null expressionCacheFactory should result in exception"); } catch (IllegalArgumentException iaex) { // expected result @@ -1359,7 +1361,8 @@ public class OgnlUtilTest extends XWorkTestCase { } public void testDefaultOgnlUtilExclusionsAlternateConstructorPopulated() { - OgnlUtil basicOgnlUtil = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<String, Object>(), new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>()); + OgnlUtil basicOgnlUtil = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), + new DefaultOgnlBeanInfoCacheFactory<>()); internalTestInitialEmptyOgnlUtilExclusions(basicOgnlUtil); internalTestOgnlUtilExclusionsImmutable(basicOgnlUtil); @@ -1734,7 +1737,7 @@ public class OgnlUtilTest extends XWorkTestCase { public void testGetExcludedClassesAlternateConstructorPopulated() { // Getter should return an immutable collection - OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<String, Object>(), new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>()); + OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), new DefaultOgnlBeanInfoCacheFactory<>()); util.setExcludedClasses("java.lang.Runtime,java.lang.ProcessBuilder,java.net.URL"); assertEquals(util.getExcludedClasses().size(), 3); try { @@ -1762,7 +1765,7 @@ public class OgnlUtilTest extends XWorkTestCase { public void testGetExcludedPackageNamePatternsAlternateConstructorPopulated() { // Getter should return an immutable collection - OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<String, Object>(), new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>()); + OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), new DefaultOgnlBeanInfoCacheFactory<>()); util.setExcludedPackageNamePatterns("java.lang."); assertEquals(util.getExcludedPackageNamePatterns().size(), 1); try { @@ -1779,24 +1782,24 @@ public class OgnlUtilTest extends XWorkTestCase { assertEquals("Initial evictionLimit did not match initial value", 2, defaultCache.getEvictionLimit()); defaultCache.setEvictionLimit(3); assertEquals("Updated evictionLimit did not match updated value", 3, defaultCache.getEvictionLimit()); - String lookupResult = defaultCache.get(Integer.valueOf(0)); + String lookupResult = defaultCache.get(0); assertNull("Lookup of empty cache returned non-null value ?", lookupResult); - defaultCache.put(Integer.valueOf(0), "Zero"); - lookupResult = defaultCache.get(Integer.valueOf(0)); + defaultCache.put(0, "Zero"); + lookupResult = defaultCache.get(0); assertEquals("Retrieved value does not match put value ?", "Zero", lookupResult); - defaultCache.put(Integer.valueOf(1), "One"); - defaultCache.put(Integer.valueOf(2), "Two"); + defaultCache.put(1, "One"); + defaultCache.put(2, "Two"); assertEquals("Default cache not size evictionlimit after adding three values ?", defaultCache.getEvictionLimit(), defaultCache.size()); - lookupResult = defaultCache.get(Integer.valueOf(2)); + lookupResult = defaultCache.get(2); assertEquals("Retrieved value does not match put value ?", "Two", lookupResult); - defaultCache.put(Integer.valueOf(3), "Three"); + defaultCache.put(3, "Three"); assertEquals("Default cache not size zero after an add that exceeded the evection limit ?", 0, defaultCache.size()); - lookupResult = defaultCache.get(Integer.valueOf(0)); + lookupResult = defaultCache.get(0); assertNull("Lookup of value 0 (should have been evicted with everything) returned non-null value ?", lookupResult); - lookupResult = defaultCache.get(Integer.valueOf(3)); + lookupResult = defaultCache.get(3); assertNull("Lookup of value 3 (should have been evicted with everything) returned non-null value ?", lookupResult); - defaultCache.putIfAbsent(Integer.valueOf(2), "Two"); - lookupResult = defaultCache.get(Integer.valueOf(2)); + defaultCache.putIfAbsent(2, "Two"); + lookupResult = defaultCache.get(2); assertEquals("Retrieved value does not match put value ?", "Two", lookupResult); defaultCache.clear(); assertEquals("Default cache not empty after clear ?", 0, defaultCache.size()); @@ -1807,22 +1810,22 @@ public class OgnlUtilTest extends XWorkTestCase { assertEquals("Initial evictionLimit did not match initial value", 2, lruCache.getEvictionLimit()); lruCache.setEvictionLimit(3); assertEquals("Updated evictionLimit did not match updated value", 3, lruCache.getEvictionLimit()); - String lookupResult = lruCache.get(Integer.valueOf(0)); + String lookupResult = lruCache.get(0); assertNull("Lookup of empty cache returned non-null value ?", lookupResult); - lruCache.put(Integer.valueOf(0), "Zero"); - lookupResult = lruCache.get(Integer.valueOf(0)); + lruCache.put(0, "Zero"); + lookupResult = lruCache.get(0); assertEquals("Retrieved value does not match put value ?", "Zero", lookupResult); - lruCache.put(Integer.valueOf(1), "One"); - lruCache.put(Integer.valueOf(2), "Two"); + lruCache.put(1, "One"); + lruCache.put(2, "Two"); assertEquals("LRU cache not size evictionlimit after adding three values ?", lruCache.getEvictionLimit(), lruCache.size()); - lookupResult = lruCache.get(Integer.valueOf(2)); + lookupResult = lruCache.get(2); assertEquals("Retrieved value does not match put value ?", "Two", lookupResult); - lruCache.put(Integer.valueOf(3), "Three"); + lruCache.put(3, "Three"); assertEquals("LRU cache not size evictionlimit after adding values ?", lruCache.getEvictionLimit(), lruCache.size()); - lookupResult = lruCache.get(Integer.valueOf(0)); + lookupResult = lruCache.get(0); assertNull("Lookup of value 0 (should have dropped off LRU cache) returned non-null value ?", lookupResult); - lruCache.putIfAbsent(Integer.valueOf(2), "Two"); - lookupResult = lruCache.get(Integer.valueOf(2)); + lruCache.putIfAbsent(2, "Two"); + lookupResult = lruCache.get(2); assertEquals("Retrieved value does not match put value ?", "Two", lookupResult); lruCache.clear(); assertEquals("LRU cache not empty after clear ?", 0, lruCache.size());