Commits

Anonymous committed 1931d22

fixed foo bean property to proper naming convention
added unit test to show taht stack.setValue works differenetly to OgnlUtil.setProperties

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

  • Participants
  • Parent commits 6d6f6ec

Comments (0)

Files changed (5)

File src/test/com/opensymphony/xwork/util/Bar.java

 
     String title;
     int somethingElse;
-
+	Long id;
+	
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void setSomethingElse(int somethingElse) {
     public String getTitle() {
         return title;
     }
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getId() {
+		return this.id;
+	}
 }

File src/test/com/opensymphony/xwork/util/Foo.java

         return useful;
     }
 
-    public long getaLong() {
+    public long getALong() {
         return aLong;
     }
 
-    public void setaLong(long aLong) {
+    public void setALong(long aLong) {
         this.aLong = aLong;
     }
 

File src/test/com/opensymphony/xwork/util/OgnlUtilTest.java

         props.put("aLong", "123a");
 
         OgnlUtil.setProperties(props, foo, context);
-        assertEquals(0, foo.getaLong());
+        assertEquals(0, foo.getALong());
     }
 
     public void testSetPropertiesBoolean() {
         assertEquals(123456, foo.getNumber());
     }
 
-    public void testStringToLong() {
-        Foo foo = new Foo();
+	public void testStringToLong() {
+		Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+		Map context = Ognl.createDefaultContext(foo);
 
-        HashMap props = new HashMap();
-        props.put("aLong", "123");
+		HashMap props = new HashMap();
+		props.put("aLong", "123");
 
-        OgnlUtil.setProperties(props, foo, context);
-        assertEquals(123, foo.getaLong());
+		OgnlUtil.setProperties(props, foo, context);
+		assertEquals(123, foo.getALong());
 
-        props.put("aLong", new String[] {"123"});
+		props.put("aLong", new String[] {"123"});
 
-        foo.setaLong(0);
-        OgnlUtil.setProperties(props, foo, context);
-        assertEquals(123, foo.getaLong());
-    }
+		foo.setALong(0);
+		OgnlUtil.setProperties(props, foo, context);
+		assertEquals(123, foo.getALong());
+	}
 
+	
     //~ Inner Classes //////////////////////////////////////////////////////////
 
     public static class Email {

File src/test/com/opensymphony/xwork/util/OgnlValueStackTest.java

         assertEquals("Rover", vs.findValue("name"));
     }
 
-    public void testSetBarAsString() {
+
+	public void testSetBarAsString() {
         Foo foo = new Foo();
 
         OgnlValueStack vs = new OgnlValueStack();

File src/test/com/opensymphony/xwork/util/SetPropertiesTest.java

+/*
+ * Created on 6/10/2003
+ *
+ */
+package com.opensymphony.xwork.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import ognl.Ognl;
+import junit.framework.TestCase;
+
+/**
+ * @author CameronBraid
+ *
+ */
+public class SetPropertiesTest extends TestCase
+{
+
+	/**
+	 * 
+	 */
+	public SetPropertiesTest(String a)
+	{
+		super(a);
+	}
+
+
+	public void testEmptyStringToLong() {
+		Bar bar = new Bar();
+		bar.setId(null);
+
+		Map context = Ognl.createDefaultContext(bar);
+
+		HashMap props = new HashMap();
+		props.put("id", "");
+
+		OgnlUtil.setProperties(props, bar, context);
+		assertNull(bar.getId());
+
+		props.put("id", new String[] {""});
+
+		bar.setId(null);
+		OgnlUtil.setProperties(props, bar, context);
+		assertNull(bar.getId());
+	}
+
+	public void testSetEmptyStringAsLong() {
+		Bar bar = new Bar();
+
+		OgnlValueStack vs = new OgnlValueStack();
+		vs.push(bar);
+
+		vs.setValue("id", "");
+		assertNull(bar.getId());
+
+		vs.setValue("id", new String[]{""});
+		assertNull(bar.getId());
+	}
+
+}