commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1298262 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
Date Thu, 08 Mar 2012 02:41:25 GMT
Author: sebb
Date: Thu Mar  8 02:41:24 2012
New Revision: 1298262

URL: http://svn.apache.org/viewvc?rev=1298262&view=rev
Log:
Fix test failures by clearing out the registry for tests that try
to show that the registry is left clean.

Modified:
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java?rev=1298262&r1=1298261&r2=1298262&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
Thu Mar  8 02:41:24 2012
@@ -170,7 +170,7 @@ public class ToStringBuilderTest {
 
     @Test
     public void testReflectionIntArray() {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         int[] array = new int[] { 1, 2, -3, 4 };
         String baseStr = this.toBaseString(array);
         assertEquals(baseStr + "[{1,2,-3,4}]", ToStringBuilder.reflectionToString(array));
@@ -181,7 +181,7 @@ public class ToStringBuilderTest {
 
     @Test
     public void testReflectionShortArray() {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         short[] array = new short[] { 1, 2, -3, 4 };
         String baseStr = this.toBaseString(array);
         assertEquals(baseStr + "[{1,2,-3,4}]", ToStringBuilder.reflectionToString(array));
@@ -202,7 +202,7 @@ public class ToStringBuilderTest {
 
     @Test
     public void testReflectionCharArray() {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         char[] array = new char[] { 'A', '2', '_', 'D' };
         String baseStr = this.toBaseString(array);
         assertEquals(baseStr + "[{A,2,_,D}]", ToStringBuilder.reflectionToString(array));
@@ -286,7 +286,7 @@ public class ToStringBuilderTest {
 
     @Test
     public void testReflectionByteArrayArray() {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         byte[][] array = new byte[][] { { 1, 2 }, null, { 5 } };
         String baseStr = this.toBaseString(array);
         assertEquals(baseStr + "[{{1,2},<null>,{5}}]", ToStringBuilder.reflectionToString(array));
@@ -297,7 +297,7 @@ public class ToStringBuilderTest {
 
     @Test
     public void testReflectionCharArrayArray() {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         char[][] array = new char[][] { { 'A', 'B' }, null, { 'p' } };
         String baseStr = this.toBaseString(array);
         assertEquals(baseStr + "[{{A,B},<null>,{p}}]", ToStringBuilder.reflectionToString(array));
@@ -552,7 +552,7 @@ public class ToStringBuilderTest {
      */
     @Test
     public void testSimpleReflectionObjectCycle() throws Exception {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         SimpleReflectionTestFixture simple = new SimpleReflectionTestFixture();
         simple.o = simple;
         assertEquals(this.toBaseString(simple) + "[o=" + this.toBaseString(simple) + "]",
simple.toString());
@@ -566,7 +566,7 @@ public class ToStringBuilderTest {
      */
     @Test
     public void testSelfInstanceVarReflectionObjectCycle() throws Exception {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         SelfInstanceVarReflectionTestFixture test = new SelfInstanceVarReflectionTestFixture();
         assertEquals(this.toBaseString(test) + "[typeIsSelf=" + this.toBaseString(test) +
"]", test.toString());
         this.validateNullToStringStyleRegistry();
@@ -593,7 +593,7 @@ public class ToStringBuilderTest {
      */
     @Test
     public void testReflectionObjectCycle() throws Exception {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         ReflectionTestCycleA a = new ReflectionTestCycleA();
         ReflectionTestCycleB b = new ReflectionTestCycleB();
         a.b = b;
@@ -633,6 +633,17 @@ public class ToStringBuilderTest {
         this.validateNullToStringStyleRegistry();
     }
 
+    private static final Object DUMMY = new Object();
+    void emptyToStringStyleRegistry() {
+        final Map<Object, Object> registry = ToStringStyle.getRegistry();
+        if (registry == null) {
+            return;
+        }
+        registry.clear(); // empty
+        ToStringStyle.register(DUMMY); // add key
+        ToStringStyle.unregister(DUMMY); // remove key and drop registry
+    }
+
     void validateNullToStringStyleRegistry() {
         final Map<Object, Object> registry = ToStringStyle.getRegistry();
         assertNull("Expected null, actual: "+registry, registry);
@@ -926,7 +937,7 @@ public class ToStringBuilderTest {
 
     @Test
     public void testObjectCycle() {
-        validateNullToStringStyleRegistry(); // Ensure registry starts out empty
+        emptyToStringStyleRegistry(); // Ensure registry starts out empty
         ObjectCycle a = new ObjectCycle();
         ObjectCycle b = new ObjectCycle();
         a.obj = b;



Mime
View raw message