From 7bb1ea25e0948b67a47d19dfca89b1f6cf2f4f45 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Fri, 24 Aug 2018 13:05:02 +0200 Subject: [PATCH] Adds additional test to check is ArrayList.size() is accessible --- .../xwork2/ognl/OgnlUtilStrutsTest.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java index bd371dd8c..9f1f49604 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java @@ -20,16 +20,19 @@ package com.opensymphony.xwork2.ognl; import org.apache.struts2.StrutsInternalTestCase; +import java.util.ArrayList; +import java.util.List; + public class OgnlUtilStrutsTest extends StrutsInternalTestCase { - + private OgnlUtil ognlUtil; - + @Override public void setUp() throws Exception { super.setUp(); ognlUtil = container.getInstance(OgnlUtil.class); } - + public void testDefaultExcludes() { ognlUtil.setExcludedClasses(""); ognlUtil.setExcludedPackageNames(""); @@ -39,18 +42,33 @@ public class OgnlUtilStrutsTest extends StrutsInternalTestCase { try { ognlUtil.getExcludedClasses().clear(); - } catch (Exception ex){ + } catch (Exception ex) { assertTrue(ex instanceof UnsupportedOperationException); } try { ognlUtil.getExcludedPackageNames().clear(); - } catch (Exception ex){ + } catch (Exception ex) { assertTrue(ex instanceof UnsupportedOperationException); } try { ognlUtil.getExcludedPackageNamePatterns().clear(); - } catch (Exception ex){ + } catch (Exception ex) { assertTrue(ex instanceof UnsupportedOperationException); } } + + public void testAccessToSizeMethod() throws Exception { + // given + List list = new ArrayList<>(); + list.add("1"); + list.add("2"); + + // when + Object value = ognlUtil.getValue("size() > 0", ognlUtil.createDefaultContext(list), list); + + // then + assertTrue(value instanceof Boolean); + assertTrue((Boolean) value); + } + }