commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang/builder ToStringBuilderTest.java
Date Thu, 23 Oct 2003 22:26:00 GMT
ggregory    2003/10/23 15:26:00

  Modified:    lang/src/test/org/apache/commons/lang/builder
                        ToStringBuilderTest.java
  Log:
  Add support for static field output.
  
  Main points: 
  
  (1) 
  Deprecate in ReflectionToStringBuilder:
  
  public static String toString(Object object, ToStringStyle style, boolean outputTransients,
boolean outputStatics)
  
  In favor of:
  
  public static String toString(Object object, ToStringStyle style, boolean outputTransients,
boolean outputStatics, Class reflectUpToClass)
  
  (2) New convenience methods ReflectionToStringBuilder.toStringWithStatics.
  
  Revision  Changes    Path
  1.11      +85 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java
  
  Index: ToStringBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ToStringBuilderTest.java	18 Aug 2003 02:22:26 -0000	1.10
  +++ ToStringBuilderTest.java	23 Oct 2003 22:26:00 -0000	1.11
  @@ -840,4 +840,88 @@
           assertEquals(baseStr + "[<null>]", new ToStringBuilder(base).append((Object)
array).toString());
       }
   
  +    public void testSimpleReflectionStatics() {
  +        SimpleReflectionStaticFieldsFixture instance1 = new SimpleReflectionStaticFieldsFixture();
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toString(instance1, null, false, true, SimpleReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toString(instance1, null, true, true, SimpleReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toStringWithStatics(instance1, SimpleReflectionStaticFieldsFixture.class));
  +    }
  +
  +    /**
  +     * Tests ReflectionToStringBuilder.toString() for statics.
  +     */
  +    public void testReflectionStatics() {
  +        ReflectionStaticFieldsFixture instance1 = new ReflectionStaticFieldsFixture();
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345,instanceString=instanceString,instanceInt=67890]",
  +            ReflectionToStringBuilder.toString(instance1, null, false, true, ReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345,staticTransientString=staticTransientString,staticTransientInt=54321,instanceString=instanceString,instanceInt=67890,transientString=transientString,transientInt=98765]",
  +            ReflectionToStringBuilder.toString(instance1, null, true, true, ReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345,instanceString=instanceString,instanceInt=67890]",
  +            ReflectionToStringBuilder.toStringWithStatics(instance1, null, ReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345,instanceString=instanceString,instanceInt=67890]",
  +            ReflectionToStringBuilder.toStringWithStatics(instance1, ReflectionStaticFieldsFixture.class));
  +    }
  +
  +    /**
  +     * Tests ReflectionToStringBuilder.toString() for statics.
  +     */
  +    public void testInheritedReflectionStatics() {
  +        InheritedReflectionStaticFieldsFixture instance1 = new InheritedReflectionStaticFieldsFixture();
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString2=staticString2,staticInt2=67890]",
  +            ReflectionToStringBuilder.toString(instance1, null, false, true, InheritedReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString2=staticString2,staticInt2=67890,staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toString(instance1, null, false, true, SimpleReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString2=staticString2,staticInt2=67890,staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
  +        assertEquals(
  +            this.toBaseString(instance1) + "[staticString2=staticString2,staticInt2=67890,staticString=staticString,staticInt=12345]",
  +            ReflectionToStringBuilder.toStringWithStatics(instance1, SimpleReflectionStaticFieldsFixture.class));
  +    }
  +
  +    /**
  +     * Tests ReflectionToStringBuilder.toString() for statics.
  +     */
  +    class ReflectionStaticFieldsFixture {
  +        static final String staticString = "staticString";
  +        static final int staticInt = 12345;
  +        static final transient String staticTransientString = "staticTransientString";
  +        static final transient int staticTransientInt = 54321;
  +        String instanceString = "instanceString";
  +        int instanceInt = 67890;
  +        transient String transientString = "transientString";
  +        transient int transientInt = 98765;
  +    }
  +
  +    /**
  +     * Test fixture for ReflectionToStringBuilder.toString() for statics.
  +     */
  +    class SimpleReflectionStaticFieldsFixture {
  +        static final String staticString = "staticString";
  +        static final int staticInt = 12345;
  +    }
  +
  +    /**
  +     * Test fixture for ReflectionToStringBuilder.toString() for statics.
  +     */
  +    class InheritedReflectionStaticFieldsFixture extends SimpleReflectionStaticFieldsFixture
{
  +        static final String staticString2 = "staticString2";
  +        static final int staticInt2 = 67890;
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message