felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1789968 - in /felix/trunk/converter/converter/src: main/java/org/apache/felix/converter/impl/AdapterImpl.java test/java/org/apache/felix/converter/impl/ConverterTest.java
Date Mon, 03 Apr 2017 11:36:56 GMT
Author: gnodet
Date: Mon Apr  3 11:36:56 2017
New Revision: 1789968

URL: http://svn.apache.org/viewvc?rev=1789968&view=rev
Log:
Re-enable the error handlers

Modified:
    felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java

Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java?rev=1789968&r1=1789967&r2=1789968&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
Mon Apr  3 11:36:56 2017
@@ -167,11 +167,11 @@ public class AdapterImpl implements Inte
                 return del.to(type);
             } catch (Exception ex) {
                 // TODO do custom error handling
-//                for (ConvertFunction<?> cf : converters) {
-//                    Object eh = cf.handleError(object, type);
-//                    if (eh != null)
-//                        return eh;
-//                }
+                for (ConvertFunction<?> cf : converters) {
+                    Object eh = cf.handleError(object, type);
+                    if (eh != null)
+                        return eh;
+                }
 
                 // No error handler, throw the original exception
                 throw ex;

Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java?rev=1789968&r1=1789967&r2=1789968&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
(original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
Mon Apr  3 11:36:56 2017
@@ -56,6 +56,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.util.converter.ConversionException;
+import org.osgi.util.converter.ConvertFunction;
 import org.osgi.util.converter.Converter;
 import org.osgi.util.converter.ConverterBuilder;
 import org.osgi.util.converter.Rule;
@@ -345,37 +346,37 @@ public class ConverterTest {
         assertArrayEquals(ia, adapted.convert("1,2").to(int[].class));
     }
 
-//    @Test
-//    public void testCustomErrorHandling() {
-//        ConvertFunction<Integer> func = new ConvertFunction<Integer>() {
-//            @Override
-//            public Integer convert(Object obj, Type targetType) throws Exception {
-//                return null;
-//            }
-//
-//            @Override
-//            public Integer handleError(Object obj, Type targetType) {
-//                if ("hello".equals(obj)) {
-//                    return -1;
-//                }
-//                return null;
-//            }
-//        };
-//
-//        ConverterBuilder cb = converter.newConverterBuilder();
-//        Converter adapted = cb.rule(Integer.class, func).build();
-//
-//        assertEquals(new Integer(12), adapted.convert("12").to(Integer.class));
-//        assertEquals(new Integer(-1), adapted.convert("hello").to(Integer.class));
-//
-//        // This is with the non-adapted converter
-//        try {
-//            converter.convert("hello").to(Integer.class);
-//            fail("Should have thrown a Conversion Exception when converting 'hello' to
a number");
-//        } catch (ConversionException ce) {
-//            // good
-//        }
-//    }
+    @Test
+    public void testCustomErrorHandling() {
+        ConvertFunction<Integer> func = new ConvertFunction<Integer>() {
+            @Override
+            public Integer convert(Object obj, Type targetType) throws Exception {
+                return null;
+            }
+
+            @Override
+            public Integer handleError(Object obj, Type targetType) {
+                if ("hello".equals(obj)) {
+                    return -1;
+                }
+                return null;
+            }
+        };
+
+        ConverterBuilder cb = converter.newConverterBuilder();
+        Converter adapted = cb.rule(Integer.class, func).build();
+
+        assertEquals(new Integer(12), adapted.convert("12").to(Integer.class));
+        assertEquals(new Integer(-1), adapted.convert("hello").to(Integer.class));
+
+        // This is with the non-adapted converter
+        try {
+            converter.convert("hello").to(Integer.class);
+            fail("Should have thrown a Conversion Exception when converting 'hello' to a
number");
+        } catch (ConversionException ce) {
+            // good
+        }
+    }
 
     @Test
     public void testUUIDConversion() {



Mime
View raw message