commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r592643 - /commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/
Date Wed, 07 Nov 2007 07:25:31 GMT
Author: bayard
Date: Tue Nov  6 23:25:30 2007
New Revision: 592643

URL: http://svn.apache.org/viewvc?rev=592643&view=rev
Log:
Applying Scott Bassin's patch from LANG-371, adding unit tests that follow the approach of
his previous patch to the documentation

Modified:
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/DefaultToStringStyleTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/MultiLineToStringStyleTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/NoFieldNamesToStringStyleTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ShortPrefixToStringStyleTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/SimpleToStringStyleTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/StandardToStringStyleTest.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringStyleTest.java

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/DefaultToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/DefaultToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/DefaultToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/DefaultToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.apache.commons.lang.builder.ToStringStyleTest.Person;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -89,6 +91,15 @@
         assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", new HashMap(),
true).toString());
         assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a",
(Object) new String[0], false).toString());
         assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new
String[0], true).toString());
+    }
+
+    public void testPerson() {
+        Person p = new Person();
+        p.name = "John Doe";
+        p.age = 33;
+        p.smoker = false;
+        String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
+        assertEquals(pBaseStr + "[name=John Doe,age=33,smoker=false]", new ToStringBuilder(p).append("name",
p.name).append("age", p.age).append("smoker", p.smoker).toString());
     }
 
     public void testLong() {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/MultiLineToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/MultiLineToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/MultiLineToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/MultiLineToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -25,6 +25,7 @@
 import junit.textui.TestRunner;
 
 import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.builder.ToStringStyleTest.Person;
 
 /**
  * Unit tests {@link org.apache.commons.lang.builder.MultiLineToStringStyleTest}.
@@ -91,6 +92,15 @@
         assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "  a={}" + SystemUtils.LINE_SEPARATOR
+ "]", new ToStringBuilder(base).append("a", new HashMap(), true).toString());
         assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "  a=<size=0>" +
SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", (Object) new String[0],
false).toString());
         assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "  a={}" + SystemUtils.LINE_SEPARATOR
+ "]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
+    }
+
+    public void testPerson() {
+        Person p = new Person();
+        p.name = "Jane Doe";
+        p.age = 25;
+        p.smoker = true;
+        String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
+        assertEquals(pBaseStr + "[" + SystemUtils.LINE_SEPARATOR + "  name=Jane Doe" + SystemUtils.LINE_SEPARATOR
+ "  age=25" + SystemUtils.LINE_SEPARATOR + "  smoker=true" + SystemUtils.LINE_SEPARATOR +
"]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
     }
 
     public void testLong() {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/NoFieldNamesToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/NoFieldNamesToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/NoFieldNamesToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/NoFieldNamesToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.apache.commons.lang.builder.ToStringStyleTest.Person;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -89,6 +91,15 @@
         assertEquals(baseStr + "[{}]", new ToStringBuilder(base).append("a", new HashMap(),
true).toString());
         assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a",
(Object) new String[0], false).toString());
         assertEquals(baseStr + "[{}]", new ToStringBuilder(base).append("a", (Object) new
String[0], true).toString());
+    }
+
+    public void testPerson() {
+        Person p = new Person();
+        p.name = "Ron Paul";
+        p.age = 72;
+        p.smoker = false;
+        String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
+        assertEquals(pBaseStr + "[Ron Paul,72,false]", new ToStringBuilder(p).append("name",
p.name).append("age", p.age).append("smoker", p.smoker).toString());
     }
 
     public void testLong() {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ShortPrefixToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ShortPrefixToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ShortPrefixToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ShortPrefixToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.apache.commons.lang.builder.ToStringStyleTest.Person;
+
 import junit.framework.TestCase;
 
 /**
@@ -72,6 +74,15 @@
         assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", new HashMap(),
true).toString());
         assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a",
(Object) new String[0], false).toString());
         assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new
String[0], true).toString());
+    }
+
+    public void testPerson() {
+        Person p = new Person();
+        p.name = "John Q. Public";
+        p.age = 45;
+        p.smoker = true;
+        String pBaseStr = p.getClass().getName();
+        assertEquals(pBaseStr + "[name=John Q. Public,age=45,smoker=true]", new ToStringBuilder(p).append("name",
p.name).append("age", p.age).append("smoker", p.smoker).toString());
     }
 
     public void testLong() {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/SimpleToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/SimpleToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/SimpleToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/SimpleToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.apache.commons.lang.builder.ToStringStyleTest.Person;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -88,6 +90,14 @@
         assertEquals("{}", new ToStringBuilder(base).append("a", new HashMap(), true).toString());
         assertEquals("<size=0>", new ToStringBuilder(base).append("a", (Object) new
String[0], false).toString());
         assertEquals("{}", new ToStringBuilder(base).append("a", (Object) new String[0],
true).toString());
+    }
+
+    public void testPerson() {
+        Person p = new Person();
+        p.name = "Jane Q. Public";
+        p.age = 47;
+        p.smoker = false;
+        assertEquals("Jane Q. Public,47,false", new ToStringBuilder(p).append("name", p.name).append("age",
p.age).append("smoker", p.smoker).toString());
     }
 
     public void testLong() {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/StandardToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/StandardToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/StandardToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/StandardToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.apache.commons.lang.builder.ToStringStyleTest.Person;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -104,6 +106,15 @@
         assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", new HashMap(),
true).toString());
         assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", (Object)
new String[0], false).toString());
         assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", (Object) new
String[0], true).toString());
+    }
+
+    public void testPerson() {
+        Person p = new Person();
+        p.name = "Suzy Queue";
+        p.age = 19;
+        p.smoker = false;
+        String pBaseStr = "ToStringStyleTest.Person";
+        assertEquals(pBaseStr + "[name=Suzy Queue,age=19,smoker=false]", new ToStringBuilder(p).append("name",
p.name).append("age", p.age).append("smoker", p.smoker).toString());
     }
 
     public void testLong() {

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringStyleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringStyleTest.java?rev=592643&r1=592642&r2=592643&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringStyleTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringStyleTest.java
Tue Nov  6 23:25:30 2007
@@ -123,4 +123,25 @@
         assertEquals("", style.getSummaryObjectEndText());
     }
 
+    /**
+     * An object used to test {@link ToStringStyle}.
+     * 
+     * @author Scott Bassin
+     */
+    static class Person {
+        /**
+         * Test String field.
+         */
+        String name;
+
+        /**
+         * Test integer field.
+         */
+        int age;
+
+        /**
+         * Test boolean field.
+         */
+        boolean smoker;
+    }
 }



Mime
View raw message