mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
WW-4954 Adds a test case to cover accessing ArrayList
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user