ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doo...@apache.org
Subject svn commit: r910355 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java
Date Mon, 15 Feb 2010 22:24:27 GMT
Author: doogie
Date: Mon Feb 15 22:24:27 2010
New Revision: 910355

URL: http://svn.apache.org/viewvc?rev=910355&view=rev
Log:
Refactored the DateTime conversion tests.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java?rev=910355&r1=910354&r2=910355&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java Mon Feb
15 22:24:27 2010
@@ -21,6 +21,7 @@
 import org.ofbiz.base.conversion.Converter;
 import org.ofbiz.base.conversion.DateTimeConverters;
 import org.ofbiz.base.test.GenericTestCaseBase;
+import org.ofbiz.base.util.UtilGenerics;
 
 public class DateTimeTests extends GenericTestCaseBase {
 
@@ -28,46 +29,22 @@
         super(name);
     }
 
+    public static <S, T> void assertConversion(String label, Converter<S, T>
converter, S source, T target) throws Exception {
+        assertEquals(label, target, converter.convert(source));
+    }
+
     public void testDateTimeConverters() throws Exception {
         // Source class = java.util.Date
-        java.util.Date utilDate = new java.util.Date();
-        long dateMillis = utilDate.getTime();
-        Converter<java.util.Date, Long> dateToLong = new DateTimeConverters.DateToLong();
-        {
-            Long target = dateToLong.convert(utilDate);
-            assertEquals("DateToLong", dateMillis, target.longValue());
-        }
-        Converter<java.util.Date, java.sql.Date> dateToSqlDate = new DateTimeConverters.DateToSqlDate();
-        {
-            java.sql.Date target = dateToSqlDate.convert(utilDate);
-            assertEquals("DateToSqlDate", dateMillis, target.getTime());
-        }
-        Converter<java.util.Date, String> dateToString = new DateTimeConverters.DateToString();
-        {
-            String target = dateToString.convert(utilDate);
-            assertEquals("DateToString", utilDate.toString(), target);
-        }
-        Converter<java.util.Date, java.sql.Timestamp> dateToTimestamp = new DateTimeConverters.DateToTimestamp();
-        {
-            java.sql.Timestamp timestamp = dateToTimestamp.convert(utilDate);
-            assertEquals("DateToTimestamp", dateMillis, timestamp.getTime());
-        }
+        long currentTime = System.currentTimeMillis();
+        java.util.Date utilDate = new java.util.Date(currentTime);
+        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("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate,
new java.sql.Timestamp(currentTime));
         // Source class = java.sql.Date
-        java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
-        Converter<java.sql.Date, java.util.Date> sqlDateToDate = new DateTimeConverters.SqlDateToDate();
-        {
-            java.util.Date target = sqlDateToDate.convert(sqlDate);
-            assertEquals("SqlDateToDate", sqlDate.getTime(), target.getTime());
-        }
-        Converter<java.sql.Date, String> sqlDateToString = new DateTimeConverters.SqlDateToString();
-        {
-            String target = sqlDateToString.convert(sqlDate);
-            assertEquals("SqlDateToString", sqlDate.toString(), target);
-        }
-        Converter<java.sql.Date, java.sql.Timestamp> sqlDateToTimestamp = new DateTimeConverters.SqlDateToTimestamp();
-        {
-            java.sql.Timestamp target = sqlDateToTimestamp.convert(sqlDate);
-            assertEquals("SqlDateToTimestamp", sqlDate.getTime(), target.getTime());
-        }
+        java.sql.Date sqlDate = new java.sql.Date(currentTime);
+        assertConversion("SqlDateToDate", new DateTimeConverters.SqlDateToDate(), sqlDate,
utilDate);
+        assertConversion("SqlDateToString", new DateTimeConverters.SqlDateToString(), sqlDate,
sqlDate.toString());
+        assertConversion("SqlDateToTimestamp", new DateTimeConverters.SqlDateToTimestamp(),
sqlDate, new java.sql.Timestamp(currentTime));
     }
 }



Mime
View raw message