WW-4954 Adds a test case to cover accessing ArrayList

This commit is contained in:
Lukasz Lenart
2018-08-29 07:57:16 +02:00
parent 899b4a6025
commit 6420f4068f
2 changed files with 22 additions and 7 deletions
@@ -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);
@@ -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;
}
}