cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1531963 - /cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/reflect/PropertyUtilsTest.java
Date Mon, 14 Oct 2013 16:13:45 GMT
Author: aadamchik
Date: Mon Oct 14 16:13:44 2013
New Revision: 1531963

URL: http://svn.apache.org/r1531963
Log:
CAY-1876 Sometimes PropertyUtilsTest failed

patch by Ilya Drabenia (I wrapped it in try/finally just in case)

Modified:
    cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/reflect/PropertyUtilsTest.java

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/reflect/PropertyUtilsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/reflect/PropertyUtilsTest.java?rev=1531963&r1=1531962&r2=1531963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/reflect/PropertyUtilsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/reflect/PropertyUtilsTest.java
Mon Oct 14 16:13:44 2013
@@ -206,32 +206,42 @@ public class PropertyUtilsTest extends T
     }
 
     public void testSetConvertedWithCustomConverter() {
-    	ConverterFactory.addConverter(Date.class, new Converter<Date>() {
-			@Override
-			protected Date convert(Object value, Class<Date> type) {
-				if (value == null) return null;
-				if (value instanceof Date) {
-					return (Date)value;
-				}
-				if (value instanceof String) {
-					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-					try {
-						return format.parse((String) value);
-					} catch (ParseException e) {
-						throw new CayenneRuntimeException("Unable to convert '" + value + "' to a Date", e);
-					}
-				}
-				throw new CayenneRuntimeException("Unable to convert '" + value + "' to a Date");
-			}
-    	});
-    	
-        TestJavaBean o1 = new TestJavaBean();
+        // save old converter for restore
+        Converter<Date> oldConverter = ConverterFactory.factory.getConverter(Date.class);
 
-        // String to date
-        PropertyUtils.setProperty(o1, "dateField", "2013-08-01");
-        
-        Calendar cal = new GregorianCalendar(2013, 7, 1, 0, 0, 0);
-        assertEquals(cal.getTime(), o1.getDateField());
+        try {
+            ConverterFactory.addConverter(Date.class, new Converter<Date>() {
+                @Override
+                protected Date convert(Object value, Class<Date> type) {
+                    if (value == null)
+                        return null;
+                    if (value instanceof Date) {
+                        return (Date) value;
+                    }
+                    if (value instanceof String) {
+                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+                        try {
+                            return format.parse((String) value);
+                        } catch (ParseException e) {
+                            throw new CayenneRuntimeException("Unable to convert '" + value
+ "' to a Date", e);
+                        }
+                    }
+                    throw new CayenneRuntimeException("Unable to convert '" + value + "'
to a Date");
+                }
+            });
+
+            TestJavaBean o1 = new TestJavaBean();
+
+            // String to date
+            PropertyUtils.setProperty(o1, "dateField", "2013-08-01");
+
+            Calendar cal = new GregorianCalendar(2013, 7, 1, 0, 0, 0);
+            assertEquals(cal.getTime(), o1.getDateField());
+        } finally {
+
+            // restore global date converter
+            ConverterFactory.addConverter(Date.class, oldConverter);
+        }
     }
     
     public void testSetNull() {



Mime
View raw message