You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2018/08/29 05:57:36 UTC

[struts] branch master updated: WW-4954 Adds a test case to cover accessing ArrayList

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/master by this push:
     new 6420f40  WW-4954 Adds a test case to cover accessing ArrayList
6420f40 is described below

commit 6420f4068f8ddbc54c022fb57d3bed881934b6a6
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Aug 29 07:57:16 2018 +0200

    WW-4954 Adds a test case to cover accessing ArrayList
---
 .../opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java    | 12 +++++-------
 .../com/opensymphony/xwork2/test/TestArrayBean.java     | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 7 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 9f1f496..1bd07e5 100644
--- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java
@@ -18,11 +18,9 @@
  */
 package com.opensymphony.xwork2.ognl;
 
+import com.opensymphony.xwork2.test.TestArrayBean;
 import org.apache.struts2.StrutsInternalTestCase;
 
-import java.util.ArrayList;
-import java.util.List;
-
 public class OgnlUtilStrutsTest extends StrutsInternalTestCase {
 
     private OgnlUtil ognlUtil;
@@ -59,12 +57,12 @@ public class OgnlUtilStrutsTest extends StrutsInternalTestCase {
 
     public void testAccessToSizeMethod() throws Exception {
         // given
-        List<String> list = new ArrayList<>();
-        list.add("1");
-        list.add("2");
+        TestArrayBean bean = new TestArrayBean();
+        bean.getPersons().add("Alice");
+        bean.getPersons().add("Mich");
 
         // when
-        Object value = ognlUtil.getValue("size() > 0", ognlUtil.createDefaultContext(list), list);
+        Object value = ognlUtil.getValue("persons.size() > 0", ognlUtil.createDefaultContext(bean), bean);
 
         // then
         assertTrue(value instanceof Boolean);
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/TestArrayBean.java b/core/src/test/java/com/opensymphony/xwork2/test/TestArrayBean.java
new file mode 100644
index 0000000..1a30f05
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/TestArrayBean.java
@@ -0,0 +1,17 @@
+package com.opensymphony.xwork2.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestArrayBean {
+
+    private List<String> persons = new ArrayList<>();
+
+    public void setPersons(List<String> persons) {
+        this.persons = persons;
+    }
+
+    public List<String> getPersons() {
+        return persons;
+    }
+}