commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1523794 - in /commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration: ConfigurationAssert.java TestAbstractConfigurationBasicFeatures.java TestPropertiesConfiguration.java TestXMLConfiguration.java
Date Mon, 16 Sep 2013 20:23:19 GMT
Author: oheger
Date: Mon Sep 16 20:23:19 2013
New Revision: 1523794

URL: http://svn.apache.org/r1523794
Log:
Added a helper method for testing equals() to ConfigurationAssert.

The already existing assertEquals() method was renamed because there was a
name clash with static imports.

Modified:
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/ConfigurationAssert.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/ConfigurationAssert.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/ConfigurationAssert.java?rev=1523794&r1=1523793&r2=1523794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/ConfigurationAssert.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/ConfigurationAssert.java
Mon Sep 16 20:23:19 2013
@@ -17,13 +17,14 @@
 
 package org.apache.commons.configuration;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Iterator;
 
-import junit.framework.Assert;
-
 /**
  * Assertions on configurations for the unit tests. This class also provides
  * access to test files.
@@ -51,21 +52,21 @@ public class ConfigurationAssert
      * @param expected the expected properties
      * @param actual the configuration to check
      */
-    public static void assertEquals(Configuration expected, Configuration actual)
+    public static void assertConfigurationEquals(Configuration expected, Configuration actual)
     {
         // check that the actual configuration contains all the properties of the expected
configuration
         for (Iterator<String> it = expected.getKeys(); it.hasNext();)
         {
             String key = it.next();
-            Assert.assertTrue("The actual configuration doesn't contain the expected key
'" + key + "'", actual.containsKey(key));
-            Assert.assertEquals("Value of the '" + key + "' property", expected.getProperty(key),
actual.getProperty(key));
+            assertTrue("The actual configuration doesn't contain the expected key '" + key
+ "'", actual.containsKey(key));
+            assertEquals("Value of the '" + key + "' property", expected.getProperty(key),
actual.getProperty(key));
         }
 
         // check that the actual configuration has no extra properties
         for (Iterator<String> it = actual.getKeys(); it.hasNext();)
         {
             String key = it.next();
-            Assert.assertTrue("The actual configuration contains an extra key '" + key +
"'", expected.containsKey(key));
+            assertTrue("The actual configuration contains an extra key '" + key + "'", expected.containsKey(key));
         }
     }
 
@@ -116,6 +117,27 @@ public class ConfigurationAssert
     }
 
     /**
+     * Helper method for testing the equals() implementation of a class. It is
+     * also checked, whether hashCode() is compatible with equals().
+     *
+     * @param o1 test object 1
+     * @param o2 test object 2
+     * @param expEquals the expected result of equals()
+     */
+    public static void checkEquals(Object o1, Object o2, boolean expEquals)
+    {
+        assertEquals("Wrong result of equals()", expEquals, o1.equals(o2));
+        if (o2 != null)
+        {
+            assertEquals("Not symmetric", expEquals, o2.equals(o1));
+        }
+        if (expEquals)
+        {
+            assertEquals("Different hash codes", o1.hashCode(), o2.hashCode());
+        }
+    }
+
+    /**
      * Helper method for converting a file to a URL.
      *
      * @param file the file

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java?rev=1523794&r1=1523793&r2=1523794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
Mon Sep 16 20:23:19 2013
@@ -215,7 +215,7 @@ public class TestAbstractConfigurationBa
     {
         AbstractConfiguration config = setUpDestConfig();
         config.copy(null);
-        ConfigurationAssert.assertEquals(setUpDestConfig(), config);
+        ConfigurationAssert.assertConfigurationEquals(setUpDestConfig(), config);
     }
 
     /**
@@ -297,7 +297,7 @@ public class TestAbstractConfigurationBa
     {
         AbstractConfiguration config = setUpDestConfig();
         config.append(null);
-        ConfigurationAssert.assertEquals(setUpDestConfig(), config);
+        ConfigurationAssert.assertConfigurationEquals(setUpDestConfig(), config);
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=1523794&r1=1523793&r2=1523794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
Mon Sep 16 20:23:19 2013
@@ -315,7 +315,7 @@ public class TestPropertiesConfiguration
         PropertiesConfiguration checkConfig = new PropertiesConfiguration();
         checkConfig.setListDelimiterHandler(new DisabledListDelimiterHandler());
         new FileHandler(checkConfig).load(testSavePropertiesFile);
-        ConfigurationAssert.assertEquals(conf, checkConfig);
+        ConfigurationAssert.assertConfigurationEquals(conf, checkConfig);
     }
 
     /**
@@ -331,7 +331,7 @@ public class TestPropertiesConfiguration
         PropertiesConfiguration checkConfig = new PropertiesConfiguration();
         checkConfig.setListDelimiterHandler(conf.getListDelimiterHandler());
         new FileHandler(checkConfig).load(testSavePropertiesFile);
-        ConfigurationAssert.assertEquals(conf, checkConfig);
+        ConfigurationAssert.assertConfigurationEquals(conf, checkConfig);
     }
 
     @Test(expected = ConfigurationException.class)
@@ -426,7 +426,7 @@ public class TestPropertiesConfiguration
         PropertiesConfiguration checkConfig = new PropertiesConfiguration();
         checkConfig.setListDelimiterHandler(new LegacyListDelimiterHandler(','));
         load(checkConfig, testSavePropertiesFile.getAbsolutePath());
-        ConfigurationAssert.assertEquals(conf, checkConfig);
+        ConfigurationAssert.assertConfigurationEquals(conf, checkConfig);
         return checkConfig;
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1523794&r1=1523793&r2=1523794&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
Mon Sep 16 20:23:19 2013
@@ -1211,7 +1211,7 @@ public class TestXMLConfiguration
         XMLConfiguration checkConf = new XMLConfiguration();
         checkConf.setListDelimiterHandler(conf.getListDelimiterHandler());
         load(checkConf, testSaveConf.getAbsolutePath());
-        ConfigurationAssert.assertEquals(conf, checkConf);
+        ConfigurationAssert.assertConfigurationEquals(conf, checkConf);
     }
 
     /**
@@ -1328,7 +1328,7 @@ public class TestXMLConfiguration
         checkConfig.registerEntityId(publicId, dtdURL);
         checkConfig.setValidating(true);
         load(checkConfig, testSaveConf.getAbsolutePath());
-        ConfigurationAssert.assertEquals(conf, checkConfig);
+        ConfigurationAssert.assertConfigurationEquals(conf, checkConfig);
     }
 
     /**
@@ -1700,7 +1700,7 @@ public class TestXMLConfiguration
             throws ConfigurationException
     {
         XMLConfiguration config = createFromFile(saveFile.getAbsolutePath());
-        ConfigurationAssert.assertEquals(conf, config);
+        ConfigurationAssert.assertConfigurationEquals(conf, config);
         return config;
     }
 



Mime
View raw message