Commits

Anonymous committed cc8346d

Tests for type conversion in collections.

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@297e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

src/test/com/opensymphony/xwork/test/User.java

  */
 package com.opensymphony.xwork.test;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
 
 /**
  * Test bean.
 public class User implements UserMarker {
     //~ Instance fields ////////////////////////////////////////////////////////
 
+    private Collection m_collection;
+    private List m_list;
+    private Map m_map;
     private String m_email;
     private String m_email2;
     private String m_name;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
+    public void setCollection(Collection collection) {
+        m_collection = collection;
+    }
+
+    public Collection getCollection() {
+        return m_collection;
+    }
+
     public void setEmail(String email) {
         m_email = email;
     }
         return m_email2;
     }
 
+    public void setList(List l) {
+        m_list = l;
+    }
+
+    public List getList() {
+        return m_list;
+    }
+
+    public void setMap(Map m) {
+        m_map = m;
+    }
+
+    public Map getMap() {
+        return m_map;
+    }
+
     public void setName(String name) {
         m_name = name;
     }

src/test/com/opensymphony/xwork/util/XWorkListTest.java

  */
 package com.opensymphony.xwork.util;
 
+import com.opensymphony.xwork.test.User;
+
 import junit.framework.TestCase;
 
 import java.util.ArrayList;
+import java.util.Map;
 
 
 /**
         assertEquals("2", xworkList.get(4));
         assertEquals("3", xworkList.get(5));
 
-
         // take 2, no trim
         xworkList = new XWorkList(String.class);
         xworkList.add(new String[] {"a"});
         assertEquals("3", xworkList.get(3));
         assertEquals("b", xworkList.get(4));
     }
+
+    public void testSetValue() {
+        OgnlValueStack stack = new OgnlValueStack();
+        Map stackContext = stack.getContext();
+        stackContext.put(InstantiatingNullHandler.CREATE_NULL_OBJECTS, Boolean.TRUE);
+        stackContext.put(XWorkMethodAccessor.DENY_METHOD_EXECUTION, Boolean.TRUE);
+        stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+        User user = new User();
+        stack.push(user);
+
+        // indexed string
+        stack.setValue("list[1]", "asdf");
+        assertNotNull(user.getList());
+        assertEquals(2, user.getList().size());
+        assertEquals(String.class, user.getList().get(0).getClass());
+        assertEquals("asdf", user.getList().get(1));
+    }
 }