You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2023/12/27 21:12:01 UTC
(sis) branch geoapi-4.0 updated (4c772ccb11 -> f35825c1dd)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
from 4c772ccb11 Move `DatumShiftGridLoader.toAbsolutePath(URI)` to `DataDirectory`.
new 95cdd7553d Add a `MarshalContext.getDocumentURI()` method.
new 9beb499ee7 When parsing a GML or WKT from a URI, store the URI on a new `DefaultParameterValue.sourceFile` property. This information allows to resolve `ParameterValue.valueFile` relatively to the source document.
new 7e3f59dffe Partial migration of some tests to JUnit 5 and addition of a test for the `WKTFormat.setSourceFile(URI)` method added in previous commit.
new f35825c1dd Move 4 PMC members to emeritus. Three of them were already ASF emeritus, one of them has his status changed directly on LDAP.
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/sis/console/CommandRunnerTest.java | 15 +-
.../apache/sis/coverage/grid/GridExtentTest.java | 23 +-
.../main/org/apache/sis/xml/MarshalContext.java | 15 +-
.../main/org/apache/sis/xml/Pooled.java | 2 +-
.../main/org/apache/sis/xml/ReferenceResolver.java | 2 +-
.../main/org/apache/sis/xml/bind/Context.java | 9 +
.../apache/sis/xml/util/ExternalLinkHandler.java | 61 +--
.../test/org/apache/sis/xml/XLinkTest.java | 25 +-
.../main/org/apache/sis/io/wkt/AbstractParser.java | 23 +-
.../apache/sis/io/wkt/GeodeticObjectParser.java | 11 +-
.../org/apache/sis/io/wkt/MathTransformParser.java | 20 +-
.../main/org/apache/sis/io/wkt/Parser.java | 4 +-
.../main/org/apache/sis/io/wkt/WKTFormat.java | 129 ++++---
.../sis/parameter/AbstractParameterDescriptor.java | 13 +-
.../sis/parameter/DefaultParameterDescriptor.java | 15 +-
.../parameter/DefaultParameterDescriptorGroup.java | 15 +-
.../sis/parameter/DefaultParameterValue.java | 171 +++++++--
.../sis/parameter/UnmodifiableParameterValue.java | 10 +
.../org/apache/sis/parameter/package-info.java | 2 +-
.../main/org/apache/sis/referencing/CRS.java | 7 +-
.../referencing/factory/GeodeticObjectFactory.java | 8 +-
.../transform/DefaultMathTransformFactory.java | 8 +-
.../test/org/apache/sis/io/wkt/ColorsTest.java | 14 +-
.../org/apache/sis/io/wkt/ComparisonWithEPSG.java | 6 +-
.../test/org/apache/sis/io/wkt/ConventionTest.java | 2 +-
.../test/org/apache/sis/io/wkt/ElementTest.java | 144 +++----
.../sis/io/wkt/GeodeticObjectParserTest.java | 336 ++++++++---------
.../apache/sis/io/wkt/MathTransformParserTest.java | 20 +-
.../test/org/apache/sis/io/wkt/SymbolsTest.java | 39 +-
.../org/apache/sis/io/wkt/TransliteratorTest.java | 20 +-
.../org/apache/sis/io/wkt/WKTDictionaryTest.java | 109 +++---
.../test/org/apache/sis/io/wkt/WKTFormatTest.java | 60 ++-
.../test/org/apache/sis/io/wkt/WKTParserTest.java | 78 ++--
.../sis/parameter/DefaultParameterValueTest.java | 414 +++++++++------------
.../transform/MathTransformFactoryMock.java | 31 ++
.../operation/transform/PoleRotationTest.java | 2 +-
.../org/apache/sis/storage/base/PRJDataStore.java | 21 +-
.../sis/io/stream/ChannelDataOutputTest.java | 20 +-
.../org/apache/sis/storage/FeatureQueryTest.java | 5 +-
.../apache/sis/storage/StorageConnectorTest.java | 49 ++-
.../org/apache/sis/measure/UnitFormatTest.java | 36 +-
.../test/org/apache/sis/test/Assertions.java | 84 +++--
.../org/apache/sis/util/ArgumentChecksTest.java | 44 +--
parent/pom.xml | 9 +-
44 files changed, 1132 insertions(+), 999 deletions(-)
(sis) 02/04: When parsing a GML or WKT from a URI, store the URI on a new `DefaultParameterValue.sourceFile` property. This information allows to resolve `ParameterValue.valueFile` relatively to the source document.
Posted by de...@apache.org.
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 9beb499ee7bfed73abfcde27e63b4db74a4f62a1
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 27 16:17:41 2023 +0100
When parsing a GML or WKT from a URI, store the URI on a new `DefaultParameterValue.sourceFile` property.
This information allows to resolve `ParameterValue.valueFile` relatively to the source document.
https://issues.apache.org/jira/browse/SIS-593
---
.../apache/sis/xml/util/ExternalLinkHandler.java | 3 +-
.../main/org/apache/sis/io/wkt/AbstractParser.java | 23 ++-
.../apache/sis/io/wkt/GeodeticObjectParser.java | 11 +-
.../org/apache/sis/io/wkt/MathTransformParser.java | 20 ++-
.../main/org/apache/sis/io/wkt/Parser.java | 4 +-
.../main/org/apache/sis/io/wkt/WKTFormat.java | 129 ++++++++++------
.../sis/parameter/AbstractParameterDescriptor.java | 13 +-
.../sis/parameter/DefaultParameterDescriptor.java | 15 +-
.../parameter/DefaultParameterDescriptorGroup.java | 15 +-
.../sis/parameter/DefaultParameterValue.java | 171 ++++++++++++++++-----
.../sis/parameter/UnmodifiableParameterValue.java | 10 ++
.../org/apache/sis/parameter/package-info.java | 2 +-
.../main/org/apache/sis/referencing/CRS.java | 7 +-
.../referencing/factory/GeodeticObjectFactory.java | 8 +-
.../transform/DefaultMathTransformFactory.java | 8 +-
.../test/org/apache/sis/io/wkt/ElementTest.java | 4 +-
.../sis/io/wkt/GeodeticObjectParserTest.java | 4 +-
.../org/apache/sis/storage/base/PRJDataStore.java | 21 ++-
18 files changed, 315 insertions(+), 153 deletions(-)
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java
index 6bd949f064..6bb7082bc7 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java
@@ -132,7 +132,7 @@ public class ExternalLinkHandler {
if (b == null) {
return null;
}
- final URI baseURI;
+ URI baseURI;
if (b instanceof URI) { // `instanceof` check of final classes are efficient.
baseURI = (URI) b;
} else {
@@ -151,6 +151,7 @@ public class ExternalLinkHandler {
warningOccured(b, e);
return null;
}
+ baseURI = baseURI.normalize();
base = baseURI;
}
return baseURI;
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/AbstractParser.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/AbstractParser.java
index 439d33516c..03b137c7b2 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/AbstractParser.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/AbstractParser.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.io.wkt;
+import java.net.URI;
import java.util.Map;
import java.util.List;
import java.util.Date;
@@ -35,11 +36,10 @@ import org.opengis.util.FactoryException;
import org.opengis.util.InternationalString;
import org.apache.sis.system.Loggers;
import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.internal.StandardDateFormat;
import org.apache.sis.measure.Units;
import org.apache.sis.measure.UnitFormat;
-import org.apache.sis.util.resources.Errors;
-import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
/**
@@ -83,6 +83,13 @@ abstract class AbstractParser implements Parser {
*/
static final int MANDATORY = 2;
+ /**
+ * The URI to declare as the source of the WKT definitions, or {@code null} if unknown.
+ * This information is not used directly by the parser, but will be stored in parameter values
+ * as a hint for resolving relative paths as absolute paths.
+ */
+ final URI sourceFile;
+
/**
* The locale for formatting error messages if parsing fails, or {@code null} for system default.
* This is <strong>not</strong> the locale for parsing number or date values.
@@ -151,22 +158,24 @@ abstract class AbstractParser implements Parser {
/**
* Constructs a parser using the specified set of symbols.
*
- * @param symbols the set of symbols to use.
+ * @param sourceFile URI to declare as the source of the WKT definitions, or {@code null} if unknown.
* @param fragments reference to the {@link WKTFormat#fragments} map, or an empty map if none.
+ * @param symbols the set of symbols to use. Cannot be null.
* @param numberFormat the number format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param dateFormat the date format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param unitFormat the unit format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param errorLocale the locale for error messages (not for parsing), or {@code null} for the system default.
*/
- AbstractParser(final Symbols symbols, final Map<String,StoredTree> fragments, NumberFormat numberFormat,
- final DateFormat dateFormat, final UnitFormat unitFormat, final Locale errorLocale)
+ AbstractParser(final URI sourceFile, final Map<String,StoredTree> fragments, final Symbols symbols,
+ NumberFormat numberFormat, final DateFormat dateFormat, final UnitFormat unitFormat,
+ final Locale errorLocale)
{
- ensureNonNull("symbols", symbols);
if (numberFormat == null) {
numberFormat = symbols.createNumberFormat();
}
- this.symbols = symbols;
+ this.sourceFile = sourceFile;
this.fragments = fragments;
+ this.symbols = symbols;
this.dateFormat = dateFormat;
this.unitFormat = unitFormat;
this.errorLocale = errorLocale;
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
index 1610727a53..be411c60d7 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.io.wkt;
+import java.net.URI;
import java.util.Map;
import java.util.List;
import java.util.Locale;
@@ -94,6 +95,7 @@ import org.apache.sis.util.iso.Types;
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Johann Sorel (Geomatys)
*/
+@SuppressWarnings("LocalVariableHidesMemberVariable") // We hide with the same value made final.
class GeodeticObjectParser extends MathTransformParser implements Comparator<CoordinateSystemAxis> {
/*
* Force class initialization of `AxisDirections` in order to have
@@ -182,7 +184,7 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
public GeodeticObjectParser(final Map<String,?> defaultProperties,
final ObjectFactory factories, final MathTransformFactory mtFactory)
{
- super(Symbols.getDefault(), Collections.emptyMap(), null, null, null,
+ super(null, Collections.emptyMap(), Symbols.getDefault(), null, null, null,
new ReferencingFactoryContainer(defaultProperties,
(CRSFactory) factories,
(CSFactory) factories,
@@ -198,8 +200,9 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
* Constructs a parser for the specified set of symbols using the specified set of factories.
* This constructor is for {@link WKTFormat} usage only.
*
- * @param symbols the set of symbols to use.
+ * @param sourceFile URI to declare as the source of the WKT definitions, or {@code null} if unknown.
* @param fragments reference to the {@link WKTFormat#fragments} map, or an empty map if none.
+ * @param symbols the set of symbols to use. Cannot be null.
* @param numberFormat the number format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param dateFormat the date format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param unitFormat the unit format provided by {@link WKTFormat}, or {@code null} for a default format.
@@ -207,12 +210,12 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo
* @param errorLocale the locale for error messages (not for parsing), or {@code null} for the system default.
* @param factories on input, the factories to use. On output, the factories used. Can be null.
*/
- GeodeticObjectParser(final Symbols symbols, final Map<String,StoredTree> fragments,
+ GeodeticObjectParser(final URI sourceFile, final Map<String,StoredTree> fragments, final Symbols symbols,
final NumberFormat numberFormat, final DateFormat dateFormat, final UnitFormat unitFormat,
final Convention convention, final Transliterator transliterator, final Locale errorLocale,
final ReferencingFactoryContainer factories)
{
- super(symbols, fragments, numberFormat, dateFormat, unitFormat, factories, errorLocale);
+ super(sourceFile, fragments, symbols, numberFormat, dateFormat, unitFormat, factories, errorLocale);
this.transliterator = transliterator;
usesCommonUnits = convention.usesCommonUnits;
ignoreAxes = convention == Convention.WKT1_IGNORE_AXES;
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/MathTransformParser.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/MathTransformParser.java
index 1afebc6c84..af4f45d5d5 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/MathTransformParser.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/MathTransformParser.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.io.wkt;
+import java.net.URI;
import java.util.Map;
import java.util.Arrays;
import java.util.Locale;
@@ -40,13 +41,13 @@ import org.opengis.referencing.operation.OperationMethod;
import org.apache.sis.referencing.util.CoordinateOperations;
import org.apache.sis.referencing.util.ReferencingFactoryContainer;
import org.apache.sis.referencing.util.WKTKeywords;
+import org.apache.sis.parameter.DefaultParameterValue;
import org.apache.sis.util.Numbers;
+import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.internal.Constants;
import org.apache.sis.math.DecimalFunctions;
import org.apache.sis.measure.UnitFormat;
import org.apache.sis.measure.Units;
-import org.apache.sis.util.resources.Errors;
-import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
/**
@@ -134,28 +135,28 @@ class MathTransformParser extends AbstractParser {
* @param mtFactory the factory to use for creating {@link MathTransform} objects.
*/
public MathTransformParser(final MathTransformFactory mtFactory) {
- this(Symbols.getDefault(), Map.of(), null, null, null,
+ this(null, Map.of(), Symbols.getDefault(), null, null, null,
new ReferencingFactoryContainer(null, null, null, null, null, mtFactory), null);
}
/**
* Creates a parser using the specified set of symbols and factories.
*
- * @param symbols the set of symbols to use.
+ * @param sourceFile URI to declare as the source of the WKT definitions, or {@code null} if unknown.
* @param fragments reference to the {@link WKTFormat#fragments} map, or an empty map if none.
+ * @param symbols the set of symbols to use. Cannot be null.
* @param numberFormat the number format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param dateFormat the date format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param unitFormat the unit format provided by {@link WKTFormat}, or {@code null} for a default format.
* @param factories the factories to use for creating math transforms and geodetic objects.
* @param errorLocale the locale for error messages (not for parsing), or {@code null} for the system default.
*/
- MathTransformParser(final Symbols symbols, final Map<String,StoredTree> fragments,
+ MathTransformParser(final URI sourceFile, final Map<String,StoredTree> fragments, final Symbols symbols,
final NumberFormat numberFormat, final DateFormat dateFormat, final UnitFormat unitFormat,
final ReferencingFactoryContainer factories, final Locale errorLocale)
{
- super(symbols, fragments, numberFormat, dateFormat, unitFormat, errorLocale);
+ super(sourceFile, fragments, symbols, numberFormat, dateFormat, unitFormat, errorLocale);
this.factories = factories;
- ensureNonNull("factories", factories);
}
/**
@@ -347,7 +348,7 @@ class MathTransformParser extends AbstractParser {
final Unit<?> defaultSI = (defaultUnit != null) ? defaultUnit.getSystemUnit() : null;
Element param = element;
try {
- while ((param = element.pullElement(OPTIONAL, WKTKeywords.Parameter)) != null) {
+ while ((param = element.pullElement(OPTIONAL, WKTKeywords.Parameter, WKTKeywords.ParameterFile)) != null) {
final String name = param.pullString("name");
Unit<?> unit = parseUnit(param);
param.pullElement(OPTIONAL, ID_KEYWORDS);
@@ -386,6 +387,9 @@ class MathTransformParser extends AbstractParser {
} else {
parameter.setValue(param.pullString("stringValue"));
}
+ if (sourceFile != null && parameter instanceof DefaultParameterValue<?>) {
+ ((DefaultParameterValue<?>) parameter).setSourceFile(sourceFile);
+ }
param.close(ignoredElements);
}
} catch (ParameterNotFoundException e) {
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Parser.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Parser.java
index eee7b89b1c..1076ef12cc 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Parser.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/Parser.java
@@ -60,9 +60,9 @@ public interface Parser {
* For processing warnings in a different way than logging them, one can use
* {@link WKTFormat#parseObject(String)} followed by a call to {@link WKTFormat#getWarnings()}.
*
- * @param text object encoded in Well-Known Text format (version 1 or 2).
+ * @param wkt object encoded in Well-Known Text format (version 1 or 2).
* @return the result of parsing the given text.
* @throws FactoryException if the object creation failed.
*/
- Object createFromWKT(String text) throws FactoryException;
+ Object createFromWKT(String wkt) throws FactoryException;
}
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java
index cc7047cc0f..8fcc5b6679 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTFormat.java
@@ -25,10 +25,12 @@ import java.util.HashMap;
import java.util.TreeMap;
import java.util.List;
import java.util.ArrayList;
+import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
import java.util.function.Function;
+import java.net.URI;
import java.io.IOException;
import java.text.Format;
import java.text.NumberFormat;
@@ -119,7 +121,7 @@ import org.opengis.metadata.Identifier;
*
* @author Martin Desruisseaux (Geomatys)
* @author Rémi Eve (IRD)
- * @version 1.4
+ * @version 1.5
*
* @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html">WKT 2 specification</a>
* @see <a href="http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html">Legacy WKT 1</a>
@@ -236,6 +238,15 @@ public class WKTFormat extends CompoundFormat<Object> {
*/
private TreeMap<String,StoredTree> fragments;
+ /**
+ * The URI to declare as the source of the WKT definitions, or {@code null} if unknown.
+ * This information is not used directly by the parser, but will be stored in parameter values
+ * as a hint for resolving relative paths as absolute paths.
+ *
+ * @see #getSourceFile()
+ */
+ private URI sourceFile;
+
/**
* {@code true} if the {@link #fragments} map is shared by two or more {@code WKTFormat} instances.
* In such case, the map shall not be modified; instead it must be copied before any modification.
@@ -386,12 +397,11 @@ public class WKTFormat extends CompoundFormat<Object> {
/**
* Sets the symbols used for parsing and formatting WKT.
*
- * @param symbols the new set of symbols to use for parsing and formatting WKT.
+ * @param style the new set of symbols to use for parsing and formatting WKT.
*/
- public void setSymbols(final Symbols symbols) {
- ArgumentChecks.ensureNonNull("symbols", symbols);
- if (!symbols.equals(this.symbols)) {
- this.symbols = symbols.immutable();
+ public void setSymbols(final Symbols style) {
+ if (!style.equals(symbols)) { // Intentional NullPointerException.
+ symbols = style.immutable();
formatter = null;
parser = null;
}
@@ -428,13 +438,13 @@ public class WKTFormat extends CompoundFormat<Object> {
* then the default mapper is {@link Transliterator#DEFAULT} except for WKT formatted according
* the {@linkplain Convention#INTERNAL internal convention}.</p>
*
- * @param transliterator the new mapper to use, or {@code null} for restoring the default value.
+ * @param map the new mapper to use, or {@code null} for restoring the default value.
*
* @since 0.6
*/
- public void setTransliterator(final Transliterator transliterator) {
- if (this.transliterator != transliterator) {
- this.transliterator = transliterator;
+ public void setTransliterator(final Transliterator map) {
+ if (transliterator != map) {
+ transliterator = map;
updateFormatter(formatter);
parser = null;
}
@@ -452,11 +462,10 @@ public class WKTFormat extends CompoundFormat<Object> {
/**
* Sets whether WKT keywords should be written with upper cases or camel cases.
*
- * @param keywordCase the case to use for formatting keywords.
+ * @param style the case to use for formatting keywords.
*/
- public void setKeywordCase(final KeywordCase keywordCase) {
- ArgumentChecks.ensureNonNull("keywordCase", keywordCase);
- this.keywordCase = keywordCase;
+ public void setKeywordCase(final KeywordCase style) {
+ keywordCase = Objects.requireNonNull(style);
updateFormatter(formatter);
}
@@ -474,13 +483,12 @@ public class WKTFormat extends CompoundFormat<Object> {
/**
* Sets whether to use short or long WKT keywords.
*
- * @param keywordStyle the style to use for formatting keywords.
+ * @param style the style to use for formatting keywords.
*
* @since 0.6
*/
- public void setKeywordStyle(final KeywordStyle keywordStyle) {
- ArgumentChecks.ensureNonNull("keywordStyle", keywordStyle);
- this.keywordStyle = keywordStyle;
+ public void setKeywordStyle(final KeywordStyle style) {
+ keywordStyle = Objects.requireNonNull(style);
updateFormatter(formatter);
}
@@ -505,13 +513,13 @@ public class WKTFormat extends CompoundFormat<Object> {
* method tries to highlight most of the elements that are relevant to
* {@link org.apache.sis.util.Utilities#equalsIgnoreMetadata(Object, Object)}.</p>
*
- * @param colors the colors for syntax coloring, or {@code null} if none.
+ * @param emphasis the colors for syntax coloring, or {@code null} if none.
*/
- public void setColors(Colors colors) {
- if (colors != null) {
- colors = colors.immutable();
+ public void setColors(Colors emphasis) {
+ if (emphasis != null) {
+ emphasis = emphasis.immutable();
}
- this.colors = colors;
+ colors = emphasis;
updateFormatter(formatter);
}
@@ -528,12 +536,11 @@ public class WKTFormat extends CompoundFormat<Object> {
/**
* Sets the convention for parsing and formatting WKT elements.
*
- * @param convention the new convention to use for parsing and formatting WKT elements.
+ * @param variant the new convention to use for parsing and formatting WKT elements.
*/
- public void setConvention(final Convention convention) {
- ArgumentChecks.ensureNonNull("convention", convention);
- if (this.convention != convention) {
- this.convention = convention;
+ public void setConvention(final Convention variant) {
+ if (convention != variant) {
+ convention = Objects.requireNonNull(variant);
updateFormatter(formatter);
parser = null;
}
@@ -625,13 +632,13 @@ public class WKTFormat extends CompoundFormat<Object> {
* Sets a new indentation to be used for formatting objects.
* The {@value #SINGLE_LINE} value means that the whole WKT is to be formatted on a single line.
*
- * @param indentation the new indentation to use.
+ * @param numSpaces the new indentation to use in number of spaces.
*
* @see org.apache.sis.setup.OptionKey#INDENTATION
*/
- public void setIndentation(final int indentation) {
- ArgumentChecks.ensureBetween("indentation", SINGLE_LINE, Byte.MAX_VALUE, indentation);
- this.indentation = (byte) indentation;
+ public void setIndentation(final int numSpaces) {
+ ArgumentChecks.ensureBetween("indentation", SINGLE_LINE, Byte.MAX_VALUE, numSpaces);
+ indentation = (byte) numSpaces;
updateFormatter(formatter);
}
@@ -658,7 +665,7 @@ public class WKTFormat extends CompoundFormat<Object> {
* @since 1.0
*/
public void setMaximumListElements(final int limit) {
- ArgumentChecks.ensureStrictlyPositive("limit", limit);
+ ArgumentChecks.ensureStrictlyPositive("listSizeLimit", limit);
listSizeLimit = limit;
updateFormatter(formatter);
}
@@ -668,7 +675,7 @@ public class WKTFormat extends CompoundFormat<Object> {
* explicit {@code ID[…]} or {@code AUTHORITY[…]} element. The main use case is for implementing
* a {@link org.opengis.referencing.crs.CRSAuthorityFactory} backed by definitions in WKT format.
*
- * <p>Note that this identifier apply to all objects to be created, which is generally not desirable.
+ * <p>Note that this identifier applies to all objects to be created, which is generally not desirable.
* Callers should invoke {@code setDefaultIdentifier(null)} in a {@code finally} block.</p>
*
* <p>This is not a publicly committed API. If we want to make this functionality public in a future
@@ -747,9 +754,47 @@ public class WKTFormat extends CompoundFormat<Object> {
}
}
+ /**
+ * Returns the URI to declare as the source of the WKT definitions. This value is not used directly by the parser,
+ * but stored as a hint for allowing users to interpret the {@code PARAMETERFILE[…]} value as a file relative to
+ * the file containing the WKT. The default value is {@code null}.
+ *
+ * @return the URI to declare as the source of the WKT definitions, or {@code null} if none.
+ *
+ * @see #setSourceFile(URI)
+ * @see org.apache.sis.parameter.DefaultParameterValue#getSourceFile()
+ * @see org.apache.sis.xml.MarshalContext#getDocumentURI()
+ * @see URI#resolve(URI)
+ *
+ * @since 1.5
+ */
+ public URI getSourceFile() {
+ return sourceFile;
+ }
+
+ /**
+ * Sets the URI to declare as the source of the WKT definitions. This information will be stored in
+ * {@link org.apache.sis.parameter.DefaultParameterValue#getSourceFile()} at WKT parsing time as a
+ * hint for resolving relative paths as absolute paths. This value has no effect at formatting time.
+ *
+ * @param document URI to the file that contains the WKT definitions to parse, or {@code null} if none.
+ *
+ * @see #getSourceFile()
+ * @see org.apache.sis.parameter.DefaultParameterValue#setSourceFile(URI)
+ * @see URI#resolve(URI)
+ *
+ * @since 1.5
+ */
+ public void setSourceFile(final URI document) {
+ if (!Objects.equals(sourceFile, document)) {
+ sourceFile = document;
+ parser = null;
+ }
+ }
+
/**
* Returns the type of objects formatted by this class. This method has to return {@code Object.class}
- * since it is the only common parent to all object types accepted by this formatter.
+ * because it is the only common parent to all object types accepted by this formatter.
*
* @return {@code Object.class}
*/
@@ -947,14 +992,12 @@ public class WKTFormat extends CompoundFormat<Object> {
* @param modifiable whether the caller intents to modify the {@link #fragments} map.
*/
private AbstractParser parser(final boolean modifiable) {
- @SuppressWarnings("LocalVariableHidesMemberVariable")
- AbstractParser parser = this.parser;
/*
* `parser` is always null on a fresh clone. However, the `fragments`
* map may need to be cloned if the caller intents to modify it.
*/
if (parser == null || (isCloned & modifiable)) {
- this.parser = parser = new Parser(symbols, fragments(modifiable),
+ parser = new Parser(sourceFile, fragments(modifiable), symbols,
(NumberFormat) getFormat(Number.class),
(DateFormat) getFormat(Date.class),
(UnitFormat) getFormat(Unit.class),
@@ -973,12 +1016,12 @@ public class WKTFormat extends CompoundFormat<Object> {
*/
private final class Parser extends GeodeticObjectParser implements Function<Object,Object> {
/** Creates a new parser. */
- Parser(final Symbols symbols, final Map<String,StoredTree> fragments,
- final NumberFormat numberFormat, final DateFormat dateFormat, final UnitFormat unitFormat,
- final Convention convention, final Transliterator transliterator, final Locale errorLocale,
- final ReferencingFactoryContainer factories)
+ Parser(final URI sourceFile, final Map<String,StoredTree> fragments, final Symbols symbols,
+ final NumberFormat numberFormat, final DateFormat dateFormat, final UnitFormat unitFormat,
+ final Convention convention, final Transliterator transliterator, final Locale errorLocale,
+ final ReferencingFactoryContainer factories)
{
- super(symbols, fragments, numberFormat, dateFormat, unitFormat, convention, transliterator, errorLocale, factories);
+ super(sourceFile, fragments, symbols, numberFormat, dateFormat, unitFormat, convention, transliterator, errorLocale, factories);
}
/** Returns the source class and method to declare in log records. */
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/AbstractParameterDescriptor.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/AbstractParameterDescriptor.java
index 8d8a015c42..9f89555788 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/AbstractParameterDescriptor.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/AbstractParameterDescriptor.java
@@ -52,8 +52,7 @@ import static org.apache.sis.util.Utilities.deepEquals;
* <th class="sep">WPS</th>
* <th class="sep">ISO 19115</th>
* <th class="sep">Remarks</th>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@link #getName() getName()}</td>
* <td class="sep">{@code name}</td>
* <td class="sep">{@code Identifier}</td>
@@ -67,22 +66,19 @@ import static org.apache.sis.util.Utilities.deepEquals;
* <td class="sep">{@code Abstract}</td>
* <td class="sep">{@code description}</td>
* <td class="sep">Also known as “definition”.</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@link #getDirection()}</td>
* <td class="sep"></td>
* <td class="sep"></td>
* <td class="sep">{@code direction}</td>
* <td class="sep">Tells if the parameter is a WPS {@code Input} or {@code Output} structure.</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@link #getMinimumOccurs()}</td>
* <td class="sep">{@code minimumOccurs}</td>
* <td class="sep">{@code MinOccurs}</td>
* <td class="sep">{@code optionality}</td>
* <td class="sep">{@code optionality = (minimumOccurs > 0)}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@link #getMaximumOccurs()}</td>
* <td class="sep">{@code maximumOccurs}</td>
* <td class="sep">{@code MaxOccurs}</td>
@@ -171,6 +167,7 @@ public abstract class AbstractParameterDescriptor extends AbstractIdentifiedObje
* @param maximumOccurs the {@linkplain #getMaximumOccurs() maximum number of times} that values
* for this parameter group are required, or {@link Integer#MAX_VALUE} if no restriction.
*/
+ @SuppressWarnings("this-escape")
protected AbstractParameterDescriptor(final Map<String,?> properties,
final int minimumOccurs, final int maximumOccurs)
{
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptor.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptor.java
index c0d020d969..17ae032cbb 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptor.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptor.java
@@ -137,28 +137,23 @@ public class DefaultParameterDescriptor<T> extends AbstractParameterDescriptor i
* <th>Property name</th>
* <th>Value type</th>
* <th>Returned by</th>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#NAME_KEY}</td>
* <td>{@link org.opengis.metadata.Identifier} or {@link String}</td>
* <td>{@link #getName()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#ALIAS_KEY}</td>
* <td>{@link org.opengis.util.GenericName} or {@link CharSequence} (optionally as array)</td>
* <td>{@link #getAlias()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#IDENTIFIERS_KEY}</td>
* <td>{@link org.opengis.metadata.Identifier} (optionally as array)</td>
* <td>{@link #getIdentifiers()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.metadata.Identifier#DESCRIPTION_KEY}</td>
* <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
* <td>{@link #getDescription()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY}</td>
* <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
* <td>{@link #getRemarks()}</td>
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
index aa17f0fcdf..472656654e 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
@@ -122,28 +122,23 @@ public class DefaultParameterDescriptorGroup extends AbstractParameterDescriptor
* <th>Property name</th>
* <th>Value type</th>
* <th>Returned by</th>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#NAME_KEY}</td>
* <td>{@link org.opengis.metadata.Identifier} or {@link String}</td>
* <td>{@link #getName()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#ALIAS_KEY}</td>
* <td>{@link org.opengis.util.GenericName} or {@link CharSequence} (optionally as array)</td>
* <td>{@link #getAlias()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#IDENTIFIERS_KEY}</td>
* <td>{@link org.opengis.metadata.Identifier} (optionally as array)</td>
* <td>{@link #getIdentifiers()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.metadata.Identifier#DESCRIPTION_KEY}</td>
* <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
* <td>{@link #getDescription()}</td>
- * </tr>
- * <tr>
+ * </tr><tr>
* <td>{@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY}</td>
* <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
* <td>{@link #getRemarks()}</td>
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterValue.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterValue.java
index d9817c7107..7cdc01b585 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterValue.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/DefaultParameterValue.java
@@ -18,6 +18,7 @@ package org.apache.sis.parameter;
import java.lang.reflect.Array;
import java.util.Objects;
+import java.util.Optional;
import java.util.logging.Logger;
import java.io.Serializable;
import java.io.File;
@@ -41,37 +42,38 @@ import org.apache.sis.io.wkt.FormattableObject;
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.xml.bind.Context;
import org.apache.sis.xml.bind.gml.Measure;
import org.apache.sis.xml.bind.gml.MeasureList;
+import org.apache.sis.xml.util.ExternalLinkHandler;
+import org.apache.sis.metadata.internal.ImplementationHelper;
import org.apache.sis.referencing.internal.Resources;
import org.apache.sis.referencing.util.WKTUtilities;
import org.apache.sis.referencing.util.WKTKeywords;
-import org.apache.sis.metadata.internal.ImplementationHelper;
-import org.apache.sis.util.Numbers;
+import org.apache.sis.math.DecimalFunctions;
+import org.apache.sis.system.Loggers;
+import org.apache.sis.util.Utilities;
+import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.LenientComparable;
import org.apache.sis.util.ObjectConverters;
import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.util.Numbers;
import org.apache.sis.util.internal.Numerics;
-import org.apache.sis.system.Loggers;
-import org.apache.sis.math.DecimalFunctions;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.logging.Logging;
-import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.util.Utilities.deepEquals;
/**
- * A single parameter value used by an operation method. {@code ParameterValue} instances are elements in
- * a {@linkplain DefaultParameterValueGroup parameter value group}, in a way similar to {@code Map.Entry}
- * instances in a {@code java.util.Map}.
- *
- * <p>In the context of coordinate operations, most parameter values are numeric and can be obtained by the
+ * A single parameter value used by an operation method. Each {@code ParameterValue} is a
+ * (<var>key</var>, <var>value</var>) pair, and an arbitrary number of those pairs can be
+ * stored in a a {@linkplain DefaultParameterValueGroup parameter value group}.
+ * In the context of coordinate operations, parameter values are often numeric and can be obtained by the
* {@link #intValue()} or {@link #doubleValue()} methods. But other types of parameter values are possible
* and can be handled by the more generic {@link #getValue()} and {@link #setValue(Object)} methods.
* All {@code xxxValue()} methods in this class are convenience methods converting the value from {@code Object}
* to some commonly used types. Those types are specified in ISO 19111 as an union of attributes, listed below with
- * the corresponding getter and setter methods:</p>
+ * the corresponding getter and setter methods:
*
* <table class="sis">
* <caption>Mapping from ISO attributes to getters and setters</caption>
@@ -96,28 +98,44 @@ import static org.apache.sis.util.Utilities.deepEquals;
* Class<T> valueClass = parameter.getDescriptor().getValueClass();
* }
*
+ * <h2>Absolute paths of value files</h2>
+ * Parameters that are too complex for being expressed as an {@code int[]}, {@code double[]} or {@code String} type
+ * may be encoded in auxiliary files. It is the case, for example, of gridded data such as datum shift grids.
+ * The name of an auxiliary file is given by {@link #valueFile()}, but often as a <em>relative</em> path.
+ * The directory where that file is located depends on the operation using the parameter.
+ * For example, datum shift grids used by coordinate transformations are searched in the
+ * {@code $SIS_DATA/DatumChanges} directory, where {@code $SIS_DATA} is the value of the environment variable.
+ * However, the latest approach requires that all potentially used auxiliary files are preexisting on the local machine.
+ * This assumption may be applicable for parameters coming from a well-known registry such as EPSG, but cannot work
+ * with arbitrary operations where the auxiliary files need to be transferred together with the parameter values.
+ * For the latter case, an alternative is to consider the auxiliary files as relative to the GML document or WKT file
+ * that provides the parameter values. For allowing users to resolve or download auxiliary files in that way,
+ * a {@link #getSourceFile()} method is provided. Operations can then use {@link URI#resolve(URI)} for getting the
+ * absolute path of an auxiliary file from the same server or directory than the GML or WKT file of parameter values.
+ *
* <h2>Instantiation</h2>
* A {@linkplain DefaultParameterDescriptor parameter descriptor} must be defined before parameter value can be created.
- * Descriptors are usually predefined by map projection or process providers. Given a descriptor, a parameter value can
- * be created by a call to the {@link #DefaultParameterValue(ParameterDescriptor)} constructor or by a call to the
- * {@link ParameterDescriptor#createValue()} method. The latter is recommended since it allows descriptors to return
- * specialized implementations.
+ * Descriptors are usually predefined (often hard-coded) by map projection or process providers. Given a descriptor,
+ * the preferred way to create a parameter value is to invoke the {@link ParameterDescriptor#createValue()} method.
+ * It is also possible to invoke the {@linkplain #DefaultParameterValue(ParameterDescriptor) constructor} directly,
+ * but the former is recommended because it allows descriptors to return specialized implementations.
*
* <h2>Implementation note for subclasses</h2>
- * All read and write operations (except constructors, {@link #equals(Object)} and {@link #hashCode()})
+ * All read and write operations except constructors, {@link #equals(Object)} and {@link #hashCode()},
* ultimately delegates to the following methods:
*
* <ul>
- * <li>All getter methods will invoke {@link #getValue()} and {@link #getUnit()} (if needed),
+ * <li>The source file property is accessed by {@link #getSourceFile()} and {@link #setSourceFile(URI)}.</li>
+ * <li>All other getter methods will invoke {@link #getValue()} and {@link #getUnit()} (if needed),
* then perform their processing on the values returned by those methods.</li>
- * <li>All setter methods delegate to the {@link #setValue(Object, Unit)} method.</li>
+ * <li>All other setter methods delegate to the {@link #setValue(Object, Unit)} method.</li>
* </ul>
*
* Consequently, the above-cited methods provide single points that subclasses can override
* for modifying the behavior of all getter and setter methods.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.4
+ * @version 1.5
*
* @param <T> the type of the value stored in this parameter.
*
@@ -175,6 +193,17 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
@SuppressWarnings("serial") // Most SIS implementations are serializable.
protected Unit<?> unit;
+ /**
+ * If the parameter value is a relative path, the base URI to use for resolving that path.
+ * This field is {@code null} by default, unless this parameter value has been read from a
+ * GML document or a WKT file, in which case this field contains the URI of that document.
+ * This information allows to interpret {@link #valueFile()} as relative to the GML or WKT file.
+ *
+ * @see #getSourceFile()
+ * @see URI#resolve(URI)
+ */
+ private URI sourceFile;
+
/**
* Creates a parameter value from the specified descriptor.
* The value will be initialized to the default value, if any.
@@ -182,7 +211,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
* @param descriptor the abstract definition of this parameter.
*/
public DefaultParameterValue(final ParameterDescriptor<T> descriptor) {
- ensureNonNull("descriptor", descriptor);
+ ArgumentChecks.ensureNonNull("descriptor", descriptor);
this.descriptor = descriptor;
this.value = descriptor.getDefaultValue();
this.unit = descriptor.getUnit();
@@ -190,8 +219,8 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
/**
* Creates a new instance initialized with the values from the specified parameter object.
- * This is a <em>shallow</em> copy constructor, since the value contained in the given
- * object is not cloned.
+ * This is a <em>shallow</em> copy constructor, since the {@linkplain #getValue() value}
+ * contained in the given object is not cloned.
*
* @param parameter the parameter to copy values from.
*
@@ -199,16 +228,17 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
* @see #unmodifiable(ParameterValue)
*/
public DefaultParameterValue(final ParameterValue<T> parameter) {
- ensureNonNull("parameter", parameter);
+ ArgumentChecks.ensureNonNull("parameter", parameter);
descriptor = parameter.getDescriptor();
value = parameter.getValue();
unit = parameter.getUnit();
+ if (parameter instanceof DefaultParameterValue<?>) {
+ sourceFile = ((DefaultParameterValue<?>) parameter).getSourceFile().orElse(null);
+ }
}
/**
- * Returns the definition of this parameter.
- *
- * @return the definition of this parameter.
+ * {@return the definition of this parameter}.
*/
@Override
@XmlElement(name = "operationParameter", required = true)
@@ -216,6 +246,28 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
return descriptor;
}
+ /**
+ * {@return the URI of the GML document or WKT file from which this parameter value has been read}.
+ * This information allows to interpret {@link #valueFile()} as a path relative to the file that defined
+ * this parameter value. For example, the following snippet gets the file, then tries to make it absolute:
+ *
+ * {@snippet lang="java" :
+ * DefaultParameterValue<?> pv = ...;
+ * URI file = pv.valueFile();
+ * file = pv.getSourceFile().map((base) -> base.resolve(file)).orElse(file);
+ * }
+ *
+ * @see #setSourceFile(URI)
+ * @see org.apache.sis.io.wkt.WKTFormat#getSourceFile()
+ * @see org.apache.sis.xml.MarshalContext#getDocumentURI()
+ * @see URI#resolve(URI)
+ *
+ * @since 1.5
+ */
+ public Optional<URI> getSourceFile() {
+ return Optional.ofNullable(sourceFile);
+ }
+
/**
* Returns the unit of measure of the parameter value.
* If the parameter value has no unit (for example because it is a {@link String} type),
@@ -272,6 +324,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public boolean booleanValue() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof Boolean) {
return (Boolean) value;
@@ -296,6 +349,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public int intValue() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof Number) {
final int integer = ((Number) value).intValue();
@@ -323,6 +377,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public int[] intValueList() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof int[]) {
return ((int[]) value).clone();
@@ -349,6 +404,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public double doubleValue() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof Number) {
return ((Number) value).doubleValue();
@@ -374,6 +430,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public double[] doubleValueList() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof double[]) {
return ((double[]) value).clone();
@@ -384,20 +441,20 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
/**
* Returns the converter to be used by {@link #doubleValue(Unit)} and {@link #doubleValueList(Unit)}.
*/
- private UnitConverter getConverterTo(final Unit<?> unit) {
+ private UnitConverter getConverterTo(final Unit<?> target) {
final Unit<?> source = getUnit();
if (source == null) {
throw new IllegalStateException(Resources.format(Resources.Keys.UnitlessParameter_1, Verifier.getDisplayName(descriptor)));
}
- ensureNonNull("unit", unit);
+ ArgumentChecks.ensureNonNull("unit", target);
final short expectedID = Verifier.getUnitMessageID(source);
- if (Verifier.getUnitMessageID(unit) != expectedID) {
- throw new IllegalArgumentException(Errors.format(expectedID, unit));
+ if (Verifier.getUnitMessageID(target) != expectedID) {
+ throw new IllegalArgumentException(Errors.format(expectedID, target));
}
try {
- return source.getConverterToAny(unit);
+ return source.getConverterToAny(target);
} catch (IncommensurableException e) {
- throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2, source, unit), e);
+ throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2, source, target), e);
}
}
@@ -422,6 +479,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public double doubleValue(final Unit<?> unit) throws IllegalArgumentException, IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final double value = doubleValue(); // Invoke first in case it throws an exception.
return getConverterTo(unit).convert(value);
}
@@ -469,6 +527,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public String stringValue() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof CharSequence) {
return value.toString();
@@ -481,6 +540,12 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
* The default implementation can convert the following value types:
* {@link URI}, {@link URL}, {@link Path}, {@link File}.
*
+ * <h4>Relative paths to absolute paths</h4>
+ * This parameter value is often a path relative to an unspecified directory. The base directory
+ * depends on the context. For example, it may be a directory where all datum grids are cached.
+ * Sometime, it is convenient to interpret the path as relative to the GML document or WKT file
+ * that defined this parameter value. For such resolution, see {@link #getSourceFile()}.
+ *
* @return the reference to a file containing parameter values.
* @throws InvalidParameterTypeException if the value is not a reference to a file or a URI.
* @throws IllegalStateException if the value is not defined and there is no default value.
@@ -490,6 +555,7 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
*/
@Override
public URI valueFile() throws IllegalStateException {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final T value = getValue();
if (value instanceof URI) return (URI) value;
if (value instanceof File) return ((File) value).toURI();
@@ -528,6 +594,23 @@ public class DefaultParameterValue<T> extends FormattableObject implements Param
return isFile(newValue);
}
+ /**
+ * Sets the URI of the GML document or WKT file from which this parameter value has been read.
+ * The given URI is a hint to be returned by {@link #getSourceFile()} for allowing callers to
+ * {@linkplain URI#resolve(URI) resolve} relative {@linkplain #valueFile() value files}.
+ *
+ * @param document URI of the document from which this parameter value has been read, or {@code null} if none.
+ *
+ * @see #getSourceFile()
+ * @see org.apache.sis.io.wkt.WKTFormat#setSourceFile(URI)
+ * @see URI#resolve(URI)
+ *
+ * @see 1.5
+ */
+ public void setSourceFile(final URI document) {
+ sourceFile = document;
+ }
+
/**
* Returns the exception to throw when an incompatible method is invoked for the value type.
*/
@@ -723,8 +806,8 @@ convert: if (componentType != null) {
setValue(n, unit);
/*
* Above code used `unit` instead of `getUnit()` despite class Javadoc claim because units are not expected
- * to be involved in this method. We access this field only as a matter of principle, for making sure that no
- * property other than the value is altered by this method call.
+ * to be involved in this method. We access this field only as a matter of principle, for making sure that
+ * no property other than the value is altered by this method call.
*/
}
@@ -841,15 +924,16 @@ convert: if (componentType != null) {
if (mode == ComparisonMode.STRICT) {
if (getClass() == object.getClass()) {
final DefaultParameterValue<?> that = (DefaultParameterValue<?>) object;
- return Objects.equals(descriptor, that.descriptor) &&
- Objects.deepEquals(value, that.value) &&
- Objects.equals(unit, that.unit);
+ return Objects.equals (descriptor, that.descriptor) &&
+ Objects.deepEquals(sourceFile, that.sourceFile) &&
+ Objects.deepEquals(value, that.value) &&
+ Objects.equals (unit, that.unit);
}
} else if (object instanceof ParameterValue<?>) {
final ParameterValue<?> that = (ParameterValue<?>) object;
- return deepEquals(getDescriptor(), that.getDescriptor(), mode) &&
- deepEquals(getValue(), that.getValue(), mode) &&
- deepEquals(getUnit(), that.getUnit(), mode);
+ return Utilities.deepEquals(getDescriptor(), that.getDescriptor(), mode) &&
+ Utilities.deepEquals(getValue(), that.getValue(), mode) &&
+ Utilities.deepEquals(getUnit(), that.getUnit(), mode);
}
}
return false;
@@ -1162,6 +1246,7 @@ convert: if (componentType != null) {
@XmlElement(name = "valueList", type = MeasureList.class)
})
private Object getXmlValue() {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
final Object value = getValue(); // Give to user a chance to override.
if (value != null) {
if (value instanceof Number) {
@@ -1196,6 +1281,10 @@ convert: if (componentType != null) {
*/
@SuppressWarnings("unchecked")
private void setXmlValue(Object xmlValue) {
+ ExternalLinkHandler linkHandler = Context.linkHandler(Context.current());
+ if (linkHandler != null) {
+ sourceFile = linkHandler.getURI();
+ }
if (value == null && unit == null) {
if (xmlValue instanceof Measure) {
final Measure measure = (Measure) xmlValue;
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/UnmodifiableParameterValue.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/UnmodifiableParameterValue.java
index 8939067bee..fb22b0c6eb 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/UnmodifiableParameterValue.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/UnmodifiableParameterValue.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.parameter;
+import java.net.URI;
import jakarta.xml.bind.annotation.XmlTransient;
import javax.measure.Unit;
import org.opengis.parameter.ParameterValue;
@@ -92,6 +93,7 @@ final class UnmodifiableParameterValue<T> extends DefaultParameterValue<T> {
*/
@Override
public T getValue() {
+ @SuppressWarnings("LocalVariableHidesMemberVariable")
T value = super.getValue();
if (value instanceof Cloneable) {
final Class<T> type = getDescriptor().getValueClass(); // May be null after GML unmarshalling.
@@ -112,6 +114,14 @@ final class UnmodifiableParameterValue<T> extends DefaultParameterValue<T> {
throw new UnsupportedOperationException(Errors.format(Errors.Keys.UnmodifiableObject_1, getClass()));
}
+ /**
+ * Do not allow modification of the parameter value.
+ */
+ @Override
+ public void setSourceFile(final URI source) {
+ throw new UnsupportedOperationException(Errors.format(Errors.Keys.UnmodifiableObject_1, getClass()));
+ }
+
/**
* Returns a modifiable copy of this parameter.
*/
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/package-info.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/package-info.java
index 4b3a2e0910..1299b3c4eb 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/package-info.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/package-info.java
@@ -85,7 +85,7 @@
* if the given value is not assignable to the expected class or is not inside the value domain.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.4
+ * @version 1.5
* @since 0.4
*/
@XmlSchema(elementFormDefault= XmlNsForm.QUALIFIED, namespace = Namespaces.GML, xmlns = {
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
index ca0cba5a49..cc2600eaa3 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
@@ -306,7 +306,7 @@ public final class CRS extends Static {
* Applications which need to parse a large amount of WKT strings should consider to use
* the {@link org.apache.sis.io.wkt.WKTFormat} class instead of this method.
*
- * @param text coordinate system encoded in Well-Known Text format (version 1 or 2).
+ * @param wkt coordinate system encoded in Well-Known Text format (version 1 or 2).
* @return the parsed Coordinate Reference System.
* @throws FactoryException if the given WKT cannot be parsed.
*
@@ -317,9 +317,8 @@ public final class CRS extends Static {
*
* @since 0.6
*/
- public static CoordinateReferenceSystem fromWKT(final String text) throws FactoryException {
- ArgumentChecks.ensureNonNull("text", text);
- final CoordinateReferenceSystem crs = GeodeticObjectFactory.provider().createFromWKT(text);
+ public static CoordinateReferenceSystem fromWKT(final String wkt) throws FactoryException {
+ final CoordinateReferenceSystem crs = GeodeticObjectFactory.provider().createFromWKT(wkt);
DefinitionVerifier.withAuthority(crs, Loggers.WKT, CRS.class, "fromWKT");
return crs;
}
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticObjectFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
index 95c4401371..ca55b08f28 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
@@ -1661,7 +1661,7 @@ public class GeodeticObjectFactory extends AbstractFactory implements CRSFactory
* Applications which need to parse a large amount of WKT strings should consider to use
* the {@link org.apache.sis.io.wkt.WKTFormat} class instead of this method.
*
- * @param text coordinate system encoded in Well-Known Text format (version 1 or 2).
+ * @param wkt coordinate system encoded in Well-Known Text format (version 1 or 2).
* @throws FactoryException if the object creation failed.
*
* @see org.apache.sis.io.wkt
@@ -1670,8 +1670,8 @@ public class GeodeticObjectFactory extends AbstractFactory implements CRSFactory
* @see <a href="http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html">Legacy WKT 1</a>
*/
@Override
- public CoordinateReferenceSystem createFromWKT(final String text) throws FactoryException {
- ArgumentChecks.ensureNonEmpty("text", text);
+ public CoordinateReferenceSystem createFromWKT(final String wkt) throws FactoryException {
+ ArgumentChecks.ensureNonEmpty("wkt", wkt);
Parser p = parser.getAndSet(null);
if (p == null) try {
Constructor<? extends Parser> c = parserConstructor;
@@ -1687,7 +1687,7 @@ public class GeodeticObjectFactory extends AbstractFactory implements CRSFactory
}
final Object object;
try {
- object = p.createFromWKT(text);
+ object = p.createFromWKT(wkt);
} catch (FactoryException e) {
/*
* In the case of map projection, the parsing may fail because a projection parameter is not known to SIS.
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
index e634c53788..6360e9bdd4 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
@@ -1659,15 +1659,15 @@ public class DefaultMathTransformFactory extends AbstractFactory implements Math
* inverse matrix but those information are lost at WKT formatting time. A similar "hidden" information
* lost may also happen with {@link WraparoundTransform}, also making that transform non-invertible.</p>
*
- * @param text math transform encoded in Well-Known Text format.
+ * @param wkt math transform encoded in Well-Known Text format.
* @return the math transform (never {@code null}).
* @throws FactoryException if the Well-Known Text cannot be parsed,
* or if the math transform creation failed from some other reason.
*/
@Override
- public MathTransform createFromWKT(final String text) throws FactoryException {
+ public MathTransform createFromWKT(final String wkt) throws FactoryException {
lastMethod.remove();
- ArgumentChecks.ensureNonEmpty("text", text);
+ ArgumentChecks.ensureNonEmpty("wkt", wkt);
Parser p = parser.getAndSet(null);
if (p == null) try {
Constructor<? extends Parser> c = parserConstructor;
@@ -1687,7 +1687,7 @@ public class DefaultMathTransformFactory extends AbstractFactory implements Math
*/
final Object object;
try {
- object = p.createFromWKT(text);
+ object = p.createFromWKT(wkt);
} catch (FactoryException e) {
/*
* The parsing may fail because a operation parameter is not known to SIS. If this happen, replace
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java
index b807ffad0f..c8ddc5db8c 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java
@@ -46,8 +46,8 @@ public final class ElementTest extends TestCase {
/**
* A dummy parser to be given to the {@link Element} constructor.
*/
- private final AbstractParser parser = new AbstractParser(Symbols.SQUARE_BRACKETS, new HashMap<>(2),
- null, null, null, Locale.ENGLISH)
+ private final AbstractParser parser = new AbstractParser(
+ null, new HashMap<>(2), Symbols.SQUARE_BRACKETS, null, null, null, Locale.ENGLISH)
{
@Override String getPublicFacade() {
throw new UnsupportedOperationException();
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
index 8ff779723e..32e34d9968 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
@@ -92,8 +92,8 @@ public final class GeodeticObjectParserTest extends TestCase {
* Instantiates the parser to test.
*/
private void newParser(final Convention convention) {
- parser = new GeodeticObjectParser(Symbols.getDefault(), Map.of(),
- null, null, null, convention, Transliterator.DEFAULT, null, new ReferencingFactoryContainer());
+ parser = new GeodeticObjectParser(null, Map.of(), Symbols.getDefault(), null, null, null,
+ convention, Transliterator.DEFAULT, null, new ReferencingFactoryContainer());
assertEquals(GeodeticObjectFactory.class.getCanonicalName(), parser.getPublicFacade());
}
diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/PRJDataStore.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/PRJDataStore.java
index 3249a57314..13449a229e 100644
--- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/PRJDataStore.java
+++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/PRJDataStore.java
@@ -144,7 +144,7 @@ public abstract class PRJDataStore extends URIDataStore {
* @throws DataStoreException if an error occurred while reading the file.
*/
protected final void readPRJ() throws DataStoreException {
- Exception cause = null;
+ Exception cause = null, suppressed = null;
try {
final AuxiliaryContent content = readAuxiliaryFile(PRJ);
if (content == null) {
@@ -154,6 +154,11 @@ public abstract class PRJDataStore extends URIDataStore {
final String wkt = content.toString();
final StoreFormat format = new StoreFormat(locale, timezone, null, listeners);
format.setConvention(Convention.WKT1_COMMON_UNITS); // Ignored if the format is WKT 2.
+ try {
+ format.setSourceFile(content.getURI());
+ } catch (URISyntaxException e) {
+ suppressed = e;
+ }
final ParsePosition pos = new ParsePosition(0);
crs = (CoordinateReferenceSystem) format.parse(wkt, pos);
if (crs != null) {
@@ -171,7 +176,9 @@ public abstract class PRJDataStore extends URIDataStore {
} catch (IOException | ParseException | ClassCastException e) {
cause = e;
}
- throw new DataStoreReferencingException(cannotReadAuxiliaryFile(PRJ), cause);
+ final var e = new DataStoreReferencingException(cannotReadAuxiliaryFile(PRJ), cause);
+ if (suppressed != null) e.addSuppressed(suppressed);
+ throw e;
}
/**
@@ -273,6 +280,16 @@ public abstract class PRJDataStore extends URIDataStore {
return IOUtilities.filename(source);
}
+ /**
+ * Returns the source as an URI if possible.
+ *
+ * @return the source as an URI, or {@code null} if none.
+ * @throws URISyntaxException if the URI cannot be parsed.
+ */
+ public URI getURI() throws URISyntaxException {
+ return IOUtilities.toURI(source);
+ }
+
/**
* Returns the number of valid characters in this sequence.
*/
(sis) 03/04: Partial migration of some tests to JUnit 5 and addition of a test for the `WKTFormat.setSourceFile(URI)` method added in previous commit.
Posted by de...@apache.org.
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 7e3f59dffe2dfd1af786e88a43b686c088c87236
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 27 22:02:24 2023 +0100
Partial migration of some tests to JUnit 5 and addition of a test for the `WKTFormat.setSourceFile(URI)` method added in previous commit.
---
.../org/apache/sis/console/CommandRunnerTest.java | 15 +-
.../apache/sis/coverage/grid/GridExtentTest.java | 23 +-
.../test/org/apache/sis/xml/XLinkTest.java | 25 +-
.../test/org/apache/sis/io/wkt/ColorsTest.java | 14 +-
.../org/apache/sis/io/wkt/ComparisonWithEPSG.java | 6 +-
.../test/org/apache/sis/io/wkt/ConventionTest.java | 2 +-
.../test/org/apache/sis/io/wkt/ElementTest.java | 140 +++----
.../sis/io/wkt/GeodeticObjectParserTest.java | 332 ++++++++---------
.../apache/sis/io/wkt/MathTransformParserTest.java | 20 +-
.../test/org/apache/sis/io/wkt/SymbolsTest.java | 39 +-
.../org/apache/sis/io/wkt/TransliteratorTest.java | 20 +-
.../org/apache/sis/io/wkt/WKTDictionaryTest.java | 109 +++---
.../test/org/apache/sis/io/wkt/WKTFormatTest.java | 60 ++-
.../test/org/apache/sis/io/wkt/WKTParserTest.java | 78 ++--
.../sis/parameter/DefaultParameterValueTest.java | 414 +++++++++------------
.../transform/MathTransformFactoryMock.java | 31 ++
.../operation/transform/PoleRotationTest.java | 2 +-
.../sis/io/stream/ChannelDataOutputTest.java | 20 +-
.../org/apache/sis/storage/FeatureQueryTest.java | 5 +-
.../apache/sis/storage/StorageConnectorTest.java | 49 ++-
.../org/apache/sis/measure/UnitFormatTest.java | 36 +-
.../test/org/apache/sis/test/Assertions.java | 84 +++--
.../org/apache/sis/util/ArgumentChecksTest.java | 44 +--
23 files changed, 753 insertions(+), 815 deletions(-)
diff --git a/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java b/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java
index c8286f0aa2..3760dea71d 100644
--- a/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java
+++ b/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.TestUtilities.getSingleton;
@@ -134,10 +135,9 @@ public final class CommandRunnerTest extends TestCase {
public void testMissingOptionValue() throws InvalidOptionException {
final CommandRunner c = new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--brief"); // Should not comply.
assertEquals(Option.BRIEF, getSingleton(c.options.keySet()));
- String message = assertThrows(InvalidOptionException.class,
- () -> new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--brief", "--locale"))
- .getMessage();
- assertTrue(message.contains("locale"));
+ InvalidOptionException exception = assertThrows(InvalidOptionException.class,
+ () -> new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--brief", "--locale"));
+ assertMessageContains(exception, "locale");
}
/**
@@ -147,10 +147,9 @@ public final class CommandRunnerTest extends TestCase {
*/
@Test
public void testUnexpectedOption() throws InvalidOptionException {
- String message = assertThrows(InvalidOptionException.class,
- () -> new Dummy(EnumSet.of(Option.HELP, Option.BRIEF), CommandRunner.TEST, "--brief", "--verbose", "--help"))
- .getMessage();
- assertTrue(message.contains("verbose"));
+ InvalidOptionException exception = assertThrows(InvalidOptionException.class,
+ () -> new Dummy(EnumSet.of(Option.HELP, Option.BRIEF), CommandRunner.TEST, "--brief", "--verbose", "--help"));
+ assertMessageContains(exception, "verbose");
}
/**
diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
index a656c5ea68..7174890014 100644
--- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
+++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
@@ -42,6 +42,7 @@ import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
import org.apache.sis.referencing.crs.HardCodedCRS;
import static org.apache.sis.test.Assertions.assertMapEquals;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.Assertions.assertMultilinesEquals;
import static org.apache.sis.referencing.Assertions.assertEnvelopeEquals;
@@ -294,9 +295,11 @@ public final class GridExtentTest extends TestCase {
assertExtentEquals(extent, 1, 220, 799);
assertExtentEquals(extent, 2, 40, 46);
assertSame(extent.intersect(domain), extent);
+
final GridExtent disjoint = domain.translate(0, 1000);
- String message = assertThrows(DisjointExtentException.class, () -> extent.intersect(disjoint)).getMessage();
- assertNotNull(message);
+ DisjointExtentException exception;
+ exception = assertThrows(DisjointExtentException.class, () -> extent.intersect(disjoint));
+ assertMessageContains(exception);
}
/**
@@ -323,8 +326,9 @@ public final class GridExtentTest extends TestCase {
new DimensionNameType[] {DimensionNameType.COLUMN, DimensionNameType.TRACK, DimensionNameType.TIME},
new long[] {100, 200, 40}, new long[] {500, 800, 50}, false);
- String message = assertThrows(IllegalArgumentException.class, () -> domain.intersect(other)).getMessage();
- assertNotNull(message);
+ IllegalArgumentException exception;
+ exception = assertThrows(IllegalArgumentException.class, () -> domain.intersect(other));
+ assertMessageContains(exception);
}
/**
@@ -367,8 +371,9 @@ public final class GridExtentTest extends TestCase {
* change in future SIS version).
*/
slicePoint.setOrdinate(0, 900);
- String message = assertThrows(PointOutsideCoverageException.class, () -> extent.slice(slicePoint, new int[] {1, 2})).getLocalizedMessage();
- assertTrue(message.contains("(900, 47)"), message); // See above comment.
+ PointOutsideCoverageException exception;
+ exception = assertThrows(PointOutsideCoverageException.class, () -> extent.slice(slicePoint, new int[] {1, 2}));
+ assertMessageContains(exception, "(900, 47)"); // See above comment.
}
/**
@@ -382,8 +387,10 @@ public final class GridExtentTest extends TestCase {
assertSubspaceEquals(extent, 0, 2 );
assertSubspaceEquals(extent, 0,1,2 );
assertSubspaceEquals(extent, 0,1,2,3);
- String message = assertThrows(SubspaceNotSpecifiedException.class, () -> extent.getSubspaceDimensions(1)).getMessage();
- assertNotNull(message);
+
+ SubspaceNotSpecifiedException exception;
+ exception = assertThrows(SubspaceNotSpecifiedException.class, () -> extent.getSubspaceDimensions(1));
+ assertMessageContains(exception);
}
/**
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java
index 6ac84d0d41..f4a38ab4c8 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java
@@ -24,6 +24,7 @@ import org.apache.sis.util.SimpleInternationalString;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
/**
@@ -108,10 +109,10 @@ public final class XLinkTest extends TestCase {
*/
link.freeze();
assertEquals(hashCode, link.hashCode(), "hashCode");
- String message;
- message = assertThrows(UnsupportedOperationException.class, () -> link.setType(null),
- "The XLink should be unmodifiable.").getMessage();
- assertTrue(message.contains("XLink"));
+
+ UnsupportedOperationException exception;
+ exception = assertThrows(UnsupportedOperationException.class, () -> link.setType(null), "The XLink should be unmodifiable.");
+ assertMessageContains(exception, "XLink");
}
/**
@@ -124,20 +125,19 @@ public final class XLinkTest extends TestCase {
final XLink link = new XLink();
link.setType(XLink.Type.SIMPLE);
link.setHRef(new URI("org:apache:sis:href"));
- String message;
/*
* Should not be allowed to set the label.
*/
+ IllegalStateException exception;
assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString());
- message = assertThrows(IllegalStateException.class, () -> link.setLabel("SomeLabel")).getMessage();
- assertTrue(message.contains("label"));
- assertTrue(message.contains("simple"));
+ exception = assertThrows(IllegalStateException.class, () -> link.setLabel("SomeLabel"));
+ assertMessageContains(exception, "label", "simple");
/*
* Should not be allowed to set a type that does not include HREF.
*/
assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString());
- message = assertThrows(IllegalStateException.class, () -> link.setType(XLink.Type.EXTENDED)).getMessage();
- assertTrue(message.contains("extended"));
+ exception = assertThrows(IllegalStateException.class, () -> link.setType(XLink.Type.EXTENDED));
+ assertMessageContains(exception, "extended");
/*
* The Locator type contains the HREF attribute, so the following operation should be allowed.
*/
@@ -148,8 +148,9 @@ public final class XLinkTest extends TestCase {
* Now freezes the XLink and ensures that it is really immutable.
*/
link.freeze();
- message = assertThrows(UnsupportedOperationException.class, () -> link.setHRef(null)).getMessage();
- assertTrue(message.contains("XLink"));
+ UnsupportedOperationException e;
+ e = assertThrows(UnsupportedOperationException.class, () -> link.setHRef(null));
+ assertMessageContains(e, "XLink");
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java
index 9684f98c4b..37c7974deb 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java
@@ -18,9 +18,10 @@ package org.apache.sis.io.wkt;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
import org.apache.sis.test.DependsOnMethod;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.Assertions.assertSerializedEquals;
@@ -65,14 +66,9 @@ public final class ColorsTest extends TestCase {
*/
@Test
public void testImmutability() {
- try {
- Colors.DEFAULT.setName(ElementKind.METHOD, "blue");
- fail("Constant shall be immutable.");
- } catch (UnsupportedOperationException e) {
- // This is the expected exception.
- final String message = e.getMessage();
- assertTrue(message, message.contains("Colors"));
- }
+ UnsupportedOperationException e;
+ e = assertThrows(UnsupportedOperationException.class, () -> Colors.DEFAULT.setName(ElementKind.METHOD, "blue"));
+ assertMessageContains(e, "Colors");
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java
index 320ccc22f8..dbd2152e25 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java
@@ -28,7 +28,7 @@ import org.apache.sis.referencing.factory.sql.EPSGFactory;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.junit.Test;
-import static org.junit.Assume.assumeNotNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.apache.sis.test.TestCase;
import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata;
@@ -162,7 +162,7 @@ public final class ComparisonWithEPSG extends TestCase {
private static void compare(final String wkt, final int epsg) throws FactoryException {
final CoordinateReferenceSystem crs = CRS.fromWKT(wkt);
final EPSGFactory factory = TestFactorySource.factory;
- assumeNotNull(factory);
+ assumeTrue(factory != null);
final CoordinateReferenceSystem reference = factory.createProjectedCRS(Integer.toString(epsg));
assertEqualsIgnoreMetadata(reference, crs);
}
@@ -178,7 +178,7 @@ public final class ComparisonWithEPSG extends TestCase {
@Test
public void testCoordinateOperation() throws FactoryException, ParseException {
final EPSGFactory factory = TestFactorySource.factory;
- assumeNotNull(factory);
+ assumeTrue(factory != null);
CoordinateOperation opFromCode = factory.createCoordinateOperation("5630");
String wkt = opFromCode.toWKT();
WKTFormat parser = new WKTFormat(null, null);
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ConventionTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ConventionTest.java
index 76c4075f0f..acb824827c 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ConventionTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ConventionTest.java
@@ -20,7 +20,7 @@ import org.apache.sis.metadata.iso.citation.Citations;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java
index c8ddc5db8c..5630062043 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java
@@ -25,7 +25,7 @@ import org.apache.sis.util.CharSequences;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestUtilities;
import org.apache.sis.test.TestCase;
@@ -67,13 +67,13 @@ public final class ElementTest extends TestCase {
try {
element = new Element(parser, text, position);
} catch (ParseException e) {
- assertEquals("index should be unchanged.", 0, position.getIndex());
- assertTrue("Error index should be set.", position.getErrorIndex() > 0);
- assertEquals("Expected consistent error indices.", position.getErrorIndex(), e.getErrorOffset());
+ assertEquals(0, position.getIndex(), "index should be unchanged.");
+ assertTrue(position.getErrorIndex() > 0, "Error index should be set.");
+ assertEquals(position.getErrorIndex(), e.getErrorOffset(), "Expected consistent error indices.");
throw e;
}
- assertEquals("errorIndex", -1, position.getErrorIndex());
- assertEquals("index", CharSequences.skipTrailingWhitespaces(text, 0, text.length()), position.getIndex());
+ assertEquals(-1, position.getErrorIndex(), "errorIndex");
+ assertEquals(CharSequences.skipTrailingWhitespaces(text, 0, text.length()), position.getIndex(), "index");
return element;
}
@@ -85,27 +85,27 @@ public final class ElementTest extends TestCase {
@Test
public void testPullString() throws ParseException {
Element element = parse("Datum[\"World Geodetic System 1984\"]");
- assertEquals("keyword", "Datum", element.keyword);
- assertEquals("value", "World Geodetic System 1984", element.pullString("value"));
+ assertEquals("Datum", element.keyword);
+ assertEquals("World Geodetic System 1984", element.pullString("value"));
element.close(null);
// Alternative bracket and quote characters.
element = parse("Datum(“World Geodetic System 1984”)");
- assertEquals("keyword", "Datum", element.keyword);
- assertEquals("value", "World Geodetic System 1984", element.pullString("value"));
+ assertEquals("Datum", element.keyword);
+ assertEquals("World Geodetic System 1984", element.pullString("value"));
element.close(null);
// Leading and trailing spaces inside quotes should be ignored (ISO 19162 §B.4).
element = parse(" Datum [ \" World Geodetic System 1984 \" ] ");
- assertEquals("keyword", "Datum", element.keyword);
- assertEquals("value", "World Geodetic System 1984", element.pullString("value"));
+ assertEquals("Datum", element.keyword);
+ assertEquals("World Geodetic System 1984", element.pullString("value"));
element.close(null);
// Consecutive values.
element = parse("A[\"B\", \"C\"]");
- assertEquals("keyword", "A", element.keyword);
- assertEquals("first", "B", element.pullString("first"));
- assertEquals("second", "C", element.pullString("second"));
+ assertEquals("A", element.keyword);
+ assertEquals("B", element.pullString("first"));
+ assertEquals("C", element.pullString("second"));
element.close(null);
}
@@ -119,20 +119,20 @@ public final class ElementTest extends TestCase {
@DependsOnMethod("testPullString")
public void testEnclosedQuotes() throws ParseException {
Element element = parse("A[“text.”]");
- assertEquals("keyword", "A", element.keyword);
- assertEquals("value", "text.", element.pullString("value"));
+ assertEquals("A", element.keyword);
+ assertEquals("text.", element.pullString("value"));
element.close(null);
// No need to double the enclosed quotes here.
element = parse("A[“text with \"quotes\".”]");
- assertEquals("keyword", "A", element.keyword);
- assertEquals("value", "text with \"quotes\".", element.pullString("value"));
+ assertEquals("A", element.keyword);
+ assertEquals("text with \"quotes\".", element.pullString("value"));
element.close(null);
// Those enclosed quotes need to be doubled.
element = parse("A[\"text with \"\"double quotes\"\".\"]");
- assertEquals("keyword", "A", element.keyword);
- assertEquals("value", "text with \"double quotes\".", element.pullString("value"));
+ assertEquals("A", element.keyword);
+ assertEquals("text with \"double quotes\".", element.pullString("value"));
element.close(null);
}
@@ -146,11 +146,11 @@ public final class ElementTest extends TestCase {
@DependsOnMethod("testPullString") // Because there is some common code in the Element class.
public void testPullDouble() throws ParseException {
Element element = parse("C[3.1, 4.2, 5.3E3, 6.4e3]");
- assertEquals("keyword", "C", element.keyword);
- assertEquals("first", 3.1, element.pullDouble("first"), STRICT);
- assertEquals("second", 4.2, element.pullDouble("second"), STRICT);
- assertEquals("third", 5300, element.pullDouble("third"), STRICT);
- assertEquals("forth", 6400, element.pullDouble("forth"), STRICT);
+ assertEquals("C", element.keyword);
+ assertEquals( 3.1, element.pullDouble("first"));
+ assertEquals( 4.2, element.pullDouble("second"));
+ assertEquals(5300, element.pullDouble("third"));
+ assertEquals(6400, element.pullDouble("forth"));
element.close(null);
}
@@ -162,23 +162,19 @@ public final class ElementTest extends TestCase {
@Test
@DependsOnMethod("testPullDouble") // Because there is lot of common code in the Element class.
public void testPullInteger() throws ParseException {
- Element element = parse("B[3, 7, -5, 6]");
- assertEquals("keyword", "B", element.keyword);
- assertEquals("first", 3, element.pullInteger("first"));
- assertEquals("second", 7, element.pullInteger("second"));
- assertEquals("third", -5, element.pullInteger("third"));
- assertEquals("forth", 6, element.pullInteger("forth"));
+ final Element element = parse("B[3, 7, -5, 6]");
+ assertEquals("B", element.keyword);
+ assertEquals( 3, element.pullInteger("first"));
+ assertEquals( 7, element.pullInteger("second"));
+ assertEquals(-5, element.pullInteger("third"));
+ assertEquals( 6, element.pullInteger("forth"));
element.close(null);
/*
* Tests error message.
*/
- element = parse("B[6.5]");
- try {
- element.pullInteger("forth");
- fail("Double value cannot be parsed as an integer.");
- } catch (ParseException e) {
- assertEquals("Text “6.5” cannot be parsed as an object of type ‘Integer’.", e.getLocalizedMessage());
- }
+ final Element next = parse("B[6.5]");
+ ParseException e = assertThrows(ParseException.class, () -> next.pullInteger("forth"));
+ assertEquals("Text “6.5” cannot be parsed as an object of type ‘Integer’.", e.getLocalizedMessage());
}
/**
@@ -190,8 +186,8 @@ public final class ElementTest extends TestCase {
@DependsOnMethod("testPullDouble") // Because there is lot of common code in the Element class.
public void testPullDate() throws ParseException {
Element element = parse("TimeOrigin[1858-11-17T00:00:00.0Z]");
- assertEquals("keyword", "TimeOrigin", element.keyword);
- assertEquals("date", TestUtilities.date("1858-11-17 00:00:00"), element.pullDate("date"));
+ assertEquals("TimeOrigin", element.keyword);
+ assertEquals(TestUtilities.date("1858-11-17 00:00:00"), element.pullDate("date"));
element.close(null);
}
@@ -204,24 +200,20 @@ public final class ElementTest extends TestCase {
@DependsOnMethod("testPullString") // Because there is some common code in the Element class.
public void testPullBoolean() throws ParseException {
Element element = parse("ConformanceResult[true]");
- assertEquals("keyword", "ConformanceResult", element.keyword);
- assertTrue("pass", element.pullBoolean("pass"));
+ assertEquals("ConformanceResult", element.keyword);
+ assertTrue(element.pullBoolean("pass"));
element.close(null);
element = parse("ConformanceResult[false]");
- assertEquals("keyword", "ConformanceResult", element.keyword);
- assertFalse("pass", element.pullBoolean("pass"));
+ assertEquals("ConformanceResult", element.keyword);
+ assertFalse(element.pullBoolean("pass"));
element.close(null);
/*
* Tests error message.
*/
- element = parse("ConformanceResult[falseX]");
- try {
- element.pullBoolean("pass");
- fail("Should not accept “falseX” as a boolean.");
- } catch (ParseException e) {
- assertEquals("Missing a “pass” component in “ConformanceResult”.", e.getLocalizedMessage());
- }
+ final Element next = parse("ConformanceResult[falseX]");
+ ParseException e = assertThrows(ParseException.class, () -> next.pullBoolean("pass"));
+ assertEquals("Missing a “pass” component in “ConformanceResult”.", e.getLocalizedMessage());
}
/**
@@ -233,29 +225,26 @@ public final class ElementTest extends TestCase {
@DependsOnMethod("testPullDate")
public void testPullElement() throws ParseException {
Element element = parse("TimeDatum[“Modified Julian”, TimeOrigin[1858-11-17T00:00:00.0Z]]");
- assertEquals("keyword", "TimeDatum", element.keyword);
- assertEquals("name", "Modified Julian", element.pullString("name"));
+ assertEquals("TimeDatum", element.keyword);
+ assertEquals("Modified Julian", element.pullString("name"));
Element inner = element.pullElement(AbstractParser.MANDATORY, "TimeOrigin");
- assertEquals("keyword", "TimeOrigin", inner.keyword);
- assertEquals("date", TestUtilities.date("1858-11-17 00:00:00"), inner.pullDate("date"));
+ assertEquals("TimeOrigin", inner.keyword);
+ assertEquals(TestUtilities.date("1858-11-17 00:00:00"), inner.pullDate("date"));
inner.close(null);
element.close(null);
}
/**
* Tests {@link Element#close(Map)}.
+ * This method should not accept to close an element when it still have unparsed child elements.
*
* @throws ParseException if an error occurred during the parsing.
*/
@Test
public void testClose() throws ParseException {
final Element element = parse("A[\"B\", \"C\"]");
- try {
- element.close(null);
- fail("Should not close will we still have unparsed elements.");
- } catch (ParseException e) {
- assertEquals("Unexpected value “B” in “A” element.", e.getLocalizedMessage());
- }
+ ParseException e = assertThrows(ParseException.class, () -> element.close(null));
+ assertEquals("Unexpected value “B” in “A” element.", e.getLocalizedMessage());
}
/**
@@ -263,27 +252,18 @@ public final class ElementTest extends TestCase {
*/
@Test
public void testParsingErrors() {
+ ParseException e;
+
// Missing closing quote or using the wrong quote character.
- try {
- parse("QuoteTest[“text\"]");
- fail("Should complain about missing quote.");
- } catch (ParseException e) {
- assertEquals("Missing a ‘”’ character in “QuoteTest” element.", e.getLocalizedMessage());
- }
+ e = assertThrows(ParseException.class, () -> parse("QuoteTest[“text\"]"));
+ assertEquals("Missing a ‘”’ character in “QuoteTest” element.", e.getLocalizedMessage());
// Missing closing bracket or using the wrong bracket character.
- try {
- parse("BracketTest(“text”]");
- fail("Should complain about missing bracket.");
- } catch (ParseException e) {
- assertEquals("Cannot parse “]” in element “BracketTest”.", e.getLocalizedMessage());
- }
- try {
- parse("BracketTest(“text”");
- fail("Should complain about missing bracket.");
- } catch (ParseException e) {
- assertEquals("Missing a ‘)’ character in “BracketTest” element.", e.getLocalizedMessage());
- }
+ e = assertThrows(ParseException.class, () -> parse("BracketTest(“text”]"));
+ assertEquals("Cannot parse “]” in element “BracketTest”.", e.getLocalizedMessage());
+
+ e = assertThrows(ParseException.class, () -> parse("BracketTest(“text”"));
+ assertEquals("Missing a ‘)’ character in “BracketTest” element.", e.getLocalizedMessage());
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
index 32e34d9968..5501c0de36 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
@@ -47,11 +47,11 @@ import static org.apache.sis.util.internal.StandardDateFormat.MILLISECONDS_PER_D
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.opengis.test.Assert.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.Assertions.assertMultilinesEquals;
import static org.apache.sis.referencing.Assertions.assertAxisEquals;
import static org.apache.sis.referencing.Assertions.assertDiagonalEquals;
@@ -111,9 +111,9 @@ public final class GeodeticObjectParserTest extends TestCase {
}
final ParsePosition position = new ParsePosition(0);
final Object obj = parser.createFromWKT(text, position);
- assertEquals("errorIndex", -1, position.getErrorIndex());
- assertEquals("index", text.length(), position.getIndex());
- assertInstanceOf("GeodeticObjectParser.parseObject", type, obj);
+ assertEquals(-1, position.getErrorIndex(), "errorIndex");
+ assertEquals(text.length(), position.getIndex(), "index");
+ assertInstanceOf(type, obj, "GeodeticObjectParser.parseObject");
return type.cast(obj);
}
@@ -127,8 +127,8 @@ public final class GeodeticObjectParserTest extends TestCase {
*/
private <T> T parse(final Class<T> type, final String text) throws ParseException {
final T obj = parseIgnoreWarnings(type, text);
- assertNull("warnings", parser.getAndClearWarnings(obj));
- assertTrue("ignoredElements", parser.ignoredElements.isEmpty());
+ assertNull(parser.getAndClearWarnings(obj), "warnings");
+ assertTrue(parser.ignoredElements.isEmpty(), "ignoredElements");
return obj;
}
@@ -146,11 +146,11 @@ public final class GeodeticObjectParserTest extends TestCase {
*/
static void assertNameAndIdentifierEqual(final String name, final int epsg, final IdentifiedObject object) {
final String message = object.getClass().getSimpleName();
- assertEquals(message, name, object.getName().getCode());
+ assertEquals(name, object.getName().getCode(), message);
if (epsg != 0) {
- assertEquals(message, String.valueOf(epsg), getSingleton(object.getIdentifiers()).getCode());
+ assertEquals(String.valueOf(epsg), getSingleton(object.getIdentifiers()).getCode(), message);
} else {
- assertTrue(message, object.getIdentifiers().isEmpty());
+ assertTrue(object.getIdentifiers().isEmpty(), message);
}
}
@@ -189,40 +189,40 @@ public final class GeodeticObjectParserTest extends TestCase {
@Test
public void testAxis() throws ParseException {
CoordinateSystemAxis axis = parse(CoordinateSystemAxis.class, "AXIS[“(Y)”, geocentricY]");
- assertEquals("name", "Y", axis.getName().getCode());
- assertEquals("abbreviation", "Y", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.GEOCENTRIC_Y, axis.getDirection());
- assertEquals("unit", Units.METRE, axis.getUnit());
+ assertEquals("Y", axis.getName().getCode(), "name");
+ assertEquals("Y", axis.getAbbreviation(), "abbreviation");
+ assertEquals(AxisDirection.GEOCENTRIC_Y, axis.getDirection(), "direction");
+ assertEquals(Units.METRE, axis.getUnit(), "unit");
axis = parse(CoordinateSystemAxis.class, "AXIS[“latitude”,north,ORDER[1],ANGLEUNIT[“degree”,0.0174532925199433]]");
- assertEquals("name", "Latitude", axis.getName().getCode());
- assertEquals("abbreviation", "φ", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.NORTH, axis.getDirection());
- assertEquals("unit", Units.DEGREE, axis.getUnit());
+ assertEquals("Latitude", axis.getName().getCode(), "name");
+ assertEquals("φ", axis.getAbbreviation(), "abbreviation");
+ assertEquals(AxisDirection.NORTH, axis.getDirection(), "direction");
+ assertEquals(Units.DEGREE, axis.getUnit(), "unit");
axis = parse(CoordinateSystemAxis.class, "AXIS[“longitude”,EAST,order[2],UNIT[“degree”,0.0174532925199433]]");
- assertEquals("name", "Longitude", axis.getName().getCode());
- assertEquals("abbreviation", "λ", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.EAST, axis.getDirection());
- assertEquals("unit", Units.DEGREE, axis.getUnit());
+ assertEquals("Longitude", axis.getName().getCode(), "name");
+ assertEquals("λ", axis.getAbbreviation(), "abbreviation");
+ assertEquals(AxisDirection.EAST, axis.getDirection(), "direction");
+ assertEquals(Units.DEGREE, axis.getUnit(), "unit");
axis = parse(CoordinateSystemAxis.class, "AXIS[“ellipsoidal height (h)”,up,ORDER[3],LengthUnit[“kilometre”,1000]]");
- assertEquals("name", "Ellipsoidal height", axis.getName().getCode());
- assertEquals("abbreviation", "h", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.UP, axis.getDirection());
- assertEquals("unit", Units.KILOMETRE, axis.getUnit());
+ assertEquals("Ellipsoidal height", axis.getName().getCode(), "name");
+ assertEquals("h", axis.getAbbreviation(), "abbreviation");
+ assertEquals(AxisDirection.UP, axis.getDirection(), "direction");
+ assertEquals(Units.KILOMETRE, axis.getUnit(), "unit");
axis = parse(CoordinateSystemAxis.class, "AXIS[“time (t)”,future,TimeUnit[“hour”,3600]]");
- assertEquals("name", "Time", axis.getName().getCode());
- assertEquals("abbreviation", "t", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.FUTURE, axis.getDirection());
- assertEquals("unit", Units.HOUR, axis.getUnit());
+ assertEquals("Time", axis.getName().getCode(), "name");
+ assertEquals("t", axis.getAbbreviation(), "abbreviation");
+ assertEquals(AxisDirection.FUTURE, axis.getDirection(), "direction");
+ assertEquals(Units.HOUR, axis.getUnit(), "unit");
axis = parse(CoordinateSystemAxis.class, "AXIS[“easting (X)”,south,MERIDIAN[90,UNIT[“degree”,0.0174532925199433]]]");
- assertEquals("name", "Easting", axis.getName().getCode());
- assertEquals("abbreviation", "X", axis.getAbbreviation());
- assertEquals("direction", CoordinateSystems.directionAlongMeridian(AxisDirection.SOUTH, 90), axis.getDirection());
- assertEquals("unit", Units.METRE, axis.getUnit());
+ assertEquals("Easting", axis.getName().getCode(), "name");
+ assertEquals("X", axis.getAbbreviation(), "abbreviation");
+ assertEquals(CoordinateSystems.directionAlongMeridian(AxisDirection.SOUTH, 90), axis.getDirection(), "direction");
+ assertEquals(Units.METRE, axis.getUnit(), "unit");
}
/**
@@ -238,14 +238,14 @@ public final class GeodeticObjectParserTest extends TestCase {
" ANCHOR[“Tananarive observatory”]]");
assertNameAndIdentifierEqual("Tananarive 1925", 0, datum);
- assertEquals("anchor", "Tananarive observatory", String.valueOf(datum.getAnchorPoint()));
+ assertEquals("Tananarive observatory", String.valueOf(datum.getAnchorPoint()));
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("International 1924", 0, ellipsoid);
- assertEquals("unit", Units.KILOMETRE, ellipsoid.getAxisUnit());
- assertEquals("semiMajor", 6378.388, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 297, ellipsoid.getInverseFlattening(), STRICT);
- assertEquals("greenwichLongitude", 0, datum.getPrimeMeridian().getGreenwichLongitude(), STRICT);
+ assertEquals(Units.KILOMETRE, ellipsoid.getAxisUnit(), "unit");
+ assertEquals(6378.388, ellipsoid.getSemiMajorAxis(), "semiMajor");
+ assertEquals(297, ellipsoid.getInverseFlattening(), "inverseFlattening");
+ assertEquals(0, datum.getPrimeMeridian().getGreenwichLongitude(), "greenwichLongitude");
}
/**
@@ -277,12 +277,12 @@ public final class GeodeticObjectParserTest extends TestCase {
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("WGS84", 7030, ellipsoid);
- assertEquals("semiMajor", 6378137, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 298.257223563, ellipsoid.getInverseFlattening(), STRICT);
+ assertEquals(6378137, ellipsoid.getSemiMajorAxis(), "semiMajor");
+ assertEquals(298.257223563, ellipsoid.getInverseFlattening(), "inverseFlattening");
// Verify that the OGC 01-009 axes have been relaced by ISO 19111 axes.
final CartesianCS cs = (CartesianCS) crs.getCoordinateSystem();
- assertEquals("dimension", 3, cs.getDimension());
+ assertEquals(3, cs.getDimension(), "dimension");
assertUnboundedAxisEquals(AxisNames.GEOCENTRIC_X, "X", AxisDirection.GEOCENTRIC_X, Units.METRE, cs.getAxis(0));
assertUnboundedAxisEquals(AxisNames.GEOCENTRIC_Y, "Y", AxisDirection.GEOCENTRIC_Y, Units.METRE, cs.getAxis(1));
assertUnboundedAxisEquals(AxisNames.GEOCENTRIC_Z, "Z", AxisDirection.GEOCENTRIC_Z, Units.METRE, cs.getAxis(2));
@@ -368,24 +368,24 @@ public final class GeodeticObjectParserTest extends TestCase {
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("GRS 1980", 0, ellipsoid);
- assertEquals("semiMajor", 6378137, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 298.257222101, ellipsoid.getInverseFlattening(), STRICT);
+ assertEquals(6378137, ellipsoid.getSemiMajorAxis(), "semiMajor");
+ assertEquals(298.257222101, ellipsoid.getInverseFlattening(), "inverseFlattening");
final EllipsoidalCS cs = crs.getCoordinateSystem();
final double secondsIn90 = 90*60*60;
CoordinateSystemAxis axis = cs.getAxis(0);
- assertEquals("name", AxisNames.GEODETIC_LONGITUDE, axis.getName().getCode());
- assertEquals("abbreviation", "λ", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.EAST, axis.getDirection());
- assertEquals("minimumValue", -secondsIn90*2, axis.getMinimumValue(), 1E-9);
- assertEquals("maximumValue", +secondsIn90*2, axis.getMaximumValue(), 1E-9);
+ assertEquals(AxisNames.GEODETIC_LONGITUDE, axis.getName().getCode());
+ assertEquals("λ", axis.getAbbreviation());
+ assertEquals(AxisDirection.EAST, axis.getDirection());
+ assertEquals(-secondsIn90*2, axis.getMinimumValue(), 1E-9);
+ assertEquals(+secondsIn90*2, axis.getMaximumValue(), 1E-9);
axis = cs.getAxis(1);
- assertEquals("name", AxisNames.GEODETIC_LATITUDE, axis.getName().getCode());
- assertEquals("abbreviation", "φ", axis.getAbbreviation());
- assertEquals("direction", AxisDirection.NORTH, axis.getDirection());
- assertEquals("minimumValue", -secondsIn90, axis.getMinimumValue(), 1E-9);
- assertEquals("maximumValue", +secondsIn90, axis.getMaximumValue(), 1E-9);
+ assertEquals(AxisNames.GEODETIC_LATITUDE, axis.getName().getCode());
+ assertEquals("φ", axis.getAbbreviation());
+ assertEquals(AxisDirection.NORTH, axis.getDirection());
+ assertEquals(-secondsIn90, axis.getMinimumValue(), 1E-9);
+ assertEquals(+secondsIn90, axis.getMaximumValue(), 1E-9);
}
/**
@@ -429,10 +429,10 @@ public final class GeodeticObjectParserTest extends TestCase {
GeographicCRS crs = parse(GeographicCRS.class, wkt);
assertNameAndIdentifierEqual("NTF (Paris)", 0, crs);
PrimeMeridian pm = verifyNTF(crs.getDatum(), false);
- assertEquals("angularUnit", Units.GRAD, pm.getAngularUnit());
- assertEquals("greenwichLongitude", 2.5969213, pm.getGreenwichLongitude(), STRICT);
+ assertEquals(Units.GRAD, pm.getAngularUnit(), "angularUnit");
+ assertEquals(2.5969213, pm.getGreenwichLongitude(), "greenwichLongitude");
EllipsoidalCS cs = crs.getCoordinateSystem();
- assertEquals("dimension", 2, cs.getDimension());
+ assertEquals(2, cs.getDimension(), "dimension");
assertAxisEquals(AxisNames.GEODETIC_LATITUDE, "φ", AxisDirection.NORTH, -100, +100, Units.GRAD, RangeMeaning.EXACT, cs.getAxis(0));
assertAxisEquals(AxisNames.GEODETIC_LONGITUDE, "λ", AxisDirection.EAST, -200, +200, Units.GRAD, RangeMeaning.WRAPAROUND, cs.getAxis(1));
/*
@@ -451,10 +451,10 @@ public final class GeodeticObjectParserTest extends TestCase {
crs = parse(GeographicCRS.class, wkt);
assertNameAndIdentifierEqual("NTF (Paris)", 0, crs);
pm = verifyNTF(crs.getDatum(), false);
- assertEquals("angularUnit", Units.DEGREE, pm.getAngularUnit());
- assertEquals("greenwichLongitude", 2.33722917, pm.getGreenwichLongitude(), STRICT);
+ assertEquals(Units.DEGREE, pm.getAngularUnit(), "angularUnit");
+ assertEquals(2.33722917, pm.getGreenwichLongitude(), "greenwichLongitude");
cs = crs.getCoordinateSystem();
- assertEquals("dimension", 2, cs.getDimension());
+ assertEquals(2, cs.getDimension(), "dimension");
assertAxisEquals(AxisNames.GEODETIC_LONGITUDE, "λ", AxisDirection.EAST, -200, +200, Units.GRAD, RangeMeaning.WRAPAROUND, cs.getAxis(0));
assertAxisEquals(AxisNames.GEODETIC_LATITUDE, "φ", AxisDirection.NORTH, -100, +100, Units.GRAD, RangeMeaning.EXACT, cs.getAxis(1));
}
@@ -487,16 +487,16 @@ public final class GeodeticObjectParserTest extends TestCase {
GeographicCRS crs = parseIgnoreWarnings(GeographicCRS.class, wkt);
final Warnings warnings = parser.getAndClearWarnings(crs);
- assertTrue("ignoredElements", parser.ignoredElements.isEmpty());
- assertNotNull("warnings", warnings);
- assertEquals("warnings.numMessages", 1, warnings.getNumMessages());
+ assertTrue(parser.ignoredElements.isEmpty());
+ assertNotNull(warnings);
+ assertEquals(1, warnings.getNumMessages());
assertNameAndIdentifierEqual("NTF (Paris)", 4807, crs);
PrimeMeridian pm = crs.getDatum().getPrimeMeridian();
- assertEquals("angularUnit", Units.DEGREE, pm.getAngularUnit());
- assertEquals("greenwichLongitude", 2.33722917, pm.getGreenwichLongitude(), STRICT);
+ assertEquals(Units.DEGREE, pm.getAngularUnit(), "angularUnit");
+ assertEquals(2.33722917, pm.getGreenwichLongitude(), "greenwichLongitude");
EllipsoidalCS cs = crs.getCoordinateSystem();
- assertEquals("dimension", 2, cs.getDimension());
+ assertEquals(2, cs.getDimension(), "dimension");
assertAxisEquals(AxisNames.GEODETIC_LATITUDE, "φ", AxisDirection.NORTH, -90, +90, Units.DEGREE, RangeMeaning.EXACT, cs.getAxis(0));
assertAxisEquals(AxisNames.GEODETIC_LONGITUDE, "λ", AxisDirection.EAST, -180, +180, Units.DEGREE, RangeMeaning.WRAPAROUND, cs.getAxis(1));
}
@@ -516,11 +516,11 @@ public final class GeodeticObjectParserTest extends TestCase {
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("WGS84", 0, ellipsoid);
- assertEquals("semiMajor", 6378137, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 298.257223563, ellipsoid.getInverseFlattening(), STRICT);
+ assertEquals(6378137, ellipsoid.getSemiMajorAxis(), "semiMajor");
+ assertEquals(298.257223563, ellipsoid.getInverseFlattening(), "inverseFlattening");
final EllipsoidalCS cs = crs.getCoordinateSystem();
- assertEquals("dimension", 2, cs.getDimension());
+ assertEquals(2, cs.getDimension(), "dimension");
assertLongitudeAxisEquals(cs.getAxis(0 ^ swap));
assertLatitudeAxisEquals (cs.getAxis(1 ^ swap));
}
@@ -530,7 +530,7 @@ public final class GeodeticObjectParserTest extends TestCase {
* with (East, North) axis directions.
*/
private static void verifyProjectedCS(final CartesianCS cs, final Unit<Length> unit) {
- assertEquals("dimension", 2, cs.getDimension());
+ assertEquals(2, cs.getDimension(), "dimension");
assertUnboundedAxisEquals("Easting", "E", AxisDirection.EAST, unit, cs.getAxis(0));
assertUnboundedAxisEquals("Northing", "N", AxisDirection.NORTH, unit, cs.getAxis(1));
}
@@ -571,17 +571,17 @@ public final class GeodeticObjectParserTest extends TestCase {
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("WGS84", 0, ellipsoid);
- assertEquals("semiMajor", 6378137, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 298.257223563, ellipsoid.getInverseFlattening(), STRICT);
+ assertEquals(6378137, ellipsoid.getSemiMajorAxis(), "semiMajor");
+ assertEquals(298.257223563, ellipsoid.getInverseFlattening(), "inverseFlattening");
assertEquals("Mercator (variant A)", crs.getConversionFromBase().getMethod().getName().getCode());
final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
- assertEquals("semi_major", 6378137.0, param.parameter("semi_major" ).doubleValue(Units.METRE), STRICT);
- assertEquals("semi_minor", 6356752.3, param.parameter("semi_minor" ).doubleValue(Units.METRE), 0.1);
- assertEquals("central_meridian", -20.0, param.parameter("central_meridian").doubleValue(Units.DEGREE), STRICT);
- assertEquals("scale_factor", 1.0, param.parameter("scale_factor" ).doubleValue(Units.UNITY), STRICT);
- assertEquals("false_easting", 500000.0, param.parameter("false_easting" ).doubleValue(Units.METRE), STRICT);
- assertEquals("false_northing", 0.0, param.parameter("false_northing" ).doubleValue(Units.METRE), STRICT);
+ assertEquals(6378137.0, param.parameter("semi_major" ).doubleValue(Units.METRE));
+ assertEquals(6356752.3, param.parameter("semi_minor" ).doubleValue(Units.METRE), 0.1);
+ assertEquals( -20.0, param.parameter("central_meridian").doubleValue(Units.DEGREE));
+ assertEquals( 1.0, param.parameter("scale_factor" ).doubleValue(Units.UNITY));
+ assertEquals( 500000.0, param.parameter("false_easting" ).doubleValue(Units.METRE));
+ assertEquals( 0.0, param.parameter("false_northing" ).doubleValue(Units.METRE));
}
/**
@@ -620,17 +620,17 @@ public final class GeodeticObjectParserTest extends TestCase {
final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
assertEquals("Transverse Mercator", crs.getConversionFromBase().getMethod().getName().getCode());
- assertEquals("semi_major", 6377563.396, param.parameter("semi_major" ).doubleValue(), 1E-4);
- assertEquals("semi_minor", 6356256.909, param.parameter("semi_minor" ).doubleValue(), 1E-3);
- assertEquals("latitude_of_origin", 49.0, param.parameter("latitude_of_origin").doubleValue(), 1E-8);
- assertEquals("central_meridian", -2.0, param.parameter("central_meridian" ).doubleValue(), 1E-8);
- assertEquals("scale_factor", 0.9996, param.parameter("scale_factor" ).doubleValue(), 1E-5);
- assertEquals("false_easting", 400000.0, param.parameter("false_easting" ).doubleValue(), 1E-4);
- assertEquals("false_northing", -100000.0, param.parameter("false_northing" ).doubleValue(), 1E-4);
+ assertEquals(6377563.396, param.parameter("semi_major" ).doubleValue(), 1E-4);
+ assertEquals(6356256.909, param.parameter("semi_minor" ).doubleValue(), 1E-3);
+ assertEquals( 49.0, param.parameter("latitude_of_origin").doubleValue(), 1E-8);
+ assertEquals( -2.0, param.parameter("central_meridian" ).doubleValue(), 1E-8);
+ assertEquals( 0.9996, param.parameter("scale_factor" ).doubleValue(), 1E-5);
+ assertEquals( 400000.0, param.parameter("false_easting" ).doubleValue(), 1E-4);
+ assertEquals( -100000.0, param.parameter("false_northing" ).doubleValue(), 1E-4);
final BursaWolfParameters[] bwp = ((DefaultGeodeticDatum) crs.getDatum()).getBursaWolfParameters();
- assertEquals("BursaWolfParameters", 1, bwp.length);
- assertArrayEquals("BursaWolfParameters", new double[] {375, -111, 431}, bwp[0].getValues(), STRICT);
+ assertEquals(1, bwp.length, "BursaWolfParameters");
+ assertArrayEquals(new double[] {375, -111, 431}, bwp[0].getValues(), "BursaWolfParameters");
}
/**
@@ -669,13 +669,13 @@ public final class GeodeticObjectParserTest extends TestCase {
final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
assertEquals("Transverse Mercator", crs.getConversionFromBase().getMethod().getName().getCode());
- assertEquals("semi_major", 6370997.0, param.parameter("semi_major" ).doubleValue(), 1E-5);
- assertEquals("semi_minor", 6370997.0, param.parameter("semi_minor" ).doubleValue(), 1E-5);
- assertEquals("latitude_of_origin", 50.0, param.parameter("latitude_of_origin").doubleValue(), 1E-8);
- assertEquals("central_meridian", 170.0, param.parameter("central_meridian" ).doubleValue(), 1E-8);
- assertEquals("scale_factor", 0.95, param.parameter("scale_factor" ).doubleValue(), 1E-8);
- assertEquals("false_easting", 0.0, param.parameter("false_easting" ).doubleValue(), 1E-8);
- assertEquals("false_northing", 0.0, param.parameter("false_northing" ).doubleValue(), 1E-8);
+ assertEquals(6370997.0, param.parameter("semi_major" ).doubleValue(), 1E-5);
+ assertEquals(6370997.0, param.parameter("semi_minor" ).doubleValue(), 1E-5);
+ assertEquals( 50.0, param.parameter("latitude_of_origin").doubleValue(), 1E-8);
+ assertEquals( 170.0, param.parameter("central_meridian" ).doubleValue(), 1E-8);
+ assertEquals( 0.95, param.parameter("scale_factor" ).doubleValue(), 1E-8);
+ assertEquals( 0.0, param.parameter("false_easting" ).doubleValue(), 1E-8);
+ assertEquals( 0.0, param.parameter("false_northing" ).doubleValue(), 1E-8);
}
/**
@@ -717,11 +717,11 @@ public final class GeodeticObjectParserTest extends TestCase {
assertNameAndIdentifierEqual("NTF (Paris) / Lambert zone II", 0, crs);
verifyProjectedCS(crs.getCoordinateSystem(), Units.KILOMETRE);
final PrimeMeridian pm = verifyNTF(crs.getDatum(), true);
- assertEquals("angularUnit", Units.DEGREE, pm.getAngularUnit());
- assertEquals("greenwichLongitude", 2.33722917, pm.getGreenwichLongitude(), STRICT);
+ assertEquals(Units.DEGREE, pm.getAngularUnit(), "angularUnit");
+ assertEquals(2.33722917, pm.getGreenwichLongitude(), "greenwichLongitude");
final ParameterValue<?> param = verifyNTF(crs.getConversionFromBase().getParameterValues());
- assertEquals("angularUnit", Units.DEGREE, param.getUnit());
- assertEquals("latitude_of_origin", 46.8, param.doubleValue(), STRICT);
+ assertEquals(Units.DEGREE, param.getUnit(), "angularUnit");
+ assertEquals(46.8, param.doubleValue(), "latitude_of_origin");
}
/**
@@ -758,7 +758,7 @@ public final class GeodeticObjectParserTest extends TestCase {
final ProjectedCRS crs = parse(ProjectedCRS.class, wkt);
validateParisFranceII(crs, 27572, false);
- assertNull("Identifier shall not have a version.", getSingleton(crs.getIdentifiers()).getVersion());
+ assertNull(getSingleton(crs.getIdentifiers()).getVersion(), "Identifier shall not have a version.");
}
/**
@@ -768,11 +768,11 @@ public final class GeodeticObjectParserTest extends TestCase {
assertNameAndIdentifierEqual("NTF (Paris) / Lambert zone II", identifier, crs);
verifyProjectedCS(crs.getCoordinateSystem(), Units.KILOMETRE);
final PrimeMeridian pm = verifyNTF(crs.getDatum(), hasToWGS84);
- assertEquals("angularUnit", Units.GRAD, pm.getAngularUnit());
- assertEquals("greenwichLongitude", 2.5969213, pm.getGreenwichLongitude(), STRICT);
+ assertEquals(Units.GRAD, pm.getAngularUnit(), "angularUnit");
+ assertEquals(2.5969213, pm.getGreenwichLongitude(), "greenwichLongitude");
final ParameterValue<?> param = verifyNTF(crs.getConversionFromBase().getParameterValues());
- assertEquals("angularUnit", Units.GRAD, param.getUnit());
- assertEquals("latitude_of_origin", 52.0, param.doubleValue(), STRICT);
+ assertEquals(Units.GRAD, param.getUnit(), "angularUnit");
+ assertEquals(52.0, param.doubleValue(), "latitude_of_origin");
}
/**
@@ -788,15 +788,14 @@ public final class GeodeticObjectParserTest extends TestCase {
assertNameAndIdentifierEqual("Nouvelle Triangulation Française (Paris)", 0, datum);
final BursaWolfParameters[] bwp = ((DefaultGeodeticDatum) datum).getBursaWolfParameters();
- assertEquals("BursaWolfParameters", hasToWGS84 ? 1 : 0, bwp.length);
+ assertEquals(hasToWGS84 ? 1 : 0, bwp.length, "BursaWolfParameters");
if (hasToWGS84) {
- assertArrayEquals("BursaWolfParameters", new double[] {-168, -60, 320}, bwp[0].getValues(), STRICT);
+ assertArrayEquals(new double[] {-168, -60, 320}, bwp[0].getValues(), "BursaWolfParameters");
}
-
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("Clarke 1880 (IGN)", 0, ellipsoid);
- assertEquals("semiMajor", 6378249.2, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 293.4660212936269, ellipsoid.getInverseFlattening(), STRICT);
+ assertEquals(6378249.2, ellipsoid.getSemiMajorAxis(), "semiMajor");
+ assertEquals(293.4660212936269, ellipsoid.getInverseFlattening(), "inverseFlattening");
final PrimeMeridian pm = datum.getPrimeMeridian();
assertNameAndIdentifierEqual("Paris", 8903, pm);
@@ -811,12 +810,12 @@ public final class GeodeticObjectParserTest extends TestCase {
*/
private static ParameterValue<?> verifyNTF(final ParameterValueGroup param) {
assertEquals("Lambert Conic Conformal (1SP)", param.getDescriptor().getName().getCode());
- assertEquals("semi_major", 6378249.2, param.parameter("semi_major" ).doubleValue(Units.METRE), STRICT);
- assertEquals("semi_minor", 6356515.0, param.parameter("semi_minor" ).doubleValue(Units.METRE), 1E-12);
- assertEquals("central_meridian", 0.0, param.parameter("central_meridian").doubleValue(Units.DEGREE), STRICT);
- assertEquals("scale_factor", 0.99987742, param.parameter("scale_factor" ).doubleValue(Units.UNITY), STRICT);
- assertEquals("false_easting", 600000.0, param.parameter("false_easting" ).doubleValue(Units.METRE), STRICT);
- assertEquals("false_northing", 2200000.0, param.parameter("false_northing" ).doubleValue(Units.METRE), STRICT);
+ assertEquals( 6378249.2, param.parameter("semi_major" ).doubleValue(Units.METRE));
+ assertEquals( 6356515.0, param.parameter("semi_minor" ).doubleValue(Units.METRE), 1E-12);
+ assertEquals( 0.0, param.parameter("central_meridian").doubleValue(Units.DEGREE));
+ assertEquals(0.99987742, param.parameter("scale_factor" ).doubleValue(Units.UNITY));
+ assertEquals( 600000.0, param.parameter("false_easting" ).doubleValue(Units.METRE));
+ assertEquals( 2200000.0, param.parameter("false_northing" ).doubleValue(Units.METRE));
return param.parameter("latitude_of_origin");
}
@@ -860,28 +859,29 @@ public final class GeodeticObjectParserTest extends TestCase {
final GeodeticDatum datum = geoCRS.getDatum();
assertNameAndIdentifierEqual("NTF=GR3DF97A", 0, datum);
assertNameAndIdentifierEqual("Greenwich", 0, datum.getPrimeMeridian());
- assertArrayEquals("BursaWolfParameters", new double[] {-168, -60, 320},
- ((DefaultGeodeticDatum) datum).getBursaWolfParameters()[0].getValues(), STRICT);
+ assertArrayEquals(new double[] {-168, -60, 320},
+ assertInstanceOf(DefaultGeodeticDatum.class, datum).getBursaWolfParameters()[0].getValues(),
+ "BursaWolfParameters");
final Ellipsoid ellipsoid = datum.getEllipsoid();
assertNameAndIdentifierEqual("Clarke 1880 (IGN)", 0, ellipsoid);
- assertEquals("semiMajor", 6378249.2, ellipsoid.getSemiMajorAxis(), STRICT);
- assertEquals("inverseFlattening", 293.4660212936269, ellipsoid.getInverseFlattening(), STRICT);
+ assertEquals(6378249.2, ellipsoid.getSemiMajorAxis(),"semiMajor");
+ assertEquals(293.4660212936269, ellipsoid.getInverseFlattening(), "inverseFlattening");
final EllipsoidalCS cs = geoCRS.getCoordinateSystem();
- assertEquals("dimension", 2, cs.getDimension());
+ assertEquals(2, cs.getDimension(), "dimension");
assertLongitudeAxisEquals(cs.getAxis(0));
assertLatitudeAxisEquals (cs.getAxis(1));
final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
assertEquals("Lambert Conic Conformal (1SP)", param.getDescriptor().getName().getCode());
- assertEquals("semi_major", 6378249.2, param.parameter("semi_major" ).doubleValue(Units.METRE), STRICT);
- assertEquals("semi_minor", 6356515.0, param.parameter("semi_minor" ).doubleValue(Units.METRE), 1E-12);
- assertEquals("latitude_of_origin", 44.1, param.parameter("latitude_of_origin").doubleValue(Units.DEGREE), STRICT);
- assertEquals("central_meridian", 2.33722917, param.parameter("central_meridian" ).doubleValue(Units.DEGREE), STRICT);
- assertEquals("scale_factor", 0.999877499, param.parameter("scale_factor" ).doubleValue(Units.UNITY), STRICT);
- assertEquals("false_easting", 600000.0, param.parameter("false_easting" ).doubleValue(Units.METRE), STRICT);
- assertEquals("false_northing", 200000.0, param.parameter("false_northing" ).doubleValue(Units.METRE), STRICT);
+ assertEquals( 6378249.2, param.parameter("semi_major" ).doubleValue(Units.METRE));
+ assertEquals( 6356515.0, param.parameter("semi_minor" ).doubleValue(Units.METRE), 1E-12);
+ assertEquals( 44.1, param.parameter("latitude_of_origin").doubleValue(Units.DEGREE));
+ assertEquals( 2.33722917, param.parameter("central_meridian" ).doubleValue(Units.DEGREE));
+ assertEquals(0.999877499, param.parameter("scale_factor" ).doubleValue(Units.UNITY));
+ assertEquals( 600000.0, param.parameter("false_easting" ).doubleValue(Units.METRE));
+ assertEquals( 200000.0, param.parameter("false_northing" ).doubleValue(Units.METRE));
}
/**
@@ -925,8 +925,7 @@ public final class GeodeticObjectParserTest extends TestCase {
final MathTransform transform = MathTransforms.concatenate(
north.getConversionFromBase().getMathTransform().inverse(),
south.getConversionFromBase().getMathTransform());
- assertInstanceOf("North to South", LinearTransform.class, transform);
- return ((LinearTransform) transform).getMatrix();
+ return assertInstanceOf(LinearTransform.class, transform).getMatrix();
}
/**
@@ -956,10 +955,10 @@ public final class GeodeticObjectParserTest extends TestCase {
assertEquals(AxisDirection.SOUTH, south.getCoordinateSystem().getAxis(1).getDirection());
Matrix matrix = conversion(north, south);
- assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0,0), STRICT);
- assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1,1), STRICT);
- assertEquals("No easting expected.", 0, matrix.getElement(0,2), STRICT);
- assertEquals("No northing expected.", 0, matrix.getElement(1,2), STRICT);
+ assertEquals(+1, matrix.getElement(0,0), "West direction should be unchanged. ");
+ assertEquals(-1, matrix.getElement(1,1), "North-South direction should be reverted.");
+ assertEquals( 0, matrix.getElement(0,2), "No easting expected.");
+ assertEquals( 0, matrix.getElement(1,2), "No northing expected.");
assertDiagonalEquals(new double[] {+1, -1, 1}, true, matrix, STRICT);
/*
* Test "Transverse Mercator South Orientated". In this projection, the "False Northing" parameter
@@ -973,10 +972,10 @@ public final class GeodeticObjectParserTest extends TestCase {
assertEquals(AxisDirection.WEST, south.getCoordinateSystem().getAxis(0).getDirection());
assertEquals(AxisDirection.SOUTH, south.getCoordinateSystem().getAxis(1).getDirection());
matrix = conversion(north, south);
- assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0,0), STRICT);
- assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1,1), STRICT);
- assertEquals("No easting expected.", 0, matrix.getElement(0,2), STRICT);
- assertEquals("Northing expected.", 2000, matrix.getElement(1,2), STRICT);
+ assertEquals( +1, matrix.getElement(0,0), "West direction should be unchanged.");
+ assertEquals( -1, matrix.getElement(1,1), "North-South direction should be reverted.");
+ assertEquals( 0, matrix.getElement(0,2), "No easting expected.");
+ assertEquals(2000, matrix.getElement(1,2), "Northing expected.");
}
/**
@@ -1008,8 +1007,8 @@ public final class GeodeticObjectParserTest extends TestCase {
assertNameAndIdentifierEqual("EPSG topocentric example B", 5820, crs);
assertNameAndIdentifierEqual("EPSG topocentric example B", 0, crs.getConversionFromBase());
CoordinateSystem cs = crs.getCoordinateSystem();
- assertInstanceOf("coordinateSystem", CartesianCS.class, cs);
- assertEquals("dimension", 3, cs.getDimension());
+ assertInstanceOf(CartesianCS.class, cs, "coordinateSystem");
+ assertEquals(3, cs.getDimension(), "dimension");
assertUnboundedAxisEquals("Topocentric East", "U", AxisDirection.EAST, Units.METRE, cs.getAxis(0));
assertUnboundedAxisEquals("Topocentric North", "V", AxisDirection.NORTH, Units.METRE, cs.getAxis(1));
assertUnboundedAxisEquals("Topocentric height", "W", AxisDirection.UP, Units.METRE, cs.getAxis(2));
@@ -1019,8 +1018,8 @@ public final class GeodeticObjectParserTest extends TestCase {
* that the expected type for “Geocentric/topocentric conversions” is Cartesian.
*/
cs = crs.getBaseCRS().getCoordinateSystem();
- assertInstanceOf("coordinateSystem", CartesianCS.class, cs);
- assertEquals("dimension", 3, cs.getDimension());
+ assertInstanceOf(CartesianCS.class, cs, "coordinateSystem");
+ assertEquals(3, cs.getDimension(), "dimension");
assertUnboundedAxisEquals(AxisNames.GEOCENTRIC_X, "X", AxisDirection.GEOCENTRIC_X, Units.METRE, cs.getAxis(0));
assertUnboundedAxisEquals(AxisNames.GEOCENTRIC_Y, "Y", AxisDirection.GEOCENTRIC_Y, Units.METRE, cs.getAxis(1));
assertUnboundedAxisEquals(AxisNames.GEOCENTRIC_Z, "Z", AxisDirection.GEOCENTRIC_Z, Units.METRE, cs.getAxis(2));
@@ -1045,8 +1044,8 @@ public final class GeodeticObjectParserTest extends TestCase {
assertNameAndIdentifierEqual("A building-centred CRS", 0, crs);
assertNameAndIdentifierEqual("Building reference point", 0, crs.getDatum());
final CoordinateSystem cs = crs.getCoordinateSystem();
- assertInstanceOf("coordinateSystem", CartesianCS.class, cs);
- assertEquals("dimension", 3, cs.getDimension());
+ assertInstanceOf(CartesianCS.class, cs, "coordinateSystem");
+ assertEquals(3, cs.getDimension(), "dimension");
// Axis names are arbitrary and could change in future SIS versions.
assertUnboundedAxisEquals("Easting", "x", AxisDirection.EAST, Units.METRE, cs.getAxis(0));
@@ -1097,14 +1096,14 @@ public final class GeodeticObjectParserTest extends TestCase {
final TemporalDatum timeDatum = timeCRS.getDatum();
assertNameAndIdentifierEqual("Time", 0, timeCRS);
assertNameAndIdentifierEqual("Modified Julian", 0, timeDatum);
- assertEquals("epoch", new Date(-40587L * MILLISECONDS_PER_DAY), timeDatum.getOrigin());
+ assertEquals(new Date(-40587L * MILLISECONDS_PER_DAY), timeDatum.getOrigin(), "epoch");
// No more CRS.
assertFalse(components.hasNext());
// Axes: we verify only the CompoundCRS ones, which should include all others.
final CoordinateSystem cs = crs.getCoordinateSystem();
- assertEquals("dimension", 4, cs.getDimension());
+ assertEquals(4, cs.getDimension(), "dimension");
assertLongitudeAxisEquals(cs.getAxis(0));
assertLatitudeAxisEquals (cs.getAxis(1));
assertUnboundedAxisEquals("Gravity-related height", "H", AxisDirection.UP, Units.METRE, cs.getAxis(2));
@@ -1137,7 +1136,7 @@ public final class GeodeticObjectParserTest extends TestCase {
" AXIS[“Ellipsoidal height”, UP]]]");
final CoordinateSystem cs = crs.getCoordinateSystem();
- assertEquals("dimension", 3, cs.getDimension());
+ assertEquals(3, cs.getDimension(), "dimension");
assertLongitudeAxisEquals(cs.getAxis(0));
assertLatitudeAxisEquals (cs.getAxis(1));
assertUnboundedAxisEquals("Ellipsoidal height", "h", AxisDirection.UP, Units.METRE, cs.getAxis(2));
@@ -1185,18 +1184,15 @@ public final class GeodeticObjectParserTest extends TestCase {
*/
@Test
public void testIncompatibleUnits() {
- try {
- parse(GeographicCRS.class,
+ ParseException exception;
+ exception = assertThrows(ParseException.class, () -> parse(GeographicCRS.class,
"GEOGCS[“NAD83”,\n" +
" DATUM[“North American Datum 1983”,\n" +
" SPHEROID[“GRS 1980”, 6378137.0, 298.257222]],\n" +
" PRIMEM[“Greenwich”, 0],\n" +
- " UNIT[“kilometre”, 1000]]"); // Wrong unit
- fail("Should not have parsed a CRS with wrong unit of measurement.");
- } catch (ParseException e) {
- final String message = e.getMessage();
- assertTrue(message, message.contains("km"));
- }
+ " UNIT[“kilometre”, 1000]]")); // Wrong unit);
+
+ assertMessageContains(exception, "km");
}
/**
@@ -1216,29 +1212,13 @@ public final class GeodeticObjectParserTest extends TestCase {
verifyGeographicCRS(0, crs);
final Warnings warnings = parser.getAndClearWarnings(crs);
- assertNotNull("warnings", warnings);
-
- assertTrue("warnings.getExceptions()",
- warnings.getExceptions().isEmpty());
-
- assertEquals("warnings.getRootElement()", "WGS 84",
- warnings.getRootElement());
-
- assertArrayEquals("warnings.getUnknownElements()",
- new String[] {"Intruder", "Ext1", "Ext2"},
- warnings.getUnknownElements().toArray());
-
- assertArrayEquals("warnings.getUnknownElementLocations(…)",
- new String[] {"PRIMEM", "GEOGCS"},
- warnings.getUnknownElementLocations("Intruder").toArray());
-
- assertArrayEquals("warnings.getUnknownElementLocations(…)",
- new String[] {"SPHEROID"},
- warnings.getUnknownElementLocations("Ext1").toArray());
-
- assertArrayEquals("warnings.getUnknownElementLocations(…)",
- new String[] {"SPHEROID"},
- warnings.getUnknownElementLocations("Ext2").toArray());
+ assertNotNull(warnings, "warnings");
+ assertTrue(warnings.getExceptions().isEmpty());
+ assertEquals("WGS 84", warnings.getRootElement());
+ assertArrayEquals(new String[] {"Intruder", "Ext1", "Ext2"}, warnings.getUnknownElements().toArray());
+ assertArrayEquals(new String[] {"PRIMEM", "GEOGCS"}, warnings.getUnknownElementLocations("Intruder").toArray());
+ assertArrayEquals(new String[] {"SPHEROID"}, warnings.getUnknownElementLocations("Ext1").toArray());
+ assertArrayEquals(new String[] {"SPHEROID"}, warnings.getUnknownElementLocations("Ext2").toArray());
assertMultilinesEquals("Parsing of “WGS 84” done, but some elements were ignored.\n" +
" • Unexpected scale factor 0.01746 for unit of measurement “°”.\n" +
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/MathTransformParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/MathTransformParserTest.java
index 7f0edffa39..21771d64e6 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/MathTransformParserTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/MathTransformParserTest.java
@@ -27,7 +27,7 @@ import org.apache.sis.measure.Units;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
@@ -63,13 +63,13 @@ public final class MathTransformParserTest extends TestCase {
*/
@Test
public void testCompleteUnitFactor() {
- assertEquals(0.017453292519943295, MathTransformParser.completeUnitFactor(Units.RADIAN, 0.01745329252), STRICT); // SIS-377
- assertEquals(0.01745329252, MathTransformParser.completeUnitFactor(Units.METRE, 0.01745329252), STRICT); // Not the right kind of units.
- assertEquals(0.3048, MathTransformParser.completeUnitFactor(Units.METRE, 0.3048), STRICT); // Check there is no confusion with US survey foot.
- assertEquals(0.30480060960121924, MathTransformParser.completeUnitFactor(Units.METRE, 0.3048006096), STRICT); // US survey foot.
- assertEquals(0.3048007491, MathTransformParser.completeUnitFactor(Units.METRE, 0.3048007491), STRICT); // British foot (1936).
- assertEquals(0.30479841, MathTransformParser.completeUnitFactor(Units.METRE, 0.30479841), STRICT); // Indian foot (1937).
- assertEquals(0.3047, MathTransformParser.completeUnitFactor(Units.METRE, 0.3047), STRICT);
+ assertEquals(0.017453292519943295, MathTransformParser.completeUnitFactor(Units.RADIAN, 0.01745329252)); // SIS-377
+ assertEquals(0.01745329252, MathTransformParser.completeUnitFactor(Units.METRE, 0.01745329252)); // Not the right kind of units.
+ assertEquals(0.3048, MathTransformParser.completeUnitFactor(Units.METRE, 0.3048)); // Check there is no confusion with US survey foot.
+ assertEquals(0.30480060960121924, MathTransformParser.completeUnitFactor(Units.METRE, 0.3048006096)); // US survey foot.
+ assertEquals(0.3048007491, MathTransformParser.completeUnitFactor(Units.METRE, 0.3048007491)); // British foot (1936).
+ assertEquals(0.30479841, MathTransformParser.completeUnitFactor(Units.METRE, 0.30479841)); // Indian foot (1937).
+ assertEquals(0.3047, MathTransformParser.completeUnitFactor(Units.METRE, 0.3047));
}
/**
@@ -84,8 +84,8 @@ public final class MathTransformParserTest extends TestCase {
}
final ParsePosition position = new ParsePosition(0);
final MathTransform mt = (MathTransform) parser.createFromWKT(text, position);
- assertEquals("errorIndex", -1, position.getErrorIndex());
- assertEquals("index", text.length(), position.getIndex());
+ assertEquals(-1, position.getErrorIndex(), "errorIndex");
+ assertEquals(text.length(), position.getIndex(), "index");
return mt;
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/SymbolsTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/SymbolsTest.java
index 641aac34df..70b94d4a2b 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/SymbolsTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/SymbolsTest.java
@@ -21,8 +21,9 @@ import org.apache.sis.util.StringBuilders;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.Assertions.assertSerializedEquals;
@@ -58,12 +59,12 @@ public final class SymbolsTest extends TestCase {
* the standard {@code '"'} quotation mark after we tested the given string.
*/
private static void assertContainsAxis(final String message, final boolean expected, final String wkt) {
- assertEquals(message, expected, Symbols.getDefault().containsElement(wkt, "AXIS"));
+ assertEquals(expected, Symbols.getDefault().containsElement(wkt, "AXIS"), message);
final StringBuilder buffer = new StringBuilder(wkt);
StringBuilders.replace(buffer, '“', '"');
StringBuilders.replace(buffer, '”', '"');
assertFalse(wkt.contentEquals(buffer));
- assertEquals(message, expected, Symbols.getDefault().containsElement(buffer, "AXIS"));
+ assertEquals(expected, Symbols.getDefault().containsElement(buffer, "AXIS"), message);
}
/**
@@ -71,22 +72,14 @@ public final class SymbolsTest extends TestCase {
*/
@Test
public void testImmutability() {
- try {
- Symbols.SQUARE_BRACKETS.setPairedBrackets("()", "[]");
- fail("Constant shall be immutable.");
- } catch (UnsupportedOperationException e) {
- // This is the expected exception.
- final String message = e.getMessage();
- assertTrue(message, message.contains("Symbols"));
- }
- try {
- Symbols.CURLY_BRACKETS.setLocale(Locale.FRENCH);
- fail("Constant shall be immutable.");
- } catch (UnsupportedOperationException e) {
- // This is the expected exception.
- final String message = e.getMessage();
- assertTrue(message, message.contains("Symbols"));
- }
+ UnsupportedOperationException exception;
+ exception = assertThrows(UnsupportedOperationException.class,
+ () -> Symbols.SQUARE_BRACKETS.setPairedBrackets("()", "[]"), "Constant shall be immutable.");
+ assertMessageContains(exception, "Symbols");
+
+ exception = assertThrows(UnsupportedOperationException.class,
+ () -> Symbols.CURLY_BRACKETS.setLocale(Locale.FRENCH), "Constant shall be immutable.");
+ assertMessageContains(exception, "Symbols");
}
/**
@@ -101,11 +94,11 @@ public final class SymbolsTest extends TestCase {
* This is necessary in order to ensure that the symbol is recomputed correctly.
*/
final Symbols symbols = new Symbols(Symbols.CURLY_BRACKETS);
- assertEquals("quote", "\"", symbols.getQuote());
+ assertEquals("\"", symbols.getQuote(), "quote");
symbols.setPairedQuotes("“”", "\"\"");
- assertEquals("quote", "”", symbols.getQuote());
+ assertEquals("”", symbols.getQuote(), "quote");
final Symbols c = assertSerializedEquals(symbols);
- assertNotSame("Expected a new instance.", symbols, c);
- assertEquals("quote", "”", c.getQuote()); // Verify the recomputed value.
+ assertNotSame(symbols, c, "Expected a new instance.");
+ assertEquals("”", c.getQuote(), "quote"); // Verify the recomputed value.
}
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/TransliteratorTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/TransliteratorTest.java
index f73c72b2e2..5b1d4c8775 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/TransliteratorTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/TransliteratorTest.java
@@ -24,7 +24,7 @@ import org.apache.sis.metadata.internal.AxisNames;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestCase;
import org.apache.sis.test.mock.CoordinateSystemAxisMock;
@@ -100,12 +100,12 @@ public final class TransliteratorTest extends TestCase {
@Test
public void testToUnicodeAbbreviation() {
final Transliterator t = Transliterator.DEFAULT;
- assertEquals("P", "φ", t.toUnicodeAbbreviation("ellipsoidal", AxisDirection.NORTH, "P"));
- assertEquals("B", "φ", t.toUnicodeAbbreviation("ellipsoidal", AxisDirection.NORTH, "B"));
- assertEquals("L", "λ", t.toUnicodeAbbreviation("ellipsoidal", AxisDirection.EAST, "L"));
- assertEquals("U", "θ", t.toUnicodeAbbreviation("polar", AxisDirection.OTHER, "U"));
- assertEquals("U", "Ω", t.toUnicodeAbbreviation("spherical", AxisDirection.NORTH, "U"));
- assertEquals("V", "θ", t.toUnicodeAbbreviation("spherical", AxisDirection.EAST, "V"));
+ assertEquals("φ", t.toUnicodeAbbreviation("ellipsoidal", AxisDirection.NORTH, "P"), "P");
+ assertEquals("φ", t.toUnicodeAbbreviation("ellipsoidal", AxisDirection.NORTH, "B"), "B");
+ assertEquals("λ", t.toUnicodeAbbreviation("ellipsoidal", AxisDirection.EAST, "L"), "L");
+ assertEquals("θ", t.toUnicodeAbbreviation("polar", AxisDirection.OTHER, "U"), "U");
+ assertEquals("Ω", t.toUnicodeAbbreviation("spherical", AxisDirection.NORTH, "U"), "U");
+ assertEquals("θ", t.toUnicodeAbbreviation("spherical", AxisDirection.EAST, "V"), "V");
}
/**
@@ -124,8 +124,7 @@ public final class TransliteratorTest extends TestCase {
* is equal to the expected string.
*/
private static void assertShortAxisNameEquals(final String expected, final CoordinateSystemAxisMock axis) {
- assertEquals("name", expected, Transliterator.DEFAULT.toShortAxisName(axis,
- axis.getDirection(), axis.getName().getCode()));
+ assertEquals(expected, Transliterator.DEFAULT.toShortAxisName(axis, axis.getDirection(), axis.getName().getCode()));
}
/**
@@ -133,8 +132,7 @@ public final class TransliteratorTest extends TestCase {
* is equal to the expected string.
*/
private static void assertAbbreviationEquals(final String expected, final CoordinateSystemAxisMock axis) {
- assertEquals("abbreviation", expected, Transliterator.DEFAULT.toLatinAbbreviation(axis,
- axis.getDirection(), axis.getAbbreviation()));
+ assertEquals(expected, Transliterator.DEFAULT.toLatinAbbreviation(axis, axis.getDirection(), axis.getAbbreviation()));
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java
index 37245b10c6..3825c1730e 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java
@@ -39,11 +39,12 @@ import org.apache.sis.metadata.iso.DefaultIdentifier;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestUtilities;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import static org.apache.sis.test.Assertions.assertSetEquals;
+import static org.apache.sis.test.Assertions.assertMessageContains;
// Specific to the geoapi-3.1 and geoapi-4.0 branches:
import org.opengis.metadata.Identifier;
@@ -91,8 +92,8 @@ public final class WKTDictionaryTest extends TestCase {
/*
* Codes can be in any order. Code spaces are omitted when there is no ambiguity.
*/
- assertArrayEquals("getCodeSpaces()", new String[] {"TEST"}, factory.getCodeSpaces().toArray());
- assertEquals("getAuthority()", "TEST", factory.getAuthority().getTitle().toString());
+ assertArrayEquals(new String[] {"TEST"}, factory.getCodeSpaces().toArray(), "getCodeSpaces()");
+ assertEquals("TEST", factory.getAuthority().getTitle().toString(), "getAuthority()");
Set<String> codes = factory.getAuthorityCodes(IdentifiedObject.class);
assertSame( codes, factory.getAuthorityCodes(SingleCRS.class));
assertSame( codes, factory.getAuthorityCodes(GeodeticCRS.class));
@@ -107,13 +108,9 @@ public final class WKTDictionaryTest extends TestCase {
/*
* Test non-existing CRS.
*/
- try {
- factory.createGeographicCRS("84");
- fail("Expected exception for non-existent CRS.");
- } catch (NoSuchAuthorityCodeException e) {
- final String message = e.getMessage();
- assertTrue(message, message.contains("84"));
- }
+ NoSuchAuthorityCodeException exception;
+ exception = assertThrows(NoSuchAuthorityCodeException.class, () -> factory.createGeographicCRS("84"));
+ assertMessageContains(exception, "84");
}
/**
@@ -141,8 +138,8 @@ public final class WKTDictionaryTest extends TestCase {
* in the test file. The authority should be "TEST" for the same reason.
* Codes can be in any order. Code spaces are omitted when there is no ambiguity.
*/
- assertArrayEquals("getCodeSpaces()", new String[] {"TEST", "ESRI"}, factory.getCodeSpaces().toArray());
- assertEquals("getAuthority()", "TEST", factory.getAuthority().getTitle().toString());
+ assertArrayEquals(new String[] {"TEST", "ESRI"}, factory.getCodeSpaces().toArray(), "getCodeSpaces()");
+ assertEquals("TEST", factory.getAuthority().getTitle().toString(), "getAuthority()");
Set<String> codes = factory.getAuthorityCodes(IdentifiedObject.class);
assertSame( codes, factory.getAuthorityCodes(IdentifiedObject.class)); // Test caching.
assertSame( codes, factory.getAuthorityCodes(SingleCRS.class)); // Test sharing.
@@ -197,8 +194,8 @@ public final class WKTDictionaryTest extends TestCase {
*/
final void verify(final WKTDictionary factory) {
factory.forEachValue(this);
- assertEquals("Some values are equal but distinct instances. A single instance should be shared.",
- new HashSet<>(counts.keySet()).size(), counts.size());
+ assertEquals(new HashSet<>(counts.keySet()).size(), counts.size(),
+ "Some values are equal but distinct instances. A single instance should be shared.");
/*
* Verify the number of occurrences of a few values. Note that the same string representation of keys
* value may appear twice: once because the value was already a `String`, and once because the value
@@ -224,7 +221,7 @@ public final class WKTDictionaryTest extends TestCase {
}
default: continue;
}
- assertEquals(key, expected, entry.getValue().intValue());
+ assertEquals(expected, entry.getValue().intValue(), key);
}
}
@@ -253,11 +250,11 @@ public final class WKTDictionaryTest extends TestCase {
* @param φ0 expected latitude of origin.
*/
private static void verifyCRS(final ProjectedCRS crs, final String name, final double φ0) {
- assertEquals("name", name, crs.getName().getCode());
+ assertEquals(name, crs.getName().getCode(), "name");
assertAxisDirectionsEqual(name, crs.getCoordinateSystem(),
AxisDirection.EAST, AxisDirection.NORTH);
- assertEquals("φ0", φ0, crs.getConversionFromBase().getParameterValues()
- .parameter("Latitude of natural origin").doubleValue(), STRICT);
+ assertEquals(φ0, crs.getConversionFromBase().getParameterValues()
+ .parameter("Latitude of natural origin").doubleValue(), "φ0");
}
/**
@@ -267,7 +264,7 @@ public final class WKTDictionaryTest extends TestCase {
* @param name expected CRS name.
*/
private static void verifyCRS(final GeographicCRS crs, final String name) {
- assertEquals("name", name, crs.getName().getCode());
+ assertEquals(name, crs.getName().getCode(), "name");
assertAxisDirectionsEqual(name, crs.getCoordinateSystem(),
AxisDirection.NORTH, AxisDirection.EAST);
}
@@ -280,41 +277,31 @@ public final class WKTDictionaryTest extends TestCase {
* @param errorOffset expected error index.
*/
private static void verifyErroneousCRS(final WKTDictionary factory, final String code, final int errorOffset) {
- String details = null;
- try {
- factory.createGeographicCRS(code);
- fail("Parsing should have failed.");
- } catch (FactoryException e) {
- /*
- * Expect a message like: Cannot create a geodetic object for "E1".
- * The exact message is locale-dependent, so we cannot test fully.
- */
- final String message = e.getMessage();
- assertTrue(message, message.contains(code));
- /*
- * Expect a message like: Missing "semiMajorAxis" component in "Ellipsoid" element.
- * The error offset (zero-based) should point to the character after "Ellipsoid" in
- * the following WKT:
- *
- * Datum["Erroneous", Ellipsoid["Missing axis length"]]
- */
- final UnparsableObjectException cause = (UnparsableObjectException) e.getCause();
- details = cause.getMessage();
- assertTrue(message, details.contains("Ellipsoid"));
- assertTrue(message, details.contains("semiMajorAxis"));
- assertEquals("errorOffset", errorOffset, cause.getErrorOffset());
- }
+ FactoryException exception;
+ exception = assertThrows(FactoryException.class, () -> factory.createGeographicCRS(code));
+ /*
+ * Expect a message like: Cannot create a geodetic object for "E1".
+ * The exact message is locale-dependent, so we cannot test fully.
+ */
+ assertMessageContains(exception, code);
+ /*
+ * Expect a message like: Missing "semiMajorAxis" component in "Ellipsoid" element.
+ * The error offset (zero-based) should point to the character after "Ellipsoid" in
+ * the following WKT:
+ *
+ * Datum["Erroneous", Ellipsoid["Missing axis length"]]
+ */
+ final UnparsableObjectException cause = assertInstanceOf(UnparsableObjectException.class, exception.getCause());
+ assertMessageContains(cause, "Ellipsoid", "semiMajorAxis");
+ assertEquals(errorOffset, cause.getErrorOffset(), "errorOffset");
/*
* Try parsing again. The exception message should have been saved,
* i.e. the parsing process is not repeated.
*/
- try {
- factory.createGeographicCRS(code);
- fail("Parsing should have failed.");
- } catch (FactoryException e) {
- assertEquals(details, e.getMessage());
- assertNull(e.getCause());
- }
+ final String details = cause.getMessage();
+ exception = assertThrows(FactoryException.class, () -> factory.createGeographicCRS(code));
+ assertEquals(details, exception.getMessage());
+ assertNull(exception.getCause());
}
/**
@@ -324,24 +311,18 @@ public final class WKTDictionaryTest extends TestCase {
*/
@Test
public void testLoadMalformed() throws IOException {
- FactoryException ex;
+ FactoryException exception;
final WKTDictionary factory = new WKTDictionary(null);
try (BufferedReader source = new BufferedReader(new InputStreamReader(
WKTFormatTest.class.getResourceAsStream("Malformed.txt"), "UTF-8")))
{
- factory.load(source);
- fail("Should not have accepted to load the file.");
- return;
- } catch (FactoryException e) {
- ex = e;
+ exception = assertThrows(FactoryException.class, () -> factory.load(source));
}
/*
* Except a message like: Cannot read file at line 13. Cause is: missing ']' in "GeodCRS" element.
* The exact message is locale-dependent, so we test for a few keywords only.
*/
- final String message = ex.getMessage();
- assertTrue(message, message.contains("GeodCRS"));
- assertTrue(message, message.contains("‘]’"));
+ assertMessageContains(exception, "GeodCRS", "‘]’");
}
/**
@@ -398,12 +379,8 @@ public final class WKTDictionaryTest extends TestCase {
/*
* Test non-existent code.
*/
- try {
- factory.createGeographicCRS("21");
- fail("Parsing should have failed.");
- } catch (FactoryException e) {
- final String message = e.getMessage();
- assertTrue(message, message.contains("21"));
- }
+ FactoryException exception;
+ exception = assertThrows(FactoryException.class, () -> factory.createGeographicCRS("21"));
+ assertMessageContains(exception, "21");
}
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java
index a77a18382c..b4c3eff19c 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java
@@ -16,22 +16,29 @@
*/
package org.apache.sis.io.wkt;
+import java.net.URI;
import java.util.Map;
import java.util.Locale;
import java.text.ParseException;
+import org.opengis.parameter.ParameterValue;
import org.opengis.referencing.crs.VerticalCRS;
+import org.opengis.referencing.operation.MathTransformFactory;
import org.apache.sis.measure.Units;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.referencing.crs.DefaultProjectedCRS;
import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
+import org.apache.sis.parameter.DefaultParameterValue;
+import org.apache.sis.parameter.Parameterized;
+import org.apache.sis.referencing.operation.transform.MathTransformFactoryMock;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.Assertions.assertMultilinesEquals;
@@ -426,32 +433,28 @@ public final class WKTFormatTest extends TestCase {
*/
@Test
public void testWarnings() throws ParseException {
- DefaultPrimeMeridian pm = new DefaultPrimeMeridian(
+ final var pm = new DefaultPrimeMeridian(
Map.of(DefaultPrimeMeridian.NAME_KEY, "Invalid “$name” here"),
-10, Units.DEGREE);
format = new WKTFormat(Locale.US, null);
final String wkt = format.format(pm);
final Warnings warnings = format.getWarnings();
- assertNotNull("warnings", warnings);
- assertEquals ("warnings.numMessages", 1, warnings.getNumMessages());
+ assertNotNull(warnings, "warnings");
+ assertEquals (1, warnings.getNumMessages(), "warnings.numMessages");
assertEquals ("PRIMEM[\"Invalid \"\"$name\"\" here\", -10.0, ANGLEUNIT[\"degree\", 0.017453292519943295]]", wkt);
assertEquals ("The “$” character in “\"$name\"” is not permitted by the “Well-Known Text” format.", warnings.getMessage(0));
assertNull (warnings.getException(0));
/*
* Verify that FormattableObject.toWKT() reports that the WKT is invalid.
*/
- try {
- pm.toWKT();
- fail("Expected UnformattableObjectException.");
- } catch (UnformattableObjectException e) {
- final String message = e.getMessage();
- assertTrue(message, message.contains("$name"));
- }
+ UnformattableObjectException e;
+ e = assertThrows(UnformattableObjectException.class, () -> pm.toWKT());
+ assertMessageContains(e, "$name");
/*
* Verify that the WKT is still parseable despite the warning.
*/
- pm = (DefaultPrimeMeridian) format.parseObject(wkt);
- assertEquals("Invalid \"$name\" here", pm.getName().getCode());
+ final var parsed = (DefaultPrimeMeridian) format.parseObject(wkt);
+ assertEquals("Invalid \"$name\" here", parsed.getName().getCode());
}
/**
@@ -479,4 +482,35 @@ public final class WKTFormatTest extends TestCase {
" AXIS[\"Longitude (L)\", east, ORDER[2]],\n" +
" ANGLEUNIT[\"degree\", 0.017453292519943295]]", wkt);
}
+
+ /**
+ * Tests parsing of a WKT when a source file specified.
+ * The source file should be present in {@link DefaultParameterValue#getSourceFile()}.
+ *
+ * @throws ParseException if the parsing failed.
+ * @throws Exception if another error occurred during test initialization.
+ */
+ @Test
+ public void testSourceFile() throws Exception {
+ final var source = new URI("test/wkt.prj");
+ final var factory = new MathTransformFactoryMock("Mercator");
+ format = new WKTFormat(null, null);
+ format.setSourceFile(source);
+ format.setFactory(MathTransformFactory.class, factory);
+ final Parameterized mt = assertInstanceOf(Parameterized.class, format.parseObject(
+ "PARAM_MT[“Mercator”,\n"
+ + "PARAMETER[“semi_major”, 1],\n"
+ + "PARAMETER[“semi_minor”, 1]]"));
+ /*
+ * Source file is not relevant to numerical parameter value. But we do not use a more
+ * relevant file parameter such as NADCON longitude/latitude files, because we do not
+ * want the operation to try to really open the file.
+ */
+ ParameterValue<?> p = factory.lastParameters.parameter("semi_major");
+ assertEquals(source, assertInstanceOf(DefaultParameterValue.class, p).getSourceFile().get());
+
+ // The information is lost in the final parameter value, because not relevant.
+ p = mt.getParameterValues().parameter("semi_major");
+ assertTrue(assertInstanceOf(DefaultParameterValue.class, p).getSourceFile().isEmpty());
+ }
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTParserTest.java
index 7765a29a61..6971a68ec8 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTParserTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTParserTest.java
@@ -25,7 +25,7 @@ import org.apache.sis.metadata.internal.AxisNames;
import org.apache.sis.referencing.factory.GeodeticObjectFactory;
import org.junit.Test;
import org.junit.Ignore;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.opengis.test.wkt.CRSParserTest;
import org.apache.sis.test.DependsOn;
@@ -76,15 +76,15 @@ public final class WKTParserTest extends CRSParserTest {
private void verifyEllipsoidalCS() {
final CoordinateSystem cs = object.getCoordinateSystem();
switch (cs.getDimension()) {
- default: assertEquals("name", AxisNames.ELLIPSOIDAL_HEIGHT, cs.getAxis(2).getName().getCode());
- case 2: assertEquals("name", AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode());
- case 1: assertEquals("name", AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode());
+ default: assertEquals(AxisNames.ELLIPSOIDAL_HEIGHT, cs.getAxis(2).getName().getCode(), "name");
+ case 2: assertEquals(AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode(), "name");
+ case 1: assertEquals(AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode(), "name");
case 0: break;
}
switch (cs.getDimension()) {
- default: assertEquals("abbreviation", "h", cs.getAxis(2).getAbbreviation());
- case 2: assertEquals("abbreviation", "λ", cs.getAxis(1).getAbbreviation());
- case 1: assertEquals("abbreviation", "φ", cs.getAxis(0).getAbbreviation());
+ default: assertEquals("h", cs.getAxis(2).getAbbreviation(), "abbreviation");
+ case 2: assertEquals("λ", cs.getAxis(1).getAbbreviation(), "abbreviation");
+ case 1: assertEquals("φ", cs.getAxis(0).getAbbreviation(), "abbreviation");
case 0: break;
}
}
@@ -224,9 +224,9 @@ public final class WKTParserTest extends CRSParserTest {
public void testGeocentric() throws FactoryException {
super.testGeocentric();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.GEOCENTRIC_X, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.GEOCENTRIC_Y, cs.getAxis(1).getName().getCode());
- assertEquals("name", AxisNames.GEOCENTRIC_Z, cs.getAxis(2).getName().getCode());
+ assertEquals(AxisNames.GEOCENTRIC_X, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.GEOCENTRIC_Y, cs.getAxis(1).getName().getCode(), "name");
+ assertEquals(AxisNames.GEOCENTRIC_Z, cs.getAxis(2).getName().getCode(), "name");
useStraightQuotes = true;
super.testGeocentric(); // Test again with “ and ” replaced by ".
@@ -281,8 +281,8 @@ public final class WKTParserTest extends CRSParserTest {
public void testProjectedWithFootUnits() throws FactoryException {
super.testProjectedWithFootUnits();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.EASTING, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.NORTHING, cs.getAxis(1).getName().getCode());
+ assertEquals(AxisNames.EASTING, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.NORTHING, cs.getAxis(1).getName().getCode(), "name");
useStraightQuotes = true;
super.testProjectedWithFootUnits(); // Test again with “ and ” replaced by ".
@@ -320,8 +320,8 @@ public final class WKTParserTest extends CRSParserTest {
public void testProjectedWithImplicitParameterUnits() throws FactoryException {
super.testProjectedWithImplicitParameterUnits();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.EASTING, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.NORTHING, cs.getAxis(1).getName().getCode());
+ assertEquals(AxisNames.EASTING, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.NORTHING, cs.getAxis(1).getName().getCode(), "name");
useStraightQuotes = true;
super.testProjectedWithImplicitParameterUnits(); // Test again with “ and ” replaced by ".
@@ -345,8 +345,8 @@ public final class WKTParserTest extends CRSParserTest {
public void testVertical() throws FactoryException {
super.testVertical();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.GRAVITY_RELATED_HEIGHT, cs.getAxis(0).getName().getCode());
- assertEquals("datumType", VerticalDatumType.GEOIDAL, ((VerticalCRS) object).getDatum().getVerticalDatumType());
+ assertEquals(AxisNames.GRAVITY_RELATED_HEIGHT, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(VerticalDatumType.GEOIDAL, ((VerticalCRS) object).getDatum().getVerticalDatumType(), "datumType");
useStraightQuotes = true;
super.testVertical(); // Test again with “ and ” replaced by ".
@@ -369,7 +369,7 @@ public final class WKTParserTest extends CRSParserTest {
public void testTemporal() throws FactoryException {
super.testTemporal();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.TIME, cs.getAxis(0).getName().getCode());
+ assertEquals(AxisNames.TIME, cs.getAxis(0).getName().getCode(), "name");
useStraightQuotes = true;
super.testTemporal(); // Test again with “ and ” replaced by ".
@@ -394,7 +394,7 @@ public final class WKTParserTest extends CRSParserTest {
public void testParametric() throws FactoryException {
super.testParametric();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", "pressure", cs.getAxis(0).getName().getCode());
+ assertEquals("pressure", cs.getAxis(0).getName().getCode(), "name");
useStraightQuotes = true;
super.testParametric(); // Test again with “ and ” replaced by ".
@@ -421,8 +421,8 @@ public final class WKTParserTest extends CRSParserTest {
public void testEngineering() throws FactoryException {
super.testEngineering();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.NORTHING, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.WESTING, cs.getAxis(1).getName().getCode());
+ assertEquals(AxisNames.NORTHING, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.WESTING, cs.getAxis(1).getName().getCode(), "name");
useStraightQuotes = true;
super.testEngineering(); // Test again with “ and ” replaced by ".
@@ -449,8 +449,8 @@ public final class WKTParserTest extends CRSParserTest {
public void testEngineeringRotated() throws FactoryException {
super.testEngineeringRotated();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", "site east", cs.getAxis(0).getName().getCode());
- assertEquals("name", "site north", cs.getAxis(1).getName().getCode());
+ assertEquals("site east", cs.getAxis(0).getName().getCode(), "name");
+ assertEquals("site north", cs.getAxis(1).getName().getCode(), "name");
useStraightQuotes = true;
super.testEngineeringRotated(); // Test again with “ and ” replaced by ".
@@ -482,9 +482,9 @@ public final class WKTParserTest extends CRSParserTest {
* In this case we had no axis names, so Apache SIS reused the abbreviations.
* This could change in any future SIS version if we update Transliterator.
*/
- assertEquals("name", "x", cs.getAxis(0).getName().getCode());
- assertEquals("name", "y", cs.getAxis(1).getName().getCode());
- assertEquals("name", "z", cs.getAxis(2).getName().getCode());
+ assertEquals("x", cs.getAxis(0).getName().getCode(), "name");
+ assertEquals("y", cs.getAxis(1).getName().getCode(), "name");
+ assertEquals("z", cs.getAxis(2).getName().getCode(), "name");
useStraightQuotes = true;
super.testEngineeringForShip(); // Test again with “ and ” replaced by ".
@@ -555,9 +555,9 @@ public final class WKTParserTest extends CRSParserTest {
public void testDerivedEngineeringFromGeodetic() throws FactoryException {
super.testDerivedEngineeringFromGeodetic();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", "Topocentric East", cs.getAxis(0).getName().getCode());
- assertEquals("name", "Topocentric North", cs.getAxis(1).getName().getCode());
- assertEquals("name", "Topocentric height", cs.getAxis(2).getName().getCode());
+ assertEquals("Topocentric East", cs.getAxis(0).getName().getCode(), "name");
+ assertEquals("Topocentric North", cs.getAxis(1).getName().getCode(), "name");
+ assertEquals("Topocentric height", cs.getAxis(2).getName().getCode(), "name");
useStraightQuotes = true;
super.testDerivedEngineeringFromGeodetic(); // Test again with “ and ” replaced by ".
@@ -580,8 +580,8 @@ public final class WKTParserTest extends CRSParserTest {
* In this case we had no axis names, so Apache SIS reused the abbreviations.
* This could change in any future SIS version if we update Transliterator.
*/
- assertEquals("name", "I", cs.getAxis(0).getName().getCode());
- assertEquals("name", "J", cs.getAxis(1).getName().getCode());
+ assertEquals("I", cs.getAxis(0).getName().getCode(), "name");
+ assertEquals("J", cs.getAxis(1).getName().getCode(), "name");
useStraightQuotes = true;
super.testDerivedEngineeringFromProjected(); // Test again with “ and ” replaced by ".
@@ -616,9 +616,9 @@ public final class WKTParserTest extends CRSParserTest {
public void testCompoundWithVertical() throws FactoryException {
super.testCompoundWithVertical();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode());
- assertEquals("name", AxisNames.GRAVITY_RELATED_HEIGHT, cs.getAxis(2).getName().getCode());
+ assertEquals(AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode(), "name");
+ assertEquals(AxisNames.GRAVITY_RELATED_HEIGHT, cs.getAxis(2).getName().getCode(), "name");
useStraightQuotes = true;
super.testCompoundWithVertical(); // Test again with “ and ” replaced by ".
@@ -651,9 +651,9 @@ public final class WKTParserTest extends CRSParserTest {
public void testCompoundWithTime() throws FactoryException {
super.testCompoundWithTime();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode());
- assertEquals("name", AxisNames.TIME, cs.getAxis(2).getName().getCode());
+ assertEquals(AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode(), "name");
+ assertEquals(AxisNames.TIME, cs.getAxis(2).getName().getCode(), "name");
useStraightQuotes = true;
super.testCompoundWithTime(); // Test again with “ and ” replaced by ".
@@ -688,9 +688,9 @@ public final class WKTParserTest extends CRSParserTest {
public void testCompoundWithParametric() throws FactoryException {
super.testCompoundWithParametric();
final CoordinateSystem cs = object.getCoordinateSystem();
- assertEquals("name", AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode());
- assertEquals("name", AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode());
- assertEquals("name", "pressure", cs.getAxis(2).getName().getCode());
+ assertEquals(AxisNames.GEODETIC_LATITUDE, cs.getAxis(0).getName().getCode(), "name");
+ assertEquals(AxisNames.GEODETIC_LONGITUDE, cs.getAxis(1).getName().getCode(), "name");
+ assertEquals("pressure", cs.getAxis(2).getName().getCode(), "name");
useStraightQuotes = true;
super.testCompoundWithParametric(); // Test again with “ and ” replaced by ".
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/DefaultParameterValueTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/DefaultParameterValueTest.java
index a43bc07976..79b57576d8 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/DefaultParameterValueTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/DefaultParameterValueTest.java
@@ -29,11 +29,12 @@ import org.apache.sis.measure.Units;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.opengis.test.Validators.validate;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
import static org.apache.sis.test.Assertions.assertSerializedEquals;
import static org.apache.sis.referencing.Assertions.assertWktEquals;
@@ -78,14 +79,14 @@ public final class DefaultParameterValueTest extends TestCase {
/** Asserts that the value and the converted value are equal to the expected one. */
void assertValueEquals(final Object expected) {
- assertEquals("value", expected, getValue());
- assertEquals("convertedValue", expected, convertedValue);
+ assertEquals(expected, getValue());
+ assertEquals(expected, convertedValue);
}
/** Asserts that the value and the converted value are equal to the expected ones. */
void assertValueEquals(final Object expected, final Object converted) {
- assertEquals("value", expected, getValue());
- assertEquals("convertedValue", converted, convertedValue);
+ assertEquals(expected, getValue());
+ assertEquals(converted, convertedValue);
}
}
@@ -130,40 +131,32 @@ public final class DefaultParameterValueTest extends TestCase {
final ParameterDescriptor<Integer> descriptor = parameter.getDescriptor();
validate(parameter);
- assertEquals("name", "Integer param", descriptor.getName().getCode());
- assertEquals("type", Integer.class, descriptor.getValueClass());
- assertNull ("defaultUnit", descriptor.getUnit());
- assertNull ("unit", parameter .getUnit());
- assertNull ("defaultValue", descriptor.getDefaultValue());
- assertEquals("value", Integer.valueOf(14), parameter .getValue());
- assertEquals("intValue", 14, parameter .intValue());
- assertEquals("doubleValue", 14, parameter .doubleValue(), STRICT);
- assertNull ("minimum", descriptor.getMinimumValue());
- assertNull ("maximum", descriptor.getMaximumValue());
- assertNull ("validValues", descriptor.getValidValues());
+ assertEquals("Integer param", descriptor.getName().getCode());
+ assertEquals(Integer.class, descriptor.getValueClass());
+ assertNull ( descriptor.getUnit());
+ assertNull ( parameter .getUnit());
+ assertNull ( descriptor.getDefaultValue());
+ assertEquals((Integer) 14, parameter .getValue());
+ assertEquals(14, parameter .intValue());
+ assertEquals(14, parameter .doubleValue());
+ assertNull ( descriptor.getMinimumValue());
+ assertNull ( descriptor.getMaximumValue());
+ assertNull ( descriptor.getValidValues());
/*
* Invalid operation: this parameter does not have unit of measurement.
*/
- try {
- parameter.doubleValue(Units.METRE);
- fail("doubleValue(METRE)");
- } catch (IllegalStateException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Integer param"));
- }
+ IllegalStateException ipt;
+ ipt = assertThrows(IllegalStateException.class, () -> parameter.doubleValue(Units.METRE));
+ assertMessageContains(ipt, "Integer param");
/*
* Invalid operation: this parameter is an integer, not a string.
* While we could convert the integer to a string, in the context
* of map projection parameters this is usually an error.
*/
- try {
- parameter.stringValue();
- fail("stringValue()");
- } catch (InvalidParameterTypeException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Integer"));
- assertEquals("Integer param", exception.getParameterName());
- }
+ InvalidParameterTypeException exception;
+ exception = assertThrows(InvalidParameterTypeException.class, () -> parameter.stringValue());
+ assertMessageContains(exception, "Integer");
+ assertEquals("Integer param", exception.getParameterName());
/*
* Set values. In the case of null value, since this parameter is optional
* the value should stay null (not substituted by the default value).
@@ -186,69 +179,51 @@ public final class DefaultParameterValueTest extends TestCase {
final Watcher<Integer> parameter = new Watcher<>(
DefaultParameterDescriptorTest.create("Bounded param", -30, +40, 15));
assertEquals(Integer.class, parameter.getDescriptor().getValueClass());
- assertEquals( "value", Integer.valueOf(15), parameter.getValue());
- assertEquals( "intValue", 15, parameter.intValue());
- assertEquals("doubleValue", 15, parameter.doubleValue(), STRICT);
+ assertEquals(Integer.valueOf(15), parameter.getValue());
+ assertEquals(15, parameter.intValue());
+ assertEquals(15, parameter.doubleValue());
validate(parameter);
/*
* Set a value inside the range of valid values.
*/
parameter.setValue(12);
parameter.assertValueEquals(Integer.valueOf(12));
- assertEquals( "intValue", 12, parameter.intValue());
- assertEquals("doubleValue", 12, parameter.doubleValue(), STRICT);
+ assertEquals(12, parameter.intValue());
+ assertEquals(12, parameter.doubleValue());
validate(parameter);
/*
* Invalid operations: attempt to set values out of range.
*/
- try {
- parameter.setValue(50);
- fail("setValue(> max)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Bounded param"));
- assertEquals("Bounded param", exception.getParameterName());
- }
- try {
- parameter.setValue(-40);
- fail("setValue(< min)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Bounded param"));
- assertEquals("Bounded param", exception.getParameterName());
- }
+ InvalidParameterValueException exception;
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(50), "setValue(> max)");
+ assertMessageContains(exception, "Bounded param");
+ assertEquals("Bounded param", exception.getParameterName());
+
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(-40), "setValue(< min)");
+ assertMessageContains(exception, "Bounded param");
+ assertEquals("Bounded param", exception.getParameterName());
/*
* Invalid operation: attempt to set a floating point value.
*/
- try {
- parameter.setValue(10.5);
- fail("setValue(double)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Integer"));
- assertEquals("Bounded param", exception.getParameterName());
- }
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(10.5), "setValue(double)");
+ assertMessageContains(exception, "Integer");
+ assertEquals("Bounded param", exception.getParameterName());
/*
* Try again to set a floating point value, but this time
* the value can be converted to an integer.
*/
parameter.setValue(10.0);
parameter.assertValueEquals(Integer.valueOf(10));
- assertEquals( "intValue", 10, parameter.intValue());
- assertEquals("doubleValue", 10, parameter.doubleValue(), STRICT);
+ assertEquals(10, parameter.intValue());
+ assertEquals(10, parameter.doubleValue());
validate(parameter);
/*
* Invalid operation: set the same value than above, but with a unit of measurement.
* This shall be an invalid operation since we created a unitless parameter.
*/
- try {
- parameter.setValue(10.0, Units.METRE);
- fail("setValue(double,Unit)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Bounded param"));
- assertEquals("Bounded param", exception.getParameterName());
- }
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(10.0, Units.METRE), "setValue(double,Unit)");
+ assertMessageContains(exception, "Bounded param");
+ assertEquals("Bounded param", exception.getParameterName());
}
/**
@@ -260,39 +235,35 @@ public final class DefaultParameterValueTest extends TestCase {
final ParameterDescriptor<Double> descriptor = parameter.getDescriptor();
validate(parameter);
- assertEquals("name", "Numerical param", descriptor.getName().getCode());
- assertEquals("defaultUnit", Units.METRE, descriptor.getUnit());
- assertEquals("unit", Units.METRE, parameter .getUnit());
- assertNull ("defaultValue", descriptor.getDefaultValue());
- assertEquals("value", Double.valueOf(3), parameter .getValue());
- assertEquals("intValue", 3, parameter .intValue());
- assertEquals("doubleValue", 3, parameter .doubleValue(), STRICT);
- assertEquals("doubleValue", 300, parameter .doubleValue(Units.CENTIMETRE), STRICT);
- assertNull ("minimum", descriptor.getMinimumValue());
- assertNull ("maximum", descriptor.getMaximumValue());
- assertNull ("validValues", descriptor.getValidValues());
+ assertEquals("Numerical param", descriptor.getName().getCode());
+ assertEquals(Units.METRE, descriptor.getUnit());
+ assertEquals(Units.METRE, parameter .getUnit());
+ assertNull ( descriptor.getDefaultValue());
+ assertEquals(Double.valueOf(3), parameter .getValue());
+ assertEquals( 3, parameter .intValue());
+ assertEquals( 3, parameter .doubleValue());
+ assertEquals(300, parameter .doubleValue(Units.CENTIMETRE));
+ assertNull ( descriptor.getMinimumValue());
+ assertNull ( descriptor.getMaximumValue());
+ assertNull ( descriptor.getValidValues());
/*
* Invalid operation: this parameter is a real number, not a string.
* While we could convert the number to a string, in the context of
* map projection parameters this is usually an error.
*/
- try {
- parameter.stringValue();
- fail("stringValue()");
- } catch (InvalidParameterTypeException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Double"));
- assertEquals("Numerical param", exception.getParameterName());
- }
+ InvalidParameterTypeException exception;
+ exception = assertThrows(InvalidParameterTypeException.class, () -> parameter.stringValue());
+ assertMessageContains(exception, "Double");
+ assertEquals("Numerical param", exception.getParameterName());
/*
* Sets a value in centimetres.
*/
parameter.setValue(400, Units.CENTIMETRE);
parameter.assertValueEquals(Double.valueOf(400), Double.valueOf(4));
- assertEquals("unit", Units.CENTIMETRE, parameter.getUnit());
- assertEquals("doubleValue", 400, parameter.doubleValue(), STRICT);
- assertEquals("doubleValue", 400, parameter.doubleValue(Units.CENTIMETRE), STRICT);
- assertEquals("doubleValue", 4, parameter.doubleValue(Units.METRE), STRICT);
+ assertEquals(Units.CENTIMETRE, parameter.getUnit());
+ assertEquals(400, parameter.doubleValue());
+ assertEquals(400, parameter.doubleValue(Units.CENTIMETRE));
+ assertEquals( 4, parameter.doubleValue(Units.METRE));
validate(parameter);
}
@@ -306,39 +277,27 @@ public final class DefaultParameterValueTest extends TestCase {
final Watcher<Double> parameter = new Watcher<>(
DefaultParameterDescriptorTest.create("Bounded param", -30.0, +40.0, 15.0, null));
assertEquals(Double.class, parameter.getDescriptor().getValueClass());
- assertEquals( "value", Double.valueOf(15), parameter.getValue());
- assertEquals( "intValue", 15, parameter.intValue());
- assertEquals("doubleValue", 15, parameter.doubleValue(), STRICT);
+ assertEquals(Double.valueOf(15), parameter.getValue());
+ assertEquals(15, parameter.intValue());
+ assertEquals(15, parameter.doubleValue());
validate(parameter);
parameter.setValue(12.0);
parameter.assertValueEquals(Double.valueOf(12));
- assertEquals( "intValue", 12, parameter.intValue());
- assertEquals("doubleValue", 12, parameter.doubleValue(), STRICT);
+ assertEquals(12, parameter.intValue());
+ assertEquals(12, parameter.doubleValue());
validate(parameter);
- try {
- parameter.setValue(50.0);
- fail("setValue(> max)");
- } catch (InvalidParameterValueException exception) {
- // This is the expected exception.
- assertEquals("Bounded param", exception.getParameterName());
- }
- try {
- parameter.setValue(-40.0);
- fail("setValue(< min)");
- } catch (InvalidParameterValueException exception) {
- // This is the expected exception.
- assertEquals("Bounded param", exception.getParameterName());
- }
- try {
- parameter.setValue("12");
- fail("setValue(String)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Bounded param"));
- assertEquals("Bounded param", exception.getParameterName());
- }
+ InvalidParameterValueException exception;
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(50.0), "setValue(> max)");
+ assertEquals("Bounded param", exception.getParameterName());
+
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(-40.0), "setValue(< min)");
+ assertEquals("Bounded param", exception.getParameterName());
+
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue("12"), "setValue(String)");
+ assertMessageContains(exception, "Bounded param");
+ assertEquals("Bounded param", exception.getParameterName());
}
/**
@@ -349,42 +308,36 @@ public final class DefaultParameterValueTest extends TestCase {
public void testBoundedMeasure() {
final Watcher<Double> parameter = new Watcher<>(
DefaultParameterDescriptorTest.create("Length measure", 4, 20, 12, Units.METRE));
- assertEquals("value", Double.valueOf(12), parameter.getValue());
- assertEquals("intValue", 12, parameter.intValue());
- assertEquals("unit", Units.METRE, parameter.getUnit());
+ assertEquals(Double.valueOf(12), parameter.getValue());
+ assertEquals(12, parameter.intValue());
+ assertEquals(Units.METRE, parameter.getUnit());
validate(parameter);
for (int i=4; i<=20; i++) {
parameter.setValue(i);
parameter.assertValueEquals(Double.valueOf(i));
- assertEquals("unit", Units.METRE, parameter.getUnit());
- assertEquals("value", i, parameter.doubleValue(Units.METRE), STRICT);
- assertEquals("value", 100*i, parameter.doubleValue(Units.CENTIMETRE), STRICT);
- }
- try {
- parameter.setValue(3.0);
- fail("setValue(< min)");
- } catch (InvalidParameterValueException exception) {
- assertEquals("Length measure", exception.getParameterName());
- }
- try {
- parameter.setValue(10.0, Units.KILOMETRE); // Out of range only after unit conversion.
- fail("setValue(> max)");
- } catch (InvalidParameterValueException exception) {
- assertEquals("Length measure", exception.getParameterName());
- }
- try {
- parameter.setValue("12");
- fail("setValue(Sring)");
- } catch (InvalidParameterValueException exception) {
- assertEquals("Length measure", exception.getParameterName());
+ assertEquals(Units.METRE, parameter.getUnit());
+ assertEquals(i, parameter.doubleValue(Units.METRE));
+ assertEquals(100*i, parameter.doubleValue(Units.CENTIMETRE));
}
+
+ InvalidParameterValueException exception;
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(3.0), "setValue(< min)");
+ assertEquals("Length measure", exception.getParameterName());
+
+ // Out of range only after unit conversion.
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(10.0, Units.KILOMETRE), "setValue(> max)");
+ assertEquals("Length measure", exception.getParameterName());
+
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue("12"), "setValue(Sring)");
+ assertEquals("Length measure", exception.getParameterName());
+
for (int i=400; i<=2000; i+=100) {
final double metres = i / 100.0;
parameter.setValue(i, Units.CENTIMETRE);
parameter.assertValueEquals(Double.valueOf(i), Double.valueOf(metres));
- assertEquals("unit", Units.CENTIMETRE, parameter.getUnit());
- assertEquals("value", metres, parameter.doubleValue(Units.METRE), EPS);
+ assertEquals(Units.CENTIMETRE, parameter.getUnit());
+ assertEquals(metres, parameter.doubleValue(Units.METRE), EPS);
}
}
@@ -411,19 +364,15 @@ public final class DefaultParameterValueTest extends TestCase {
assertArrayEquals(metres, parameter.convertedValue, 0);
assertArrayEquals(values, parameter.doubleValueList(), 0);
assertArrayEquals(metres, parameter.doubleValueList(Units.METRE), 0);
- /*
- * Values out of range.
- */
- try {
- parameter.setValue(new double[] {5, 10, -5}, Units.METRE);
- } catch (InvalidParameterValueException e) {
- assertTrue(e.getMessage().contains("myValues[2]"));
- }
- try {
- parameter.setValue(new double[] {4, 5}, Units.KILOMETRE); // Out of range only after unit conversion.
- } catch (InvalidParameterValueException e) {
- assertTrue(e.getMessage().contains("myValues[1]"));
- }
+
+ // Values out of range.
+ InvalidParameterValueException exception;
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(new double[] {5, 10, -5}, Units.METRE));
+ assertMessageContains(exception, "myValues[2]");
+
+ // Values out of range only after unit conversion.
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(new double[] {4, 5}, Units.KILOMETRE));
+ assertMessageContains(exception, "myValues[1]");
}
/**
@@ -442,55 +391,40 @@ public final class DefaultParameterValueTest extends TestCase {
final DefaultParameterValue<AxisDirection> parameter = new DefaultParameterValue<>(descriptor);
validate(parameter);
- assertEquals ("name", "Direction", descriptor.getName().getCode());
- assertEquals ("defaultValue", AxisDirection.NORTH, descriptor.getDefaultValue());
- assertEquals ("value", AxisDirection.NORTH, parameter .getValue());
- assertNull ("defaultUnit", descriptor.getUnit());
- assertNull ("unit", parameter .getUnit());
- assertNull ("minimum", descriptor.getMinimumValue());
- assertNull ("maximum", descriptor.getMaximumValue());
- assertArrayEquals("validValues", directions, descriptor.getValidValues().toArray());
+ assertEquals ("Direction", descriptor.getName().getCode());
+ assertEquals (AxisDirection.NORTH, descriptor.getDefaultValue());
+ assertEquals (AxisDirection.NORTH, parameter .getValue());
+ assertNull ( descriptor.getUnit());
+ assertNull ( parameter .getUnit());
+ assertNull ( descriptor.getMinimumValue());
+ assertNull ( descriptor.getMaximumValue());
+ assertArrayEquals(directions, descriptor.getValidValues().toArray());
/*
- * Invalid operation: attempt to get the value as a 'double' is not allowed.
+ * Invalid operation: attempt to get the value as a `double` is not allowed.
*/
- try {
- parameter.doubleValue();
- fail("doubleValue shall not be allowed on AxisDirection");
- } catch (InvalidParameterTypeException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("AxisDirection"));
- assertEquals("Direction", exception.getParameterName());
- }
+ InvalidParameterTypeException ipt;
+ ipt = assertThrows(InvalidParameterTypeException.class, () -> parameter.doubleValue(),
+ "doubleValue() shall not be allowed on AxisDirection");
+ assertMessageContains(ipt, "AxisDirection");
+ assertEquals("Direction", ipt.getParameterName());
/*
* Set a valid value.
*/
parameter.setValue(AxisDirection.PAST);
- assertEquals("value", AxisDirection.PAST, parameter.getValue());
+ assertEquals(AxisDirection.PAST, parameter.getValue());
/*
* Invalid operation: set a value of valid type but not in the list of valid values.
*/
- try {
- parameter.setValue(AxisDirection.GEOCENTRIC_X);
- fail("setValue(AxisDirection.UP)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Direction"));
- assertTrue(message, message.contains("Geocentric X"));
- assertEquals("Direction", exception.getParameterName());
- }
+ InvalidParameterValueException exception;
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(AxisDirection.GEOCENTRIC_X));
+ assertMessageContains(exception, "Direction", "Geocentric X");
+ assertEquals("Direction", exception.getParameterName());
/*
* Invalid operation: attempt to set a value of wrong type.
*/
- try {
- parameter.setValue(VerticalDatumType.BAROMETRIC);
- fail("setValue(VerticalDatumType)");
- } catch (InvalidParameterValueException exception) {
- final String message = exception.getMessage();
- assertTrue(message, message.contains("Direction"));
- assertTrue(message, message.contains("VerticalDatumType"));
- assertTrue(message, message.contains("AxisDirection"));
- assertEquals("Direction", exception.getParameterName());
- }
+ exception = assertThrows(InvalidParameterValueException.class, () -> parameter.setValue(VerticalDatumType.BAROMETRIC));
+ assertMessageContains(exception, "Direction", "VerticalDatumType", "AxisDirection");
+ assertEquals("Direction", exception.getParameterName());
}
/**
@@ -509,62 +443,62 @@ public final class DefaultParameterValueTest extends TestCase {
d = p.getDescriptor();
validate(p);
- assertNotNull("Expected a descriptor.", d);
- assertNull ("Expected no default value.", d.getDefaultValue());
- assertNull ("Expected no minimal value.", d.getMinimumValue());
- assertNull ("Expected no maximal value.", d.getMaximumValue());
- assertNull ("Expected no enumeration.", d.getValidValues());
- assertEquals ("Expected integer type.", Integer.class, d.getValueClass());
- assertTrue ("Expected integer type.", p.getValue() instanceof Integer);
- assertNull ("Expected unitless parameter.", p.getUnit());
- assertEquals ("Expected integer value", i, p.intValue());
- assertEquals ("Expected integer value", i, p.doubleValue(), STRICT);
+ assertNotNull (d);
+ assertNull (d.getDefaultValue());
+ assertNull (d.getMinimumValue());
+ assertNull (d.getMaximumValue());
+ assertNull (d.getValidValues());
+ assertEquals (Integer.class, d.getValueClass());
+ assertInstanceOf(Integer.class, p.getValue());
+ assertNull (p.getUnit());
+ assertEquals (i, p.intValue());
+ assertEquals (i, p.doubleValue());
p = create("Unitlesss double value", i, null);
d = p.getDescriptor();
validate(p);
- assertNotNull("Expected a descriptor.", d);
- assertNull ("Expected no default value.", d.getDefaultValue());
- assertNull ("Expected no minimal value.", d.getMinimumValue());
- assertNull ("Expected no maximal value.", d.getMaximumValue());
- assertNull ("Expected no enumeration.", d.getValidValues());
- assertEquals ("Expected double type.", Double.class, d.getValueClass());
- assertTrue ("Expected double type.", p.getValue() instanceof Double);
- assertNull ("Expected unitless parameter.", p.getUnit());
- assertEquals ("Expected integer value", i, p.intValue());
- assertEquals ("Expected integer value", i, p.doubleValue(), STRICT);
+ assertNotNull (d);
+ assertNull (d.getDefaultValue());
+ assertNull (d.getMinimumValue());
+ assertNull (d.getMaximumValue());
+ assertNull (d.getValidValues());
+ assertEquals (Double.class, d.getValueClass());
+ assertInstanceOf(Double.class, p.getValue());
+ assertNull (p.getUnit());
+ assertEquals (i, p.intValue());
+ assertEquals (i, p.doubleValue());
p = create("Dimensionless double value", i, Units.UNITY);
d = p.getDescriptor();
validate(p);
- assertNotNull("Expected a descriptor.", d);
- assertNull ("Expected no default value.", d.getDefaultValue());
- assertNull ("Expected no minimal value.", d.getMinimumValue());
- assertNull ("Expected no maximal value.", d.getMaximumValue());
- assertNull ("Expected no enumeration.", d.getValidValues());
- assertEquals ("Expected double type.", Double.class, d.getValueClass());
- assertTrue ("Expected double type.", p.getValue() instanceof Double);
- assertEquals ("Expected dimensionless.", Units.UNITY, p.getUnit());
- assertEquals ("Expected integer value", i, p.intValue());
- assertEquals ("Expected integer value", i, p.doubleValue(), STRICT);
+ assertNotNull (d);
+ assertNull (d.getDefaultValue());
+ assertNull (d.getMinimumValue());
+ assertNull (d.getMaximumValue());
+ assertNull (d.getValidValues());
+ assertEquals (Double.class, d.getValueClass());
+ assertInstanceOf(Double.class, p.getValue());
+ assertEquals (Units.UNITY, p.getUnit());
+ assertEquals (i, p.intValue());
+ assertEquals (i, p.doubleValue());
p = create("Angular double value", i, Units.DEGREE);
d = p.getDescriptor();
validate(p);
- assertNotNull("Expected a descriptor.", d);
- assertNull ("Expected no default value.", d.getDefaultValue());
- assertNull ("Expected no minimal value.", d.getMinimumValue());
- assertNull ("Expected no maximal value.", d.getMaximumValue());
- assertNull ("Expected no enumeration.", d.getValidValues());
- assertEquals ("Expected double type.", Double.class, d.getValueClass());
- assertTrue ("Expected double type.", p.getValue() instanceof Double);
- assertEquals ("Expected angular unit.", Units.DEGREE, p.getUnit());
- assertEquals ("Expected integer value", i, p.intValue());
- assertEquals ("Expected integer value", i, p.doubleValue(), STRICT);
- assertEquals ("Expected unit conversion.", toRadians(i), p.doubleValue(Units.RADIAN), EPS);
+ assertNotNull (d);
+ assertNull (d.getDefaultValue());
+ assertNull (d.getMinimumValue());
+ assertNull (d.getMaximumValue());
+ assertNull (d.getValidValues());
+ assertEquals (Double.class, d.getValueClass());
+ assertInstanceOf(Double.class, p.getValue());
+ assertEquals (Units.DEGREE, p.getUnit());
+ assertEquals (i, p.intValue());
+ assertEquals (i, p.doubleValue());
+ assertEquals (toRadians(i), p.doubleValue(Units.RADIAN), EPS, "Require unit conversion.");
}
}
@@ -573,8 +507,8 @@ public final class DefaultParameterValueTest extends TestCase {
*/
@Test
public void testClone() {
- final DefaultParameterValue<Double> parameter = create("Clone test", 3, Units.METRE);
- assertEquals("equals(clone)", parameter, parameter.clone());
+ DefaultParameterValue<Double> parameter = create("Clone test", 3, Units.METRE);
+ assertEquals(parameter, parameter.clone());
}
/**
@@ -582,7 +516,7 @@ public final class DefaultParameterValueTest extends TestCase {
*/
@Test
public void testSerialization() {
- final DefaultParameterValue<Double> parameter = create("Serialization test", 3, Units.METRE);
+ DefaultParameterValue<Double> parameter = create("Serialization test", 3, Units.METRE);
assertNotSame(parameter, assertSerializedEquals(parameter));
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformFactoryMock.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformFactoryMock.java
index dbc7bd7fdb..c9565b5cce 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformFactoryMock.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformFactoryMock.java
@@ -29,6 +29,10 @@ import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.OperationMethod;
import org.opengis.referencing.operation.SingleOperation;
import org.apache.sis.referencing.operation.DefaultOperationMethod;
+import org.apache.sis.referencing.operation.provider.AbstractProvider;
+
+// Test dependencies
+import static org.junit.jupiter.api.Assertions.*;
/**
@@ -43,6 +47,21 @@ public final class MathTransformFactoryMock implements MathTransformFactory {
*/
private final DefaultOperationMethod method;
+ /**
+ * Parameters used during the last creation of a math transform.
+ * Stored for allowing callers to verify the parameters if needed.
+ *
+ * @see #createParameterizedTransform(ParameterValueGroup)
+ */
+ public ParameterValueGroup lastParameters;
+
+ /**
+ * Creates a new mock supporting only the affine and concatenate operations.
+ */
+ public MathTransformFactoryMock() {
+ method = null;
+ }
+
/**
* Creates a new mock for the given operation method.
*
@@ -52,6 +71,17 @@ public final class MathTransformFactoryMock implements MathTransformFactory {
this.method = method;
}
+ /**
+ * Creates a new mock for the operation method of the given name.
+ *
+ * @param method the operation method to put in this factory.
+ * @throws NoSuchIdentifierException if the given method is not known.
+ */
+ public MathTransformFactoryMock(final String method) throws NoSuchIdentifierException {
+ final var factory = DefaultMathTransformFactory.provider();
+ this.method = assertInstanceOf(AbstractProvider.class, factory.getOperationMethod(method));
+ }
+
/**
* Returns the singleton method, if assignable to the given type.
*
@@ -98,6 +128,7 @@ public final class MathTransformFactoryMock implements MathTransformFactory {
*/
@Override
public MathTransform createParameterizedTransform(ParameterValueGroup parameters) throws FactoryException {
+ lastParameters = parameters;
return ((MathTransformProvider) method).createMathTransform(this, parameters);
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/PoleRotationTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/PoleRotationTest.java
index 78d35b321a..ccbdad56df 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/PoleRotationTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/PoleRotationTest.java
@@ -39,7 +39,7 @@ public final class PoleRotationTest extends MathTransformTestCase {
* This mock supports only the "affine" and "concatenate" operations.
*/
private static MathTransformFactory factory() {
- return new MathTransformFactoryMock(null);
+ return new MathTransformFactoryMock();
}
/**
diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java
index bdd7011a6c..d82bc971ff 100644
--- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java
+++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java
@@ -27,6 +27,7 @@ import javax.imageio.stream.ImageOutputStream;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
+import static org.apache.sis.test.Assertions.assertMessageContains;
/**
@@ -194,23 +195,24 @@ public final class ChannelDataOutputTest extends ChannelDataTestCase {
@Test
public void testArgumentChecks() throws IOException {
initialize("testArgumentChecks", 20, 10);
- String message;
// Shall not accept invalid bitOffset.
- message = assertThrows(IllegalArgumentException.class, () -> testedStream.setBitOffset(9)).getMessage();
- assertTrue(message.contains("bitOffset"), message);
+ Exception exception;
+ exception = assertThrows(IllegalArgumentException.class, () -> testedStream.setBitOffset(9));
+ assertMessageContains(exception, "bitOffset");
// Shall not accept reset without mark.
- message = assertThrows(IOException.class, () -> testedStream.reset()).getMessage();
- assertNotNull(message);
+ exception = assertThrows(IOException.class, () -> testedStream.reset());
+ assertMessageContains(exception);
// Shall not flush at a position greater than buffer limit.
final int v = random.nextInt();
referenceStream.writeShort(v);
testedStream.writeShort(v);
testedStream.flushBefore(0); // Valid.
- message = assertThrows(IndexOutOfBoundsException.class, () -> testedStream.flushBefore(3)).getMessage();
- assertTrue(message.contains("position"), message);
+
+ exception = assertThrows(IndexOutOfBoundsException.class, () -> testedStream.flushBefore(3));
+ assertMessageContains(exception, "position");
testedStream.flush();
testedStream.flushBefore(0); // Should be a no-operation.
@@ -351,8 +353,8 @@ public final class ChannelDataOutputTest extends ChannelDataTestCase {
/*
* Verify that we have no remaining marks, and finally compare stream content.
*/
- String message = assertThrows(IOException.class, () -> testedStream.reset()).getMessage();
- assertNotNull(message);
+ IOException exception = assertThrows(IOException.class, () -> testedStream.reset());
+ assertMessageContains(exception);
assertStreamContentEquals();
}
diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java
index 8afb88139d..5569206dc2 100644
--- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java
+++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java
@@ -33,6 +33,7 @@ import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.sis.test.TestUtilities;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
// Specific to the geoapi-3.1 and geoapi-4.0 branches:
import org.opengis.feature.Feature;
@@ -434,7 +435,7 @@ public final class FeatureQueryTest extends TestCase {
query.setProjection(new FeatureQuery.NamedExpression(ff.property("value1", Integer.class), (String) null),
virtualProjection(ff.property("valueMissing", Integer.class), "renamed1"));
- DataStoreContentException ex = assertThrows(DataStoreContentException.class, this::executeAndGetFirst);
- assertNotNull(ex.getMessage());
+ DataStoreContentException exception = assertThrows(DataStoreContentException.class, this::executeAndGetFirst);
+ assertMessageContains(exception);
}
}
diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java
index 6813520876..21851ec985 100644
--- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java
+++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java
@@ -39,10 +39,10 @@ import org.apache.sis.storage.internal.InputStreamAdapter;
import org.junit.Test;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assertions.*;
-import static org.opengis.test.Assert.assertInstanceOf;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
/**
@@ -198,19 +198,18 @@ public final class StorageConnectorTest extends TestCase {
final StorageConnector connector = create(asStream);
assertEquals(asStream, connector.getStorageAs(URI.class) == null);
assertEquals(asStream, connector.getStorageAs(Path.class) == null);
- final DataInput input = connector.getStorageAs(DataInput.class);
+ final ChannelDataInput input = assertInstanceOf(ChannelDataInput.class,
+ connector.getStorageAs(DataInput.class), "Needs the SIS implementation.");
assertSame(input, connector.getStorageAs(DataInput.class), "Value shall be cached.");
- assertInstanceOf("Needs the SIS implementation.", ChannelDataInput.class, input);
assertSame(input, connector.getStorageAs(ChannelDataInput.class), "Instance shall be shared.");
/*
* 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.
*/
- final ReadableByteChannel channel = ((ChannelDataInput) input).channel;
- assertTrue(channel.isOpen(), "channel.isOpen()");
+ assertTrue(input.channel.isOpen(), "channel.isOpen()");
assertEquals(MAGIC_NUMBER, input.readInt(), "First 4 bytes");
connector.closeAllExcept(null);
- assertFalse(channel.isOpen(), "channel.isOpen()");
+ assertFalse(input.channel.isOpen(), "channel.isOpen()");
}
/**
@@ -278,13 +277,12 @@ public final class StorageConnectorTest extends TestCase {
final InputStream in = connector.getStorageAs(InputStream.class);
assertNotSame(connector.getStorage(), in);
assertSame(in, connector.getStorageAs(InputStream.class), "Expected cached value.");
- assertInstanceOf("Expected Channel backend.", InputStreamAdapter.class, in);
- final ImageInputStream input = ((InputStreamAdapter) in).input;
- assertInstanceOf("Expected Channel backend.", ChannelImageInputStream.class, input);
+
+ final ImageInputStream input = assertInstanceOf(InputStreamAdapter.class, in).input;
assertSame(input, connector.getStorageAs(DataInput.class));
assertSame(input, connector.getStorageAs(ImageInputStream.class));
- final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
+ final ReadableByteChannel channel = assertInstanceOf(ChannelImageInputStream.class, input).channel;
assertTrue(channel.isOpen());
connector.closeAllExcept(null);
assertFalse(channel.isOpen());
@@ -310,7 +308,7 @@ public final class StorageConnectorTest extends TestCase {
* This operation should force StorageConnector to discard the previous Reader.
*/
final ImageInputStream im = connector.getStorageAs(ImageInputStream.class);
- assertInstanceOf("Needs the SIS implementation.", ChannelImageInputStream.class, im);
+ assertInstanceOf(ChannelImageInputStream.class, im, "Needs the SIS implementation.");
im.mark();
assertEquals(MAGIC_NUMBER, im.readInt(), "First 4 bytes");
im.reset();
@@ -342,11 +340,11 @@ public final class StorageConnectorTest extends TestCase {
/*
* Get as an image input stream and ensure that the cached value has been replaced.
*/
- final ImageInputStream stream = connector.getStorageAs(ImageInputStream.class);
- assertInstanceOf("Needs the SIS implementation", ChannelImageInputStream.class, stream);
+ final ChannelImageInputStream stream = assertInstanceOf(ChannelImageInputStream.class,
+ connector.getStorageAs(ImageInputStream.class), "Needs the SIS implementation");
assertNotSame(input, stream, "Expected a new instance.");
- assertSame(input.channel, ((ChannelDataInput) stream).channel, "Shall share the channel.");
- assertSame(input.buffer, ((ChannelDataInput) stream).buffer, "Shall share the buffer.");
+ assertSame(input.channel, stream.channel, "Shall share the channel.");
+ assertSame(input.buffer, stream.buffer, "Shall share the buffer.");
assertSame(stream, connector.getStorageAs(ChannelDataInput.class), "Cached valud shall have been replaced.");
connector.closeAllExcept(null);
}
@@ -419,10 +417,9 @@ public final class StorageConnectorTest extends TestCase {
assertNull (connector.getStorageAs(URI.class));
assertNull (connector.getStorageAs(String.class));
- String message;
- message = assertThrows(UnconvertibleObjectException.class, () -> connector.getStorageAs(Float.class),
- "Should not have accepted Float.class").getMessage();
- assertTrue(message.contains("Float"), message);
+ UnconvertibleObjectException exception = assertThrows(UnconvertibleObjectException.class,
+ () -> connector.getStorageAs(Float.class), "Should not accept Float.class");
+ assertMessageContains(exception, "Float");
connector.closeAllExcept(null);
}
@@ -437,11 +434,10 @@ public final class StorageConnectorTest extends TestCase {
public void testCloseAllExcept() throws DataStoreException, IOException {
final StorageConnector connector = create(true);
final ChannelDataInput input = connector.getStorageAs(ChannelDataInput.class);
- final ReadableByteChannel channel = input.channel;
- assertTrue(channel.isOpen(), "channel.isOpen()");
+ assertTrue(input.channel.isOpen());
connector.closeAllExcept(input);
- assertTrue(channel.isOpen(), "channel.isOpen()");
- channel.close();
+ assertTrue(input.channel.isOpen());
+ input.channel.close(); // No "try-with-resource" for easier debugging if needed.
}
/**
@@ -456,10 +452,9 @@ public final class StorageConnectorTest extends TestCase {
final StorageConnector connector = create(false);
final InputStream stream = connector.commit(InputStream.class, "Test");
- String message;
- message = assertThrows(IllegalStateException.class, () -> connector.getStorageAs(ByteBuffer.class),
- "Connector should be closed.").getMessage();
- assertNotNull(message);
+ IllegalStateException exception = assertThrows(IllegalStateException.class,
+ () -> connector.getStorageAs(ByteBuffer.class), "Connector should be closed.");
+ assertMessageContains(exception);
assertExpectedBytes(stream);
stream.close(); // No "try-with-resource" for easier debugging if needed.
}
diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java
index 9badced427..a75fa01e36 100644
--- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java
+++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java
@@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
/**
@@ -197,14 +198,14 @@ public final class UnitFormatTest extends TestCase {
assertEquals("sFoo", f.format(Units.SECOND));
assertSame(Units.METRE, f.parse("mètre"));
- String message;
// “mFoo” should not be assigned to unit anymore.
- message = assertThrows(MeasurementParseException.class, () -> f.parse("mFoo")).getMessage();
- assertTrue(message.contains("mFoo"), message);
+ RuntimeException exception;
+ exception = assertThrows(MeasurementParseException.class, () -> f.parse("mFoo"));
+ assertMessageContains(exception, "mFoo");
// Should not accept labels ending with a digit.
- message = assertThrows(IllegalArgumentException.class, () -> f.label(Units.METRE, "m¹")).getMessage();
- assertTrue(message.contains("m¹"), message);
+ exception = assertThrows(IllegalArgumentException.class, () -> f.label(Units.METRE, "m¹"));
+ assertMessageContains(exception, "m¹");
}
/**
@@ -389,16 +390,14 @@ public final class UnitFormatTest extends TestCase {
assertSame(Units.WATT, f.parse("watt"));
assertSame(Units.UNITY, f.parse("unity"));
- String message;
// Should not accept unknown unit.
- message = assertThrows(MeasurementParseException.class, () -> f.parse("degree foo")).getMessage();
- assertTrue(message.contains("degree"), message);
- assertTrue(message.contains("foo"), message);
+ MeasurementParseException exception;
+ exception = assertThrows(MeasurementParseException.class, () -> f.parse("degree foo"));
+ assertMessageContains(exception, "degree", "foo");
// Should not accept localized unit unless requested.
- message = assertThrows(MeasurementParseException.class, () -> f.parse("mètre cube")).getMessage();
- assertTrue(message.contains("mètre"), message);
- assertTrue(message.contains("cube"), message);
+ exception = assertThrows(MeasurementParseException.class, () -> f.parse("mètre cube"));
+ assertMessageContains(exception, "mètre", "cube");
f.setLocale(Locale.FRANCE);
assertSame(Units.CUBIC_METRE, f.parse("mètre cube"));
@@ -486,10 +485,10 @@ public final class UnitFormatTest extends TestCase {
*/
assertSame(Units.TROPICAL_YEAR, f.parse("a"));
- String message;
// Should not accept prefix in ConventionalUnit.
- message = assertThrows(MeasurementParseException.class, () -> f.parse("ka")).getMessage();
- assertTrue(message.contains("ka"), message);
+ MeasurementParseException exception;
+ exception = assertThrows(MeasurementParseException.class, () -> f.parse("ka"));
+ assertMessageContains(exception, "ka");
}
/**
@@ -519,10 +518,9 @@ public final class UnitFormatTest extends TestCase {
assertEqualsIgnoreSymbol(Units.KILOGRAM.divide(Units.SQUARE_METRE), f.parse("kg m**-2"));
// Should not accept unknown sentence even if each individual word is known.
- String message;
- message = assertThrows(MeasurementParseException.class, () -> f.parse("degree minute")).getMessage();
- assertTrue(message.contains("degree"), message);
- assertTrue(message.contains("minute"), message);
+ MeasurementParseException exception;
+ exception = assertThrows(MeasurementParseException.class, () -> f.parse("degree minute"));
+ assertMessageContains(exception, "degree", "minute");
}
/**
diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Assertions.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Assertions.java
index f6610a8396..4dacca3fab 100644
--- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Assertions.java
+++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Assertions.java
@@ -40,7 +40,7 @@ import org.apache.sis.util.Classes;
import org.apache.sis.util.Static;
// Test dependencies
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
@@ -64,13 +64,13 @@ public final class Assertions extends Static {
* @param o2 the second object.
*/
public static void assertNotDeepEquals(final Object o1, final Object o2) {
- assertNotSame("same", o1, o2);
- assertFalse("equals", Objects .equals (o1, o2));
- assertFalse("deepEquals", Objects .deepEquals(o1, o2));
- assertFalse("deepEquals(STRICT)", Utilities.deepEquals(o1, o2, ComparisonMode.STRICT));
- assertFalse("deepEquals(BY_CONTRACT)", Utilities.deepEquals(o1, o2, ComparisonMode.BY_CONTRACT));
- assertFalse("deepEquals(IGNORE_METADATA)", Utilities.deepEquals(o1, o2, ComparisonMode.IGNORE_METADATA));
- assertFalse("deepEquals(APPROXIMATE)", Utilities.deepEquals(o1, o2, ComparisonMode.APPROXIMATE));
+ assertNotSame(o1, o2, "same");
+ assertFalse(Objects .equals (o1, o2), "equals");
+ assertFalse(Objects .deepEquals(o1, o2), "deepEquals");
+ assertFalse(Utilities.deepEquals(o1, o2, ComparisonMode.STRICT), "deepEquals(STRICT)");
+ assertFalse(Utilities.deepEquals(o1, o2, ComparisonMode.BY_CONTRACT), "deepEquals(BY_CONTRACT)");
+ assertFalse(Utilities.deepEquals(o1, o2, ComparisonMode.IGNORE_METADATA), "deepEquals(IGNORE_METADATA)");
+ assertFalse(Utilities.deepEquals(o1, o2, ComparisonMode.APPROXIMATE), "deepEquals(APPROXIMATE)");
}
/**
@@ -83,10 +83,10 @@ public final class Assertions extends Static {
* @param actual the actual object.
*/
public static void assertAlmostEquals(final Object expected, final Object actual) {
- assertFalse("Shall not be strictly equals", Utilities.deepEquals(expected, actual, ComparisonMode.STRICT));
- assertFalse("Shall be slightly different", Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA));
- assertTrue ("Shall be approximately equals", Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
- assertTrue ("DEBUG inconsistent with APPROXIMATE", Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATE));
+ assertFalse(Utilities.deepEquals(expected, actual, ComparisonMode.STRICT), "Shall not be strictly equal.");
+ assertFalse(Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA), "Shall be slightly different.");
+ assertTrue (Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG), "Shall be approximately equal.");
+ assertTrue (Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATE), "DEBUG inconsistent with APPROXIMATE.");
}
/**
@@ -97,9 +97,9 @@ public final class Assertions extends Static {
* @param actual the actual object.
*/
public static void assertEqualsIgnoreMetadata(final Object expected, final Object actual) {
- assertTrue("Shall be approximately equals", Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
- assertTrue("DEBUG inconsistent with APPROXIMATE", Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATE));
- assertTrue("Shall be equal, ignoring metadata", Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA));
+ assertTrue(Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG), "Shall be approximately equal.");
+ assertTrue(Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATE), "DEBUG inconsistent with APPROXIMATE.");
+ assertTrue(Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA), "Shall be equal, ignoring metadata.");
}
/**
@@ -112,9 +112,9 @@ public final class Assertions extends Static {
public static void assertArrayEqualsIgnoreMetadata(final Object[] expected, final Object[] actual) {
if (expected != actual) {
if (expected == null) {
- assertNull("Expected null array.", actual);
+ assertNull(actual, "Expected null array.");
} else {
- assertNotNull("Expected non-null array.", actual);
+ assertNotNull(actual, "Expected non-null array.");
final int length = StrictMath.min(expected.length, actual.length);
for (int i=0; i<length; i++) try {
assertEqualsIgnoreMetadata(expected[i], actual[i]);
@@ -122,7 +122,7 @@ public final class Assertions extends Static {
throw new AssertionError(Exceptions.formatChainedMessages(null, "Comparison failure at index "
+ i + " (a " + Classes.getShortClassName(actual[i]) + ").", e), e);
}
- assertEquals("Unexpected array length.", expected.length, actual.length);
+ assertEquals(expected.length, actual.length, "Unexpected array length.");
}
}
}
@@ -152,14 +152,15 @@ public final class Assertions extends Static {
final CharSequence[] expectedLines = CharSequences.splitOnEOL(expected);
final CharSequence[] actualLines = CharSequences.splitOnEOL(actual);
final int length = StrictMath.min(expectedLines.length, actualLines.length);
- final StringBuilder buffer = new StringBuilder(message != null ? message : "Line").append('[');
- final int base = buffer.length();
+ final var buffer = new StringBuilder(message != null ? message : "Line").append('[');
+ final int base = buffer.length();
for (int i=0; i<length; i++) {
+ buffer.append(i).append(']');
CharSequence e = expectedLines[i];
CharSequence a = actualLines[i];
e = e.subSequence(0, CharSequences.skipTrailingWhitespaces(e, 0, e.length()));
a = a.subSequence(0, CharSequences.skipTrailingWhitespaces(a, 0, a.length()));
- assertEquals(buffer.append(i).append(']').toString(), e, a);
+ assertEquals(e, a, () -> buffer.toString());
buffer.setLength(base);
}
if (expectedLines.length > actualLines.length) {
@@ -170,6 +171,22 @@ public final class Assertions extends Static {
}
}
+ /**
+ * Asserts that the message of the given exception contains all the given keywords.
+ * We do not test the exact exception message because it is locale-dependent.
+ * If the list of keywords is empty, then this method only verifies that the message is non-null.
+ *
+ * @param exception the exception for which to validate the message.
+ * @param keywords the keywords which should be present in the exception.
+ */
+ public static void assertMessageContains(final Throwable exception, final String... keywords) {
+ final String message = exception.getMessage();
+ assertNotNull(message, "Missing exception message.");
+ for (final String keyword : keywords) {
+ assertTrue(message.contains(keyword), () -> "Missing \"" + keyword + "\" in exception message: " + message);
+ }
+ }
+
/**
* Verifies that the given stream produces the same values than the given iterator, in same order.
* This method assumes that the given stream is sequential.
@@ -194,7 +211,7 @@ public final class Assertions extends Static {
count++;
}
});
- assertFalse("Unexpected end of stream.", expected.hasNext());
+ assertFalse(expected.hasNext(), "Unexpected end of stream.");
}
/**
@@ -249,15 +266,15 @@ public final class Assertions extends Static {
public static void assertSetEquals(final Collection<?> expected, final Collection<?> actual) {
if (expected != null && actual != null && !expected.isEmpty()) {
final Set<Object> r = new LinkedHashSet<>(expected);
- assertTrue("The two sets are disjoint.", r.removeAll(actual));
- assertTrue("The set is missing elements: " + r, r.isEmpty());
- assertTrue("The set unexpectedly became empty.", r.addAll(actual));
- assertTrue("The two sets are disjoint.", r.removeAll(expected));
- assertTrue("The set contains unexpected elements: " + r, r.isEmpty());
+ assertTrue(r.removeAll(actual), "The two sets are disjoint.");
+ assertTrue(r.isEmpty(), "The set is missing elements: " + r);
+ assertTrue(r.addAll(actual), "The set unexpectedly became empty.");
+ assertTrue(r.removeAll(expected), "The two sets are disjoint.");
+ assertTrue(r.isEmpty(), () -> "The set contains unexpected elements: " + r);
}
if (expected instanceof Set<?> && actual instanceof Set<?>) {
- assertEquals("Set.equals(Object) failed:", expected, actual);
- assertEquals("Unexpected hash code value.", expected.hashCode(), actual.hashCode());
+ assertEquals(expected, actual, "Set.equals(Object) failed:");
+ assertEquals(expected.hashCode(), actual.hashCode(), "Unexpected hash code value.");
}
}
@@ -301,7 +318,7 @@ public final class Assertions extends Static {
fail("The map contains unexpected elements:" + r);
}
}
- assertEquals("Map.equals(Object) failed:", expected, actual);
+ assertEquals(expected, actual, "Map.equals(Object) failed:");
}
/**
@@ -335,15 +352,14 @@ public final class Assertions extends Static {
} catch (IOException e) {
throw new AssertionError(e.toString(), e);
}
- assertNotNull("Deserialized object shall not be null.", deserialized);
+ assertNotNull(deserialized, "Deserialized object shall not be null.");
/*
* Compare with the original object and return it.
*/
@SuppressWarnings("unchecked")
final Class<? extends T> type = (Class<? extends T>) object.getClass();
- assertEquals("Deserialized object not equal to the original one.", object, deserialized);
- assertEquals("Deserialized object has a different hash code.",
- object.hashCode(), deserialized.hashCode());
+ assertEquals(object, deserialized, "Deserialized object not equal to the original one.");
+ assertEquals(object.hashCode(), deserialized.hashCode(), "Deserialized object has a different hash code.");
return type.cast(deserialized);
}
}
diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
index 785c30bff2..5ac0e7d620 100644
--- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
+++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
@@ -21,6 +21,7 @@ import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
+import static org.apache.sis.test.Assertions.assertMessageContains;
/**
@@ -41,14 +42,12 @@ public final class ArgumentChecksTest extends TestCase {
*/
@Test
public void testEnsureNonNullElement() {
- NullPointerException e = assertThrows(NullPointerException.class, () -> {
- ArgumentChecks.ensureNonNullElement("axes", 2, null);
- });
- assertTrue(e.getMessage().contains("axes[2]"));
- e = assertThrows(NullPointerException.class, () -> {
- ArgumentChecks.ensureNonNullElement("axes[#].unit", 2, null);
- });
- assertTrue(e.getMessage().contains("axes[2].unit"));
+ NullPointerException exception;
+ exception = assertThrows(NullPointerException.class, () -> ArgumentChecks.ensureNonNullElement("axes", 2, null));
+ assertMessageContains(exception, "axes[2]");
+
+ exception = assertThrows(NullPointerException.class, () -> ArgumentChecks.ensureNonNullElement("axes[#].unit", 2, null));
+ assertTrue(exception.getMessage().contains("axes[2].unit"));
}
/**
@@ -57,10 +56,9 @@ public final class ArgumentChecksTest extends TestCase {
@Test
public void testEnsureBetweenAndDistinct() {
ArgumentChecks.ensureNonEmptyBounded("dimensions", true, 0, 4, new int[] {2, 3, 0, 1});
- IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
- ArgumentChecks.ensureNonEmptyBounded("dimensions", true, 0, 4, new int[] {2, 3, 3, 1});
- });
- assertNotNull(e.getMessage());
+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
+ () -> ArgumentChecks.ensureNonEmptyBounded("dimensions", true, 0, 4, new int[] {2, 3, 3, 1}));
+ assertMessageContains(exception);
}
/**
@@ -70,17 +68,15 @@ public final class ArgumentChecksTest extends TestCase {
public void testEnsurePositive() {
ArgumentChecks.ensurePositive("length", 4d);
ArgumentChecks.ensurePositive("length", 0d);
- IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
- ArgumentChecks.ensurePositive("length", -4d);
- });
- assertTrue(e.getMessage().contains("length"));
- e = assertThrows(IllegalArgumentException.class, () -> {
- ArgumentChecks.ensurePositive("length", -0d);
- });
- assertTrue(e.getMessage().contains("length"));
- e = assertThrows(IllegalArgumentException.class, () -> {
- ArgumentChecks.ensurePositive("length", -0f);
- });
- assertTrue(e.getMessage().contains("length"));
+ IllegalArgumentException exception;
+
+ exception = assertThrows(IllegalArgumentException.class, () -> ArgumentChecks.ensurePositive("length", -4d));
+ assertMessageContains(exception, "length");
+
+ exception = assertThrows(IllegalArgumentException.class, () -> ArgumentChecks.ensurePositive("length", -0d));
+ assertMessageContains(exception, "length");
+
+ exception = assertThrows(IllegalArgumentException.class, () -> ArgumentChecks.ensurePositive("length", -0f));
+ assertMessageContains(exception, "length");
}
}
(sis) 01/04: Add a `MarshalContext.getDocumentURI()` method.
Posted by de...@apache.org.
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 95cdd7553d7a99413bd8f155c4d5dc978971e902
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Dec 26 11:28:58 2023 +0100
Add a `MarshalContext.getDocumentURI()` method.
---
.../main/org/apache/sis/xml/MarshalContext.java | 15 +++++-
.../main/org/apache/sis/xml/Pooled.java | 2 +-
.../main/org/apache/sis/xml/ReferenceResolver.java | 2 +-
.../main/org/apache/sis/xml/bind/Context.java | 9 ++++
.../apache/sis/xml/util/ExternalLinkHandler.java | 60 +++++++++++++---------
5 files changed, 61 insertions(+), 27 deletions(-)
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java
index c2454965ff..4509ff7470 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/MarshalContext.java
@@ -16,7 +16,9 @@
*/
package org.apache.sis.xml;
+import java.net.URI;
import java.util.Locale;
+import java.util.Optional;
import java.util.TimeZone;
import org.opengis.util.InternationalString;
import org.apache.sis.util.Localized;
@@ -103,5 +105,16 @@ public abstract class MarshalContext implements Localized {
* @param prefix one of the above-cited prefix.
* @return the version for the given schema, or {@code null} if unknown.
*/
- public abstract Version getVersion(final String prefix);
+ public abstract Version getVersion(String prefix);
+
+ /**
+ * Returns the URI of the document being (un)marshalled, if this URI is known.
+ * The URI is generally unknown if the source of the XML document is,
+ * for example, an {@link java.io.InputStream}.
+ *
+ * @return the URI of the document being marshalled or unmarshalled.
+ *
+ * @since 1.5
+ */
+ public abstract Optional<URI> getDocumentURI();
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java
index 3473dc7d1c..6bfc282ffd 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/Pooled.java
@@ -577,7 +577,7 @@ abstract class Pooled {
public String toString() {
final Context current = Context.current();
return Strings.toString(getClass(),
- "baseURI", Context.linkHandler(current).getURI(),
+ "baseURI", Context.linkHandler(current).getBase(),
"locale", locale, "timezone", timezone,
"versionGML", versionGML, "versionMetadata", versionMetadata);
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
index fc98dc2657..75a283c747 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
@@ -195,7 +195,7 @@ public class ReferenceResolver {
final ExternalLinkHandler handler = Context.linkHandler(c);
Source source = null;
if (externalSourceResolver != null) {
- Object base = handler.getURI();
+ Object base = handler.getBase();
if (base != null) {
source = externalSourceResolver.resolve(href.toString(), base.toString());
}
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java
index b4723f081c..85e11932f2 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/Context.java
@@ -23,6 +23,7 @@ import java.util.IdentityHashMap;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Collections;
+import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
@@ -380,6 +381,14 @@ public final class Context extends MarshalContext {
return null;
}
+ /**
+ * Returns the URI of the document being (un)marshalled, if this URI is known.
+ */
+ @Override
+ public final Optional<URI> getDocumentURI() {
+ return (linkHandler != null) ? Optional.ofNullable(linkHandler.getURI()) : Optional.empty();
+ }
+
diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java
index 06d85dd71e..6bd949f064 100644
--- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java
+++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/util/ExternalLinkHandler.java
@@ -119,10 +119,43 @@ public class ExternalLinkHandler {
* {@return the base URI of the link handler}. The returned object may be an instance of
* {@link String}, {@link File}, {@link URL} or {@link URI}, or it may be {@code null}.
*/
- public final Object getURI() {
+ public final Object getBase() {
return base;
}
+ /**
+ * {@return the base URI of the link handler}. This is the same value as {@link #getBase()},
+ * but converted to an {@link URI} object when first invoked.
+ */
+ public final URI getURI() {
+ final Object b = base;
+ if (b == null) {
+ return null;
+ }
+ final URI baseURI;
+ if (b instanceof URI) { // `instanceof` check of final classes are efficient.
+ baseURI = (URI) b;
+ } else {
+ base = null; // Clear first in case of failure, for avoiding to try again later.
+ try {
+ if (b instanceof String) {
+ baseURI = new URI((String) b);
+ } else if (b instanceof URL) {
+ baseURI = ((URL) b).toURI();
+ } else if (b instanceof File) {
+ baseURI = ((File) b).toURI();
+ } else {
+ return null;
+ }
+ } catch (URISyntaxException e) {
+ warningOccured(b, e);
+ return null;
+ }
+ base = baseURI;
+ }
+ return baseURI;
+ }
+
/**
* Resolves the given path as an URI. This method behaves as specified in {@link URI#resolve(URI)},
* with the URI given at construction-time as the base URI. If the given path is relative and there
@@ -134,29 +167,8 @@ public class ExternalLinkHandler {
* @see URI#resolve(URI)
*/
final URI resolve(final URI path) {
- final Object b = base;
-valid: if (b != null) {
- final URI baseURI;
- if (b instanceof URI) { // `instanceof` check of final classes are efficient.
- baseURI = (URI) b;
- } else {
- base = null; // Clear first in case of failure, for avoiding to try again later.
- try {
- if (b instanceof String) {
- baseURI = new URI((String) b);
- } else if (b instanceof URL) {
- baseURI = ((URL) b).toURI();
- } else if (b instanceof File) {
- baseURI = ((File) b).toURI();
- } else {
- break valid;
- }
- } catch (URISyntaxException e) {
- warningOccured(b, e);
- break valid;
- }
- base = baseURI;
- }
+ final URI baseURI = getURI();
+ if (baseURI != null) {
return baseURI.resolve(path);
}
return path.isAbsolute() ? path : null;
(sis) 04/04: Move 4 PMC members to emeritus. Three of them were already ASF emeritus, one of them has his status changed directly on LDAP.
Posted by de...@apache.org.
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 f35825c1dd824b27e9251dcf5f5bea958a5987d0
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 27 12:43:29 2023 +0100
Move 4 PMC members to emeritus. Three of them were already ASF emeritus, one of them has his status changed directly on LDAP.
---
parent/pom.xml | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/parent/pom.xml b/parent/pom.xml
index fe55d57c27..755907c9e2 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -162,8 +162,7 @@
<name>Gregory D. Reddin</name>
<id>greddin</id>
<roles>
- <role>PMC member</role>
- <role>mentor</role>
+ <role>PMC emeritus</role>
</roles>
</developer>
<developer>
@@ -244,7 +243,7 @@
<organization>AT&T Interactive</organization>
<timezone>-8</timezone>
<roles>
- <role>PMC member</role>
+ <role>PMC emeritus</role>
</roles>
</developer>
<developer>
@@ -256,7 +255,7 @@
<organizationUrl>https://www.jpl.nasa.gov</organizationUrl>
<timezone>-8</timezone>
<roles>
- <role>PMC member</role>
+ <role>PMC emeritus</role>
</roles>
</developer>
<developer>
@@ -305,7 +304,7 @@
<id>tlpinney</id>
<email>travis.pinney@gmail.com</email>
<roles>
- <role>PMC member</role>
+ <role>PMC emeritus</role>
</roles>
</developer>
</developers>