sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1457080 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/internal/converter/ test/java/org/apache/sis/internal/converter/
Date Fri, 15 Mar 2013 19:47:55 GMT
Author: desruisseaux
Date: Fri Mar 15 19:47:54 2013
New Revision: 1457080

URL: http://svn.apache.org/r1457080
Log:
Added a few missing test cases.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java?rev=1457080&r1=1457079&r2=1457080&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
[UTF-8] Fri Mar 15 19:47:54 2013
@@ -394,7 +394,11 @@ abstract class StringConverter<T> extend
 
         /** Converts the given string to the target type of this converter. */
         @Override T doConvert(String source) {
-            return Types.forCodeName(targetClass, source, true);
+            final T code = Types.forCodeName(targetClass, source, false);
+            if (code == null) {
+                throw new UnconvertibleObjectException(formatErrorMessage(source));
+            }
+            return code;
         }
 
         /** Invoked by the constructor for creating the inverse converter. */

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java?rev=1457080&r1=1457079&r2=1457080&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
[UTF-8] Fri Mar 15 19:47:54 2013
@@ -134,6 +134,6 @@ abstract class SystemConverter<S,T> exte
      * @return The error message.
      */
     final String formatErrorMessage(final S value) {
-        return Errors.format(Errors.Keys.CanNotConvertValue_2, value, getTargetClass());
+        return Errors.format(Errors.Keys.CanNotConvertValue_2, value, targetClass);
     }
 }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java?rev=1457080&r1=1457079&r2=1457080&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
[UTF-8] Fri Mar 15 19:47:54 2013
@@ -27,6 +27,7 @@ import java.net.MalformedURLException;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import org.opengis.util.InternationalString;
+import org.opengis.metadata.spatial.PixelOrientation;
 import org.apache.sis.math.FunctionProperty;
 import org.apache.sis.util.ObjectConverter;
 import org.apache.sis.util.UnconvertibleObjectException;
@@ -36,6 +37,10 @@ import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
 
+// Related to JDK7
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
 
 /**
  * Tests the various {@link StringConverter} implementations.
@@ -242,7 +247,19 @@ public final strictfp class StringConver
     @Test
     public void testFile() {
         final ObjectConverter<String,File> c = getInstance(File.class);
-        runInvertibleConversion(c, "home/user/index.txt", new File("home/user/index.txt"));
+        final String path = "home/user/index.txt".replace('/', File.separatorChar);
+        runInvertibleConversion(c, path, new File(path));
+        assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to {@link Path}.
+     */
+    @Test
+    public void testPath() {
+        final ObjectConverter<String,Path> c = getInstance(Path.class);
+        final String path = "home/user/index.txt".replace('/', File.separatorChar);
+        runInvertibleConversion(c, path, Paths.get(path));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }
 
@@ -269,4 +286,14 @@ public final strictfp class StringConver
         runInvertibleConversion(c, "file:/home/user/index.txt", new URL("file:/home/user/index.txt"));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }
+
+    /**
+     * Tests conversions to {@link org.opengis.util.CodeList}.
+     */
+    @Test
+    public void testCodeList() {
+        final ObjectConverter<String, PixelOrientation> c = new StringConverter.CodeList<>(PixelOrientation.class);
+        runInvertibleConversion(c, "LOWER_RIGHT", PixelOrientation.LOWER_RIGHT);
+        tryUnconvertibleValue(c);
+    }
 }



Mime
View raw message