sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1455080 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/internal/converter/ test/java/org/apache/sis/internal/converter/ test/java/org/apache/sis/test/ test/java/org/apache/sis/test/suite/
Date Mon, 11 Mar 2013 10:18:07 GMT
Author: desruisseaux
Date: Mon Mar 11 10:18:07 2013
New Revision: 1455080

URL: http://svn.apache.org/r1455080
Log:
Ported some JUnit tests.

Added:
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
  (with props)
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
  (with props)
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
  (with props)
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java
  (with props)
Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java?rev=1455080&r1=1455079&r2=1455080&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FileConverter.java
[UTF-8] Mon Mar 11 10:18:07 2013
@@ -68,7 +68,7 @@ abstract class FileConverter<T> extends 
         }
 
         @Override public java.lang.String convert(final File source) {
-            return (source != null) ? source.getAbsolutePath() : null;
+            return (source != null) ? source.getPath() : null;
         }
 
         /** Returns the inverse, since this converter is "almost" bijective. */
@@ -84,6 +84,7 @@ abstract class FileConverter<T> extends 
 
     /**
      * Converter from {@link File} to {@link java.net.URI}.
+     * Note that this converter change relative paths to absolute paths.
      */
     @Immutable
     static final class URI extends FileConverter<java.net.URI> {

Added: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java?rev=1455080&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
(added)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
[UTF-8] Mon Mar 11 10:18:07 2013
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.converter;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.MalformedURLException;
+import org.apache.sis.util.ArraysExt;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.test.PlatformDependentTest;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assume.*;
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the various {@link FileConverter} implementations.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.01)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class FileConverterTest extends TestCase {
+    /**
+     * Assumes that the platform file system has a Unix-style root.
+     * Windows platform has driver letters instead, like "C:\\",
+     * which are not correctly tested by this class.
+     */
+    static void assumeUnixRoot() {
+        assumeTrue(ArraysExt.contains(File.listRoots(), new File("/")));
+    }
+
+    /**
+     * Tests conversions to string values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     */
+    @Test
+    public void testString() throws UnconvertibleObjectException {
+        final File   source = new File("home/user/index.txt");
+        final String target = "home/user/index.txt".replace("/", File.separator);
+        final ObjectConverter<File,String> c = FileConverter.String.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to URI values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws URISyntaxException Should never happen.
+     */
+    @Test
+    @PlatformDependentTest
+    public void testURI() throws UnconvertibleObjectException, URISyntaxException {
+        assumeUnixRoot();
+        final File source = new File("/home/user/index.txt");
+        final URI  target = new URI("file:/home/user/index.txt");
+        final ObjectConverter<File,URI> c = FileConverter.URI.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to URL values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws MalformedURLException Should never happen.
+     */
+    @Test
+    @PlatformDependentTest
+    public void testURL() throws UnconvertibleObjectException, MalformedURLException {
+        assumeUnixRoot();
+        final File source = new File("/home/user/index.txt");
+        final URL  target = new URL("file:/home/user/index.txt");
+        final ObjectConverter<File,URL> c = FileConverter.URL.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java?rev=1455080&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
(added)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
[UTF-8] Mon Mar 11 10:18:07 2013
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.converter;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.MalformedURLException;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.test.PlatformDependentTest;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the various {@link URIConverter} implementations.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.01)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class URIConverterTest extends TestCase {
+    /**
+     * Tests conversions to string values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws URISyntaxException Should never happen.
+     */
+    @Test
+    public void testString() throws UnconvertibleObjectException, URISyntaxException {
+        final URI    source = new URI("file:/home/user/index.txt");
+        final String target = "file:/home/user/index.txt";
+        final ObjectConverter<URI,String> c = URIConverter.String.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to URL values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws MalformedURLException Should never happen.
+     * @throws URISyntaxException Should never happen.
+     */
+    @Test
+    public void testURL() throws UnconvertibleObjectException, MalformedURLException, URISyntaxException
{
+        final URI source = new URI("file:/home/user/index.txt");
+        final URL target = new URL("file:/home/user/index.txt");
+        final ObjectConverter<URI,URL> c = URIConverter.URL.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to File values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws URISyntaxException Should never happen.
+     */
+    @Test
+    @PlatformDependentTest
+    public void testFile() throws UnconvertibleObjectException, URISyntaxException {
+        FileConverterTest.assumeUnixRoot();
+        final URI  source = new URI("file:/home/user/index.txt");
+        final File target = new File("/home/user/index.txt");
+        final ObjectConverter<URI,File> c = URIConverter.File.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java?rev=1455080&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
(added)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
[UTF-8] Mon Mar 11 10:18:07 2013
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.converter;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.MalformedURLException;
+import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.test.PlatformDependentTest;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the various {@link URLConverter} implementations.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.01)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class URLConverterTest extends TestCase {
+    /**
+     * Tests conversions to string values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws MalformedURLException Should never happen.
+     */
+    @Test
+    public void testString() throws UnconvertibleObjectException, MalformedURLException {
+        final URL    source = new URL("file:/home/user/index.txt");
+        final String target = "file:/home/user/index.txt";
+        final ObjectConverter<URL,String> c = URLConverter.String.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to URI values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws MalformedURLException Should never happen.
+     * @throws URISyntaxException Should never happen.
+     */
+    @Test
+    public void testURI() throws UnconvertibleObjectException, MalformedURLException, URISyntaxException
{
+        final URL source = new URL("file:/home/user/index.txt");
+        final URI target = new URI("file:/home/user/index.txt");
+        final ObjectConverter<URL,URI> c = URLConverter.URI.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+
+    /**
+     * Tests conversions to File values.
+     *
+     * @throws UnconvertibleObjectException Should never happen.
+     * @throws MalformedURLException Should never happen.
+     */
+    @Test
+    @PlatformDependentTest
+    public void testFile() throws UnconvertibleObjectException, MalformedURLException {
+        FileConverterTest.assumeUnixRoot();
+        final URL  source = new URL("file:/home/user/index.txt");
+        final File target = new File("/home/user/index.txt");
+        final ObjectConverter<URL,File> c = URLConverter.File.INSTANCE;
+        assertEquals("Forward conversion", target, c.convert(source));
+        assertEquals("Inverse conversion", source, c.inverse().convert(target));
+        assertSame(c, assertSerializedEquals(c));
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java?rev=1455080&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java
(added)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java
[UTF-8] Mon Mar 11 10:18:07 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.test;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+
+/**
+ * A marker annotation for platform-dependent tests. The platform-dependent part may
+ * be the Operating System, or whether some dependencies are present or not.
+ *
+ * <p>This annotation is used in order to remember which part of the SIS library
+ * (or its test suite) need to be revisited for better portability.</p>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.14)
+ * @version 0.3
+ * @module
+ */
+@Documented
+@Target(ElementType.METHOD)
+public @interface PlatformDependentTest {
+}

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/PlatformDependentTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1455080&r1=1455079&r2=1455080&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Mon Mar 11 10:18:07 2013
@@ -91,6 +91,9 @@ import org.junit.runners.Suite;
     org.apache.sis.util.collection.RangeSetTest.class,
 
     // Converters
+    org.apache.sis.internal.converter.URIConverterTest.class,
+    org.apache.sis.internal.converter.URLConverterTest.class,
+    org.apache.sis.internal.converter.FileConverterTest.class,
     org.apache.sis.internal.converter.FallbackConverterTest.class,
 
     // XML most basic types.



Mime
View raw message