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 a511c4dec5cb8fd428e3d74b48401f5af7a0b695
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Mar 25 10:58:50 2021 +0100

    Fix tests which was timezone-dependent.
---
 .../src/main/java/org/apache/sis/measure/RangeFormat.java   |  2 +-
 .../test/java/org/apache/sis/measure/RangeFormatTest.java   | 13 ++++++++++---
 .../src/test/java/org/apache/sis/measure/RangeTest.java     | 12 +++++++++---
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java 
b/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
index cb21a87..bef9d1c 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
@@ -336,7 +336,7 @@ public class RangeFormat extends Format implements 
Localized {
      * using the given locale and timezone.
      *
      * @param locale    the locale for parsing and formatting range components.
-     * @param timezone  the timezone for the date to be formatted.
+     * @param timezone  the timezone for the dates to be formatted.
      */
     public RangeFormat(final Locale locale, final TimeZone timezone) {
         this(locale, Date.class);
diff --git 
a/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java 
b/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
index ba197fa..74fc29e 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
@@ -309,12 +309,16 @@ public final strictfp class RangeFormatTest extends 
TestCase {
      */
     @Test
     public void testFormatLocalDate() {
-        format = new RangeFormat(Locale.CANADA_FRENCH, LocalDate.class);
+        format = new RangeFormat(Locale.CANADA, LocalDate.class);
         final Range<LocalDate> range = new Range<>(LocalDate.class,
                 LocalDate.parse("2019-12-23"), true,
                 LocalDate.parse("2020-05-31"), true);
-
-        assertEquals("[2019-12-23 … 2020-05-31]", format.format(range));
+        /*
+         * Expected output is "[2019-12-23 … 2020-05-31]" but be robust
+         * to small variation in output format (years may be on 2 digits).
+         */
+        final String result = format.format(range);
+        assertTrue(result, result.matches("\\[(20)?19-12-23 … 
(20)?20-05-31\\]"));
     }
 
     /**
@@ -332,10 +336,13 @@ public final strictfp class RangeFormatTest extends 
TestCase {
 
     /**
      * Tests formatting a range of {@link Instant} objects.
+     *
+     * @see RangeTest#testFormatInstantTo()
      */
     @Test
     public void testFormatInstant() {
         format = new RangeFormat(Locale.FRANCE, Instant.class);
+        ((DateFormat) 
format.elementFormat).setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
         final Range<Instant> range = new Range<>(Instant.class,
                 Instant.parse("2019-12-23T06:00:00Z"), true,
                 Instant.parse("2020-05-31T18:00:00Z"), true);
diff --git 
a/core/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java 
b/core/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java
index d0732e3..409a4bc 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/measure/RangeTest.java
@@ -326,14 +326,20 @@ public final strictfp class RangeTest extends TestCase {
 
     /**
      * Tests the {@link Range#formatTo(Formatter, int, int, int)} method with 
a range of instants.
+     *
+     * @see RangeFormatTest#testFormatInstant()
      */
     @Test
     public void testFormatInstantTo() {
         final Range<Instant> range = new Range<>(Instant.class,
                 Instant.parse("2019-12-23T06:00:00Z"), true,
-                Instant.parse("2020-05-31T18:00:00Z"), true);
-
-        assertEquals("[23/12/2019 07:00 … 31/05/2020 20:00]", 
String.format(Locale.FRANCE, "%s", range));
+                Instant.parse("2020-05-14T18:00:00Z"), true);
+        /*
+         * The result depends on time zone and we have no API for forcing the 
time zone to some specific
+         * value in a call to 'Range.formatTo(Formatter, …)`. So we verify 
only the year and the month.
+         */
+        final String result = String.format(Locale.CANADA, "%s", range);
+        assertTrue(result, result.matches("\\[2019-12-.+ … 2020-05-.+\\]"));
     }
 
     /**

Reply via email to