This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch 1.0-RC
in repository https://gitbox.apache.org/repos/asf/sis.git

commit c56e2773938cb7ba49629627bc09072aa78f5bdb
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Thu Sep 12 20:40:47 2019 +0200

    Bug fix: MetadataCopier.copy(type, metadata) should accept a type which is 
a super-type of the interface implemented by the given metadata instance.
---
 .../java/org/apache/sis/internal/metadata/Resources.java  |  2 +-
 .../org/apache/sis/internal/metadata/Resources.properties |  2 +-
 .../apache/sis/internal/metadata/Resources_fr.properties  |  2 +-
 .../main/java/org/apache/sis/metadata/MetadataCopier.java |  2 +-
 .../java/org/apache/sis/metadata/MetadataCopierTest.java  | 15 +++++++++++++++
 .../org/apache/sis/metadata/MetadataStandardTest.java     |  4 +++-
 6 files changed, 22 insertions(+), 5 deletions(-)

diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
index f2badce..660a727 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.java
@@ -81,7 +81,7 @@ public final class Resources extends IndexedResourceBundle {
         public static final short ElementsOmitted_1 = 4;
 
         /**
-         * `{1}` is an implementation class. Specify the `{0}` interface 
instead.
+         * Illegal class `{1}`. Specify the `{0}` interface instead.
          */
         public static final short ExpectedInterface_2 = 5;
 
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
index 0e80c25..8ab6976 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources.properties
@@ -23,5 +23,5 @@ BoxCrossesAntiMeridian            = Bounding box crosses the 
antimeridian.
 ConnectionAlreadyInitialized_1    = Connection to \u201c{0}\u201d database is 
already initialized.
 ElementAlreadyInitialized_1       = This metadata element is already 
initialized with value \u201c{0}\u201d.
 ElementsOmitted_1                 = \u2026 {0} elements omitted \u2026
-ExpectedInterface_2               = `{1}` is an implementation class. Specify 
the `{0}` interface instead.
+ExpectedInterface_2               = Illegal class `{1}`. Specify the `{0}` 
interface instead.
 UnmodifiableMetadata              = This metadata is not modifiable.
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
index c8eefe5..8359aaa 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Resources_fr.properties
@@ -28,5 +28,5 @@ BoxCrossesAntiMeridian            = La bo\u00eete englobante 
traverse l\u2019ant
 ConnectionAlreadyInitialized_1    = La connexion \u00e0 la base de 
donn\u00e9es \u00ab\u202f{0}\u202f\u00bb est d\u00e9j\u00e0 initialis\u00e9e.
 ElementAlreadyInitialized_1       = Cet \u00e9l\u00e9ment de 
m\u00e9ta-donn\u00e9e est d\u00e9j\u00e0 initialis\u00e9 avec la valeur 
\u00ab\u202f{0}\u202f\u00bb.
 ElementsOmitted_1                 = \u2026 {0} \u00e9l\u00e9ments omis \u2026
-ExpectedInterface_2               = `{1}` est une classe 
d\u2019impl\u00e9mentation. Sp\u00e9cifiez l\u2019interface `{0}` \u00e0 la 
place.
+ExpectedInterface_2               = La classe `{1}` est ill\u00e9gale. 
Sp\u00e9cifiez l\u2019interface `{0}` \u00e0 la place.
 UnmodifiableMetadata              = Cette m\u00e9ta-donn\u00e9e n\u2019est pas 
modifiable.
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java
index a99df1a..1e34396 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataCopier.java
@@ -155,7 +155,7 @@ public class MetadataCopier extends MetadataVisitor<Object> 
{
         ArgumentChecks.ensureNonNull("type", type);
         if (metadata instanceof AbstractMetadata) {
             final Class<?> interfaceType = ((AbstractMetadata) 
metadata).getInterface();
-            if (type != interfaceType) {
+            if (!type.isAssignableFrom(interfaceType)) {
                 /*
                  * In case the user specified an implementation despite the 
documentation warning.
                  * We could replace `type` by `interfaceType` and it would 
work most of the time,
diff --git 
a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
 
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
index 7765a19..5c2634c 100644
--- 
a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
+++ 
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataCopierTest.java
@@ -17,8 +17,10 @@
 package org.apache.sis.metadata;
 
 import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.extent.GeographicExtent;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicDescription;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -70,6 +72,19 @@ public final strictfp class MetadataCopierTest extends 
TestCase {
     }
 
     /**
+     * Tests {@link MetadataCopier#copy(Class, Object)} when the given type is 
a parent
+     * of the interface implemented by the given argument.
+     */
+    @Test
+    public void testCopyWithSuperType() {
+        final MetadataCopier copier = new 
MetadataCopier(MetadataStandard.ISO_19115);
+        final DefaultGeographicDescription original = new 
DefaultGeographicDescription("Some area.");
+        final GeographicExtent copy = copier.copy(GeographicExtent.class, 
original);
+        assertNotSame(original, copy);
+        assertEquals (original, copy);
+    }
+
+    /**
      * Tests {@link MetadataCopier#copy(Class, Object)} with an implementation 
class specified instead of an interface.
      */
     @Test
diff --git 
a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
 
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
index ab16cf6..3adc5d6 100644
--- 
a/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
+++ 
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.HashSet;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.quality.Completeness;
+import org.opengis.metadata.extent.GeographicExtent;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
@@ -56,7 +57,7 @@ import static org.apache.sis.test.TestUtilities.getSingleton;
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */
@@ -131,6 +132,7 @@ public final strictfp class MetadataStandardTest extends 
TestCase {
         assertEquals("getInterface(Citation)",               Citation.class,   
      getInterface(Citation.class));
         assertEquals("getInterface(DefaultCitation)",        Citation.class,   
      getInterface(DefaultCitation.class));
         assertEquals("getInterface(AbstractCompleteness)",   
Completeness.class,     getInterface(AbstractCompleteness.class));
+        assertEquals("getInterface(GeographicExtent)",       
GeographicExtent.class, getInterface(GeographicExtent.class));
 
         standard = MetadataStandard.ISO_19111;
         assertEquals("getInterface(Citation)",               Citation.class,   
      getInterface(Citation.class));

Reply via email to