sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1488934 - in /sis/branches/JDK7: core/sis-utility/src/main/java/org/apache/sis/setup/ core/sis-utility/src/test/java/org/apache/sis/setup/ storage/sis-storage/src/test/java/org/apache/sis/storage/
Date Mon, 03 Jun 2013 09:17:52 GMT
Author: desruisseaux
Date: Mon Jun  3 09:17:51 2013
New Revision: 1488934

URL: http://svn.apache.org/r1488934
Log:
More tests.

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/setup/OptionKeyTest.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreConnectionTest.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java?rev=1488934&r1=1488933&r2=1488934&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java [UTF-8]
Mon Jun  3 09:17:51 2013
@@ -26,7 +26,7 @@ import org.apache.sis.util.logging.Loggi
 
 
 /**
- * Keys in a map of options. This class defines a set of static constants for commonly-used
options.
+ * Keys in a map of options, together with static constants for commonly-used options.
  * Developers can subclass this class for defining their own options.
  *
  * @param <T> The type of option values.

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/setup/OptionKeyTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/setup/OptionKeyTest.java?rev=1488934&r1=1488933&r2=1488934&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/setup/OptionKeyTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/setup/OptionKeyTest.java
[UTF-8] Mon Jun  3 09:17:51 2013
@@ -17,6 +17,7 @@
 package org.apache.sis.setup;
 
 import java.util.Map;
+import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -35,6 +36,20 @@ import static org.apache.sis.test.TestUt
  */
 public final strictfp class OptionKeyTest extends TestCase {
     /**
+     * A custom subclass of {@link OptionKey} for testing the ability to create custom option.
+     * This subclass implements {@link CheckedContainer} for ensuring that the {@code OptionKey}
+     * API is compatible with {@code CheckedContainer}. The public class does not implement
that
+     * interface because a key is not a container. However we keep this possibility open
in case
+     * some users find this approach convenient for their own keys.
+     */
+    @SuppressWarnings("serial")
+    private static final class CustomKey<T> extends OptionKey<T> implements CheckedContainer<T>
{
+        CustomKey(final String name, final Class<T> type) {
+            super(name, type);
+        }
+    }
+
+    /**
      * Tests the {@link OptionKey#getValueFrom(Map)} and {@link OptionKey#setValueInto(Map,
Object)}
      * methods with null arguments.
      */
@@ -68,4 +83,14 @@ public final strictfp class OptionKeyTes
         assertSame(URL_ENCODING, assertSerializedEquals(URL_ENCODING));
         assertSame(BYTE_BUFFER,  assertSerializedEquals(BYTE_BUFFER ));
     }
+
+    /**
+     * Tests the serialization of a custom subclass. {@link OptionKey} can not resolve
+     * to a unique instance, unless the subclass provides its own resolution mechanism.
+     */
+    @Test
+    public void testSubclassSerialization() {
+        final CustomKey<Integer> key = new CustomKey<>("key", Integer.class);
+        assertNotSame(key, assertSerializedEquals(key));
+    }
 }

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreConnectionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreConnectionTest.java?rev=1488934&r1=1488933&r2=1488934&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreConnectionTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/storage/DataStoreConnectionTest.java
[UTF-8] Mon Jun  3 09:17:51 2013
@@ -18,8 +18,10 @@ package org.apache.sis.storage;
 
 import java.io.DataInput;
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
 import org.apache.sis.internal.storage.ChannelImageInputStream;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -97,7 +99,7 @@ public final strictfp class DataStoreCon
     }
 
     /**
-     * Implementation of {@link #testOpenAsStream()}.
+     * Implementation of {@link #testOpenFromURL()} and {@link #testOpenFromStream()}.
      */
     private void testOpenAsDataInput(final boolean asStream) throws DataStoreException, IOException
{
         final DataStoreConnection connection = create(asStream);
@@ -106,12 +108,46 @@ public final strictfp class DataStoreCon
         assertInstanceOf("Needs the SIS implementation", ChannelImageInputStream.class, input);
         final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
         /*
-         * Reads a single integer for checking that the stream is at the right position,
-         * then close the stream.
+         * Reads a single integer for checking that the stream is at the right position,
then close the stream.
+         * Since the file is a compiled Java class, the integer that we read shall be the
Java magic number.
          */
         assertTrue("channel.isOpen()", channel.isOpen());
         assertEquals(MAGIC_NUMBER, input.readInt());
         connection.closeAllExcept(null);
         assertFalse("channel.isOpen()", channel.isOpen());
     }
+
+    /**
+     * Tests the {@link DataStoreConnection#openAs(Class)} method for the {@link ByteBuffer}
type.
+     * This method uses the same test file than {@link #testOpenFromURL()}.
+     *
+     * @throws DataStoreException Should never happen.
+     * @throws IOException If an error occurred while reading the test file.
+     */
+    @Test
+    @DependsOnMethod("testOpenFromURL")
+    public void testOpenAsByteBuffer() throws DataStoreException, IOException {
+        final DataStoreConnection connection = create(false);
+        final ByteBuffer buffer = connection.openAs(ByteBuffer.class);
+        assertEquals(MAGIC_NUMBER, buffer.getInt());
+        connection.closeAllExcept(null);
+    }
+
+    /**
+     * Tests the {@link DataStoreConnection#closeAllExcept(Object)} method.
+     *
+     * @throws DataStoreException Should never happen.
+     * @throws IOException If an error occurred while reading the test file.
+     */
+    @Test
+    @DependsOnMethod("testOpenFromStream")
+    public void testCloseAllExcept() throws DataStoreException, IOException {
+        final DataStoreConnection connection = create(true);
+        final DataInput input = connection.openAs(DataInput.class);
+        final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
+        assertTrue("channel.isOpen()", channel.isOpen());
+        connection.closeAllExcept(input);
+        assertTrue("channel.isOpen()", channel.isOpen());
+        channel.close();
+    }
 }



Mime
View raw message