commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r922775 - /commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestDateTimeConverters.java
Date Sun, 14 Mar 2010 06:35:35 GMT
Author: adrianc
Date: Sun Mar 14 06:35:34 2010
New Revision: 922775

URL: http://svn.apache.org/viewvc?rev=922775&view=rev
Log:
Improved Date/Time converter tests.

Modified:
    commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestDateTimeConverters.java

Modified: commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestDateTimeConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestDateTimeConverters.java?rev=922775&r1=922774&r2=922775&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestDateTimeConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestDateTimeConverters.java
Sun Mar 14 06:35:34 2010
@@ -34,25 +34,46 @@ public class TestDateTimeConverters exte
         assertEquals(label + " converted", target, converter.convert(source));
     }
 
+    public static <S, T> void assertStringConversion(String label, Converter<S,
T> converter, S source, java.util.Date target) throws Exception {
+        assertTrue(label + " can convert", converter.canConvert(source.getClass(), target.getClass()));
+        T result = converter.convert(source);
+        assertEquals(label + " converted", source, result.toString());
+    }
+
     public void testDateTimeConverters() throws Exception {
-        // Source class = java.util.Date
         long currentTime = System.currentTimeMillis();
         java.util.Date utilDate = new java.util.Date(currentTime);
+        java.sql.Date sqlDate = new java.sql.Date(currentTime);
+        java.sql.Time sqlTime = new java.sql.Time(currentTime);
+        java.sql.Timestamp timestamp = new java.sql.Timestamp(currentTime);
+        // Source class = java.util.Date
         assertConversion("DateToLong", new DateTimeConverters.DateToLong(), utilDate, currentTime);
         assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate,
new java.sql.Date(currentTime));
         assertConversion("DateToString", new DateTimeConverters.DateToString(), utilDate,
utilDate.toString());
-        //assertConversion("StringToDate", new DateTimeConverters.StringToDate(), utilDate.toString(),
utilDate);
         assertConversion("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate,
new java.sql.Timestamp(currentTime));
         // Source class = java.sql.Date
-        java.sql.Date sqlDate = new java.sql.Date(currentTime);
         assertConversion("SqlDateToDate", new DateTimeConverters.SqlDateToDate(), sqlDate,
utilDate);
+        assertConversion("SqlDateToLong", new DateTimeConverters.SqlDateToLong(), sqlDate,
currentTime);
         assertConversion("SqlDateToString", new DateTimeConverters.SqlDateToString(), sqlDate,
sqlDate.toString());
-        //assertConversion("StringToSqlDate", new DateTimeConverters.StringToSqlDate(), sqlDate.toString(),
sqlDate);
-        java.sql.Timestamp timestamp = new java.sql.Timestamp(currentTime);
         assertConversion("SqlDateToTimestamp", new DateTimeConverters.SqlDateToTimestamp(),
sqlDate, timestamp);
-        assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(),
timestamp.toString(), timestamp);
+        // Source class = java.sql.Time
+        // assertConversion("SqlTimeToDate", new DateTimeConverters.SqlTimeToSqlDate(), sqlTime,
sqlDate);
+        assertConversion("SqlTimeToLong", new DateTimeConverters.SqlTimeToLong(), sqlTime,
currentTime);
+        assertConversion("SqlTimeToString", new DateTimeConverters.SqlTimeToString(), sqlTime,
sqlTime.toString());
+        // Source class = java.sql.Timestamp
         assertConversion("TimestampToDate", new DateTimeConverters.TimestampToDate(), timestamp,
utilDate);
+        assertConversion("TimestampToLong", new DateTimeConverters.TimestampToLong(), timestamp,
currentTime);
         assertConversion("TimestampToSqlDate", new DateTimeConverters.TimestampToSqlDate(),
timestamp, sqlDate);
-        //assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(),
timestamp, timestamp.toString());
+        assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(),
timestamp, timestamp.toString());
+        // Source class = java.lang.String
+        assertStringConversion("StringToDate", new DateTimeConverters.StringToDate(), utilDate.toString(),
utilDate);
+        assertStringConversion("StringToSqlDate", new DateTimeConverters.StringToSqlDate(),
sqlDate.toString(), sqlDate);
+        assertStringConversion("StringToSqlTime", new DateTimeConverters.StringToSqlTime(),
sqlTime.toString(), sqlTime);
+        assertStringConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(),
timestamp.toString(), timestamp);
+        // Source class = java.lang.Long
+        assertConversion("LongToDate", new DateTimeConverters.LongToDate(), currentTime,
utilDate);
+        assertConversion("LongToSqlDate", new DateTimeConverters.LongToSqlDate(), currentTime,
sqlDate);
+        assertConversion("LongToSqlTime", new DateTimeConverters.LongToSqlTime(), currentTime,
sqlTime);
+        assertConversion("LongToTimestamp", new DateTimeConverters.LongToTimestamp(), currentTime,
timestamp);
     }
 }



Mime
View raw message