sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: One more attempt to fix platform-dependent line separator issue in tests.
Date Wed, 05 Jun 2019 09:46:17 GMT
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 b8e3a9b4df9d886b75c95220bf26f76aa015c55c
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jun 5 11:33:42 2019 +0200

    One more attempt to fix platform-dependent line separator issue in tests.
---
 .../java/org/apache/sis/console/CRSCommandTest.java | 21 +++++++++++++++++----
 .../java/org/apache/sis/util/CharSequences.java     | 12 ++++++------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
b/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
index 5c3aab9..bb562ae 100644
--- a/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
+++ b/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.console;
 
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -28,7 +29,7 @@ import static org.junit.Assert.*;
  * Tests the {@link CRSCommand} sub-command.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.8
  * @module
  */
@@ -39,7 +40,13 @@ public final strictfp class CRSCommandTest extends TestCase {
      * This string uses the native line separator. Consequently test cases comparing
      * against this pattern are expected to use that line separator for every lines.
      */
-    private final String WGS84 =
+    private String WGS84;
+
+    /**
+     * Creates a new test.
+     */
+    public CRSCommandTest() {
+        WGS84 =
             "\\QGeodeticCRS[\"WGS 84\",\n" +
             "  Datum[\"World Geodetic System 1984\",\n" +
             "    Ellipsoid[\"WGS 84\", 6378137.0, 298.257223563]],\n" +
@@ -50,8 +57,14 @@ public final strictfp class CRSCommandTest extends TestCase {
             "  Scope[\"Horizontal component of 3D system.\\E.*\\Q\"],\n" +              
       // EPSG geodetic dataset provides more details here.
             "  Area[\"\\E.*\\Q\"],\n" +                                                 
       // Language may vary because of SIS localization.
             "  BBox[-90.00, -180.00, 90.00, 180.00],\n" +
-            "  Id[\"EPSG\", 4326,\\E.*\\Q URI[\"urn:ogc:def:crs:EPSG:\\E.*\\Q:4326\"]]]\n\\E"
  // Version number of EPSG dataset may vary.
-            .replace("\n", System.lineSeparator());
+            "  Id[\"EPSG\", 4326,\\E.*\\Q URI[\"urn:ogc:def:crs:EPSG:\\E.*\\Q:4326\"]]]\n\\E";
 // Version number of EPSG dataset may vary.
+        /*
+         * Insert the native line separator in the expected string. We modify the expected
string
+         * instead than modifying the `test.outputBuffer` result because we want to verify
that the
+         * native line separator appears in every output lines.
+         */
+        WGS84 = CharSequences.replace(WGS84, "\n", System.lineSeparator()).toString();
+    }
 
     /**
      * Tests fetching the CRS from a simple code ({@code "EPSG:4326"}).
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java b/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
index df3629d..223dd63 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
@@ -2013,12 +2013,9 @@ cmp:    while (ia < lga) {
      * then this method returns the {@code text} unchanged.
      * Otherwise this method returns a new character sequence with all occurrences replaced
by {@code replaceBy}.
      *
-     * <p>This method is similar to {@link String#replace(CharSequence, CharSequence)}
except for the following:</p>
-     * <ul>
-     *   <li>This method accepts arbitrary {@code CharSequence} objects.</li>
-     *   <li>This method <strong>does not use regular expression</strong>.
-     *       The {@code toSearch} value is searched verbatim.</li>
-     * </ul>
+     * <p>This method is similar to {@link String#replace(CharSequence, CharSequence)}
except that is accepts
+     * arbitrary {@code CharSequence} objects. As of Java 10, another difference is that
this method does not
+     * create a new {@code String} if {@code toSearch} is equals to {@code replaceBy}.</p>
      *
      * @param  text       the character sequence in which to perform the replacements, or
{@code null}.
      * @param  toSearch   the string to replace.
@@ -2036,6 +2033,9 @@ cmp:    while (ia < lga) {
         ArgumentChecks.ensureNonEmpty("toSearch",  toSearch);
         ArgumentChecks.ensureNonNull ("replaceBy", replaceBy);
         if (text != null && !toSearch.equals(replaceBy)) {
+            if (text instanceof String) {
+                return ((String) text).replace(toSearch, replaceBy);
+            }
             final int length = text.length();
             int i = indexOf(text, toSearch, 0, length);
             if (i >= 0) {


Mime
View raw message