Author: ebourg
Date: Wed Apr 18 16:46:34 2007
New Revision: 530205

URL: http://svn.apache.org/viewvc?view=rev&rev=530205
Log:
Changed TestDataConfiguration to make it compile and run on Java 1.3
Conversion to InternetAddress is no longer tested on Java 1.3

Modified:
    
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java

Modified: 
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java?view=diff&rev=530205&r1=530204&r2=530205
==============================================================================
--- 
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java
 (original)
+++ 
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java
 Wed Apr 18 16:46:34 2007
@@ -31,7 +31,8 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.NoSuchElementException;
-import javax.mail.internet.InternetAddress;
+
+import org.apache.commons.lang.SystemUtils;
 
 import junit.framework.TestCase;
 import junitx.framework.ArrayAssert;
@@ -297,10 +298,10 @@
         conf.addProperty("ip.string.interpolated", "${ip.string}");
         conf.addProperty("ip.object", InetAddress.getByName("127.0.0.1"));
 
-        // email address
+        // email address (tested on Java 1.4+)
         conf.addProperty("email.string", "[EMAIL PROTECTED]");
         conf.addProperty("email.string.interpolated", "${email.string}");
-        conf.addProperty("email.object", new InternetAddress("[EMAIL 
PROTECTED]"));
+        conf.addProperty("email.object", "[EMAIL PROTECTED]");
     }
 
     public void testGetConfiguration()
@@ -1692,21 +1693,27 @@
 
     public void testGetInternetAddress() throws Exception
     {
-        InternetAddress expected = new InternetAddress("[EMAIL PROTECTED]");
+        if (!SystemUtils.isJavaVersionAtLeast(1.4f))
+        {
+            // skip the test on Java 1.3
+            return;
+        }
+
+        Object expected = createInternetAddress("[EMAIL PROTECTED]");
 
         // address as string
-        assertEquals(expected, conf.get(InternetAddress.class, 
"email.string"));
+        assertEquals(expected, conf.get(expected.getClass(), "email.string"));
 
         // address object
-        assertEquals(expected, conf.get(InternetAddress.class, 
"email.object"));
+        assertEquals(expected, conf.get(expected.getClass(), "email.object"));
 
         // interpolated value
-        assertEquals(expected, conf.get(InternetAddress.class, 
"email.string.interpolated"));
+        assertEquals(expected, conf.get(expected.getClass(), 
"email.string.interpolated"));
 
         conf.setProperty("email.invalid", "[EMAIL PROTECTED]@org");
         try
         {
-            conf.get(InternetAddress.class, "email.invalid");
+            conf.get(expected.getClass(), "email.invalid");
             fail("ConversionException should be thrown for invalid emails");
         }
         catch (ConversionException e)
@@ -1715,7 +1722,18 @@
         }
     }
 
-    public void testConversionException()
+    /**
+     * Create an instance of InternetAddress. This trick is necessary to
+     * compile and run the test with Java 1.3 and the javamail-1.4 which
+     * is not compatible with Java 1.3
+     */
+    private Object createInternetAddress(String email) throws Exception
+    {
+        Class cls = Class.forName("javax.mail.internet.InternetAddress");
+        return cls.getConstructor(new Class[]{String.class}).newInstance(new 
Object[]{email});
+    }
+
+    public void testConversionException() throws Exception
     {
         conf.addProperty("key1", new Object());
         conf.addProperty("key2", "xxxxxx");
@@ -2330,14 +2348,18 @@
             // expected
         }
 
-        try
-        {
-            conf.get(InternetAddress.class, "key1");
-            fail("getInternetAddress didn't throw a ConversionException");
-        }
-        catch (ConversionException e)
+        if (SystemUtils.isJavaVersionAtLeast(1.4f))
         {
-            // expected
+            // skip the test on Java 1.3
+            try
+            {
+                conf.get(Class.forName("javax.mail.internet.InternetAddress"), 
"key1");
+                fail("getInternetAddress didn't throw a ConversionException");
+            }
+            catch (ConversionException e)
+            {
+                // expected
+            }
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to