This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit a31026987c0c7cdf08bae87098cb745032c8947d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Nov 15 18:12:47 2022 +0100 Add a few tests for metadata quality package. --- .../iso/quality/DefaultQuantitativeResult.java | 14 ++++++ .../iso/quality/DefaultDomainConsistencyTest.java | 47 ++++++++++++++++++++ .../iso/quality/DefaultQuantitativeResultTest.java | 50 ++++++++++++++++++++++ .../apache/sis/test/suite/MetadataTestSuite.java | 2 + 4 files changed, 113 insertions(+) diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java index d92e2565c0..8e0d1a1b6f 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java @@ -253,4 +253,18 @@ public class DefaultQuantitativeResult extends AbstractResult implements Quantit checkWritePermission(errorStatistic); errorStatistic = newValue; } + + /** + * Returns {@code true} if this metadata contains only {@code null}, nil or empty properties. + * The deprecated {@code errorStatistic} is also verified because there is no non-deprecated + * replacement receiving a value that {@code super.isEmpty()} would recognize. + * + * @return {@code true} if this metadata is empty. + * + * @hidden + */ + @Override + public boolean isEmpty() { + return super.isEmpty() && errorStatistic == null; + } } diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java new file mode 100644 index 0000000000..0ad12c0936 --- /dev/null +++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java @@ -0,0 +1,47 @@ +/* + * 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.metadata.iso.quality; + +import java.util.Map; +import java.util.Collections; +import org.apache.sis.test.TestCase; +import org.junit.Test; + +import static org.junit.Assert.*; + + +/** + * Tests {@link DefaultDomainConsistency}. + * + * @author Martin Desruisseaux (Geomatys) + * @version 1.3 + * @since 1.3 + * @module + */ +public final strictfp class DefaultDomainConsistencyTest extends TestCase { + /** + * Tests {@link DefaultDomainConsistency#asMap()}. + */ + @Test + public void testAsMap() { + final DefaultDescriptiveResult r = new DefaultDescriptiveResult("A result"); + final DefaultDomainConsistency c = new DefaultDomainConsistency(); + final Map<String,Object> m = c.asMap(); + c.setResults(Collections.singleton(r)); + assertEquals(Collections.singletonList(r), m.get("result")); + } +} diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResultTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResultTest.java new file mode 100644 index 0000000000..ebd8da6df4 --- /dev/null +++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResultTest.java @@ -0,0 +1,50 @@ +/* + * 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.metadata.iso.quality; + +import org.apache.sis.util.SimpleInternationalString; +import org.apache.sis.test.TestCase; +import org.junit.Test; + +import static org.junit.Assert.*; + + +/** + * Tests {@link DefaultQuantitativeResult}. + * + * @author Martin Desruisseaux (Geomatys) + * @version 1.3 + * @since 1.3 + * @module + */ +public final strictfp class DefaultQuantitativeResultTest extends TestCase { + /** + * Tests {@link DefaultQuantitativeResult#isEmpty()}. The {@code isEmpty()} method needs a special check + * for the deprecated {@code "errorStatistic"} property because, contrarily to other deprecated properties, + * that one has no replacement. Consequently no non-deprecated property is set as a result of redirection. + * Because by default {@code isEmpty()} ignores deprecated properties, + * it can cause {@link DefaultQuantitativeResult} to be wrongly considered as empty. + */ + @Test + @SuppressWarnings("deprecation") + public void testIsEmpty() { + final DefaultQuantitativeResult r = new DefaultQuantitativeResult(); + assertTrue(r.isEmpty()); + r.setErrorStatistic(new SimpleInternationalString("a description")); + assertFalse(r.isEmpty()); + } +} diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java b/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java index a7f8adda19..f570c1bf7d 100644 --- a/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java +++ b/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java @@ -120,6 +120,8 @@ import org.junit.BeforeClass; org.apache.sis.metadata.iso.identification.DefaultServiceIdentificationTest.class, org.apache.sis.metadata.iso.quality.AbstractElementTest.class, org.apache.sis.metadata.iso.quality.AbstractPositionalAccuracyTest.class, + org.apache.sis.metadata.iso.quality.DefaultDomainConsistencyTest.class, + org.apache.sis.metadata.iso.quality.DefaultQuantitativeResultTest.class, org.apache.sis.metadata.iso.quality.ScopeCodeTest.class, org.apache.sis.metadata.iso.lineage.DefaultLineageTest.class, org.apache.sis.metadata.iso.lineage.DefaultProcessStepTest.class,