sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1569812 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/referencing/crs/ sis-referencing/src/test/java/org/apache/sis/referencing/crs/ sis-utility/src/test/java/o...
Date Wed, 19 Feb 2014 16:27:24 GMT
Author: desruisseaux
Date: Wed Feb 19 16:27:23 2014
New Revision: 1569812

URL: http://svn.apache.org/r1569812
Log:
Fix indentation of PrimeMeridian and Axis in WKT 2 formatting.
assertMultilineEquals(...) does not ignore anymore the leading spaces (i.e. the indentation).
Fix tests accordingly.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/test/AssertTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -456,11 +456,13 @@ public class Formatter implements Locali
     }
 
     /**
-     * Increase or reduce the indentation. A value of {@code +1} increase
+     * Increases or decreases the indentation. A value of {@code +1} increases
      * the indentation by the amount of spaces specified at construction time,
-     * and a value of {@code -1} reduce it.
+     * and a value of {@code -1} reduces it by the same amount.
+     *
+     * @param amount +1 for increasing the indentation, or -1 for decreasing it, or 0 for
no-op.
      */
-    private void indent(final int amount) {
+    public void indent(final int amount) {
         margin = Math.max(0, margin + indentation*amount);
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -433,6 +433,7 @@ public class AbstractCRS extends Abstrac
             }
         } else {
             formatter.append(cs); // The concept of CoordinateSystem was not explicit in
WKT 1.
+            formatter.indent(+1);
         }
         final int dimension = cs.getDimension();
         for (int i=0; i<dimension; i++) {
@@ -442,6 +443,7 @@ public class AbstractCRS extends Abstrac
         if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them before axes.
             formatter.newLine();
             formatter.append(unit);
+            formatter.indent(-1);
         }
         formatter.removeContextualUnit(unit);
         formatter.addContextualUnit(oldUnit);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -218,12 +218,12 @@ public class DefaultGeocentricCRS extend
      *   GeodeticCRS["Geocentric",
      *     Datum["World Geodetic System 1984",
      *       Ellipsoid["WGS84", 6378137.0, 298.257223563, LengthUnit["metre", 1]]],
-     *     PrimeMeridian["Greenwich", 0.0, AngleUnit["degree", 0.017453292519943295]],
+     *       PrimeMeridian["Greenwich", 0.0, AngleUnit["degree", 0.017453292519943295]],
      *     CS["Cartesian", 3],
-     *     Axis["(X)", geocentricX],
-     *     Axis["(Y)", geocentricY],
-     *     Axis["(Z)", geocentricZ],
-     *     LengthUnit["metre", 1]]
+     *       Axis["(X)", geocentricX],
+     *       Axis["(Y)", geocentricY],
+     *       Axis["(Z)", geocentricZ],
+     *       LengthUnit["metre", 1]]
      * }
      *
      * <p>Same coordinate reference system using WKT 1. Note that axis directions are
totally different.</p>

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -173,7 +173,9 @@ class DefaultGeodeticCRS extends Abstrac
         formatter.newLine();
         formatter.append(datum);
         formatter.newLine();
+        formatter.indent(isWKT1 ? 0 : +1);
         formatter.append(datum.getPrimeMeridian());
+        formatter.indent(isWKT1 ? 0 : -1);
         formatter.newLine();
         CoordinateSystem cs = super.getCoordinateSystem();
         if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes them after axes.
@@ -196,6 +198,7 @@ class DefaultGeodeticCRS extends Abstrac
             }
         } else {
             formatter.append(cs); // The concept of CoordinateSystem was not explicit in
WKT 1.
+            formatter.indent(+1);
         }
         final int dimension = cs.getDimension();
         for (int i=0; i<dimension; i++) {
@@ -205,6 +208,7 @@ class DefaultGeodeticCRS extends Abstrac
         if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them before axes.
             formatter.newLine();
             formatter.append(unit);
+            formatter.indent(-1);
         }
         formatter.removeContextualUnit(unit);
         formatter.addContextualUnit(oldUnit);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -199,7 +199,7 @@ public class DefaultGeographicCRS extend
      *   GeodeticCRS["WGS 84",
      *      Datum["World Geodetic System 1984",
      *        Ellipsoid["WGS84", 6378137.0, 298.257223563, LengthUnit["metre", 1]]],
-     *      PrimeMeridian["Greenwich", 0.0, AngleUnit["degree", 0.017453292519943295]],
+     *        PrimeMeridian["Greenwich", 0.0, AngleUnit["degree", 0.017453292519943295]],
      *      CS["ellipsoidal", 2],
      *        Axis["Latitude", north],
      *        Axis["Longitude", east],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -179,7 +179,7 @@ public final strictfp class DefaultCompo
                 "  GeodeticCRS[“WGS 84”,\n" +
                 "    Datum[“World Geodetic System 1984”,\n" +
                 "      Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”,
1]]],\n" +
-                "    PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
+                "      PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
                 "    CS[“ellipsoidal”, 2],\n" +
                 "      Axis[“Longitude (λ)”, east],\n" +
                 "      Axis[“Latitude (φ)”, north],\n" +

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -69,12 +69,12 @@ public final strictfp class DefaultGeoce
                 "GeodeticCRS[“Geocentric”,\n" +
                 "  Datum[“World Geodetic System 1984”,\n" +
                 "    Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”,
1]]],\n" +
-                "  PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
+                "    PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
                 "  CS[“Cartesian”, 3],\n" +
-                "  Axis[“(X)”, geocentricX],\n" +
-                "  Axis[“(Y)”, geocentricY],\n" +
-                "  Axis[“(Z)”, geocentricZ],\n" +
-                "  LengthUnit[“metre”, 1]]",
+                "    Axis[“(X)”, geocentricX],\n" +
+                "    Axis[“(Y)”, geocentricY],\n" +
+                "    Axis[“(Z)”, geocentricZ],\n" +
+                "    LengthUnit[“metre”, 1]]",
                 HardCodedCRS.GEOCENTRIC);
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -112,7 +112,7 @@ public final strictfp class DefaultGeogr
                 "GeodeticCRS[“WGS 84”,\n" +
                 "  Datum[“World Geodetic System 1984”,\n" +
                 "    Ellipsoid[“WGS84”, 6378137.0, 298.257223563, LengthUnit[“metre”,
1]]],\n" +
-                "  PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
+                "    PrimeMeridian[“Greenwich”, 0.0, AngleUnit[“degree”, 0.017453292519943295]],\n"
+
                 "  CS[“ellipsoidal”, 2],\n" +
                 "    Axis[“Longitude (λ)”, east],\n" +
                 "    Axis[“Latitude (φ)”, north],\n" +
@@ -125,7 +125,7 @@ public final strictfp class DefaultGeogr
                 "GeodeticCRS[“WGS 84”,\n" +
                 "  Datum[“World Geodetic System 1984”,\n" +
                 "    Ellipsoid[“WGS84”, 6378137.0, 298.257223563]],\n" +
-                "  PrimeMeridian[“Greenwich”, 0.0],\n" +
+                "    PrimeMeridian[“Greenwich”, 0.0],\n" +
                 "  CS[“ellipsoidal”, 2],\n" +
                 "    Axis[“Longitude (λ)”, east],\n" +
                 "    Axis[“Latitude (φ)”, north],\n" +
@@ -139,7 +139,7 @@ public final strictfp class DefaultGeogr
                 "  Datum[“World Geodetic System 1984”,\n" +
                 "    Ellipsoid[“WGS84”, 6378137.0, 298.257223563],\n" +
                 "    Id[“EPSG”, 6326]],\n" +
-                "  PrimeMeridian[“Greenwich”, 0.0, Id[“EPSG”, 8901]],\n" +
+                "    PrimeMeridian[“Greenwich”, 0.0, Id[“EPSG”, 8901]],\n" +
                 "  CS[“ellipsoidal”, 2],\n" +
                 "    Axis[“Geodetic longitude (λ)”, east],\n" +
                 "    Axis[“Geodetic latitude (φ)”, north],\n" +

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultVerticalCRSTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -56,8 +56,8 @@ public final strictfp class DefaultVerti
                 "VerticalCRS[“Depth”,\n" +
                 "  VerticalDatum[“Mean Sea Level”],\n" +
                 "  CS[“vertical”, 1],\n" +
-                "  Axis[“Depth (D)”, down],\n" +
-                "  LengthUnit[“metre”, 1]]",
+                "    Axis[“Depth (D)”, down],\n" +
+                "    LengthUnit[“metre”, 1]]",
                 HardCodedCRS.DEPTH);
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -58,7 +58,7 @@ public final strictfp class ConverterReg
      * All converters registered in a test case. Only the converter type and properties
      * will be verified; no conversion or serialization shall be attempted.
      */
-    private Deque<ObjectConverter<?,?>> converters = new ArrayDeque<>();
+    private final Deque<ObjectConverter<?,?>> converters = new ArrayDeque<>();
 
     /**
      * Registers a converter to test.

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/test/AssertTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/test/AssertTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/test/AssertTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/test/AssertTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -36,8 +36,22 @@ public final strictfp class AssertTest e
      */
     @Test
     public void testAssertEqualsMultilines() {
+        // Without trailing spaces.
         assertMultilinesEquals("Line 1\nLine 2\r\nLine 3\n\rLine 5",
                                "Line 1\rLine 2\nLine 3\n\nLine 5");
+
+        // With different trailing spaces.
+        assertMultilinesEquals("Line 1\nLine 2\r\nLine 3\n\rLine 5",
+                               "Line 1\rLine 2\nLine 3\n\nLine 5  ");
+
+        // With different leading spaces.
+        try {
+            assertMultilinesEquals("Line 1\nLine 2\r\nLine 3\n\rLine 5",
+                                   "Line 1\rLine 2\n  Line 3\n\nLine 5");
+            fail("Lines are not equal.");
+        } catch (AssertionError e) {
+            assertTrue(e.getMessage().startsWith("Line[2]"));
+        }
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java [UTF-8]
Wed Feb 19 16:27:23 2014
@@ -100,29 +100,45 @@ public strictfp class Assert extends org
 
     /**
      * Asserts that two strings are equal, ignoring the differences in EOL characters.
-     * The comparisons is performed one a line-by-line basis. For each line, leading
-     * and trailing spaces are ignored in order to make the comparison independent of
-     * indentation.
+     * The comparisons is performed one a line-by-line basis. For each line, trailing
+     * spaces (but not leading spaces) are ignored.
      *
      * @param expected The expected string.
      * @param actual   The actual string.
      */
     public static void assertMultilinesEquals(final CharSequence expected, final CharSequence
actual) {
-        assertArrayEquals(CharSequences.split(expected, '\n'), CharSequences.split(actual,
'\n'));
+        assertMultilinesEquals(null, expected, actual);
     }
 
     /**
      * Asserts that two strings are equal, ignoring the differences in EOL characters.
-     * The comparisons is performed one a line-by-line basis. For each line, leading
-     * and trailing spaces are ignored in order to make the comparison independent of
-     * indentation.
+     * The comparisons is performed one a line-by-line basis. For each line, trailing
+     * spaces (but not leading spaces) are ignored.
      *
      * @param message  The message to print in case of failure, or {@code null} if none.
      * @param expected The expected string.
      * @param actual   The actual string.
      */
     public static void assertMultilinesEquals(final String message, final CharSequence expected,
final CharSequence actual) {
-        assertArrayEquals(message, CharSequences.split(expected, '\n'), CharSequences.split(actual,
'\n'));
+        final CharSequence[] expectedLines = CharSequences.splitOnEOL(expected);
+        final CharSequence[] actualLines   = CharSequences.splitOnEOL(actual);
+        final int length = Math.min(expectedLines.length, actualLines.length);
+        final StringBuilder buffer = new StringBuilder(message != null ? message : "Line").append('[');
+        final int base = buffer.length();
+        for (int i=0; i<length; i++) {
+            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);
+            buffer.setLength(base);
+        }
+        if (expectedLines.length > actualLines.length) {
+            fail(buffer.append(length).append("] missing line: ").append(expectedLines[length]).toString());
+        }
+        if (expectedLines.length < actualLines.length) {
+            fail(buffer.append(length).append("] extraneous line: ").append(actualLines[length]).toString());
+        }
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java?rev=1569812&r1=1569811&r2=1569812&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
[UTF-8] Wed Feb 19 16:27:23 2014
@@ -58,10 +58,19 @@ public final strictfp class MonolineForm
      * The given string shall use tabulation before each line of the message.
      */
     private static String localize(final Level level, final String expected) {
-        final String label = level.getLocalizedName();
-        CharSequence text = CharSequences.replace(expected, level.getName(), label);
-        text = CharSequences.replace(text, "\t", CharSequences.spaces(MonolineFormatter.levelWidth(null)
- label.length()));
-        return text.toString();
+        final String levelToReplace = level.getName();
+        final String levelLocalized = level.getLocalizedName();
+        assertTrue(expected, expected.startsWith(levelToReplace));
+        final int margin = MonolineFormatter.levelWidth(null);
+        final StringBuilder buffer = new StringBuilder(expected.length() + 40)
+                .append(levelLocalized)
+                .append(CharSequences.spaces(margin - levelLocalized.length()))
+                .append(expected, levelToReplace.length() + 1, expected.length()); // +1
is for skipping '\t'.
+        final String spaces = CharSequences.spaces(margin).toString();
+        for (int i=margin; (i=buffer.indexOf("\n\t", i)) >= 0; i += margin) {
+            buffer.replace(++i, i+1, spaces); // Replace only tabulation, leave new line.
+        }
+        return buffer.toString();
     }
 
     /**
@@ -74,8 +83,8 @@ public final strictfp class MonolineForm
         final String formatted = formatter.format(record);
         assertMultilinesEquals(localize(Level.INFO,
                 "INFO\t First line\n" +
-                "    \t   Indented line\n" +
-                "    \t Last line\n"), formatted);
+                    "\t   Indented line\n" +
+                    "\t Last line\n"), formatted);
     }
 
     /**
@@ -94,9 +103,9 @@ public final strictfp class MonolineForm
         String formatted = formatter.format(record);
         assertMultilinesEquals(localize(Level.WARNING,
                 "WARNING\t An exception occured.\n" +
-                "       \t   Caused by: java.lang.Exception\n" +
-                "       \t     at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n"
+
-                "       \t     at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted);
+                       "\t Caused by: java.lang.Exception\n" +
+                       "\t     at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n"
+
+                       "\t     at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted);
         /*
          * Remove the message and try again.
          */
@@ -104,7 +113,7 @@ public final strictfp class MonolineForm
         formatted = formatter.format(record);
         assertMultilinesEquals(localize(Level.WARNING,
                 "WARNING\t java.lang.Exception\n" +
-                "       \t     at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n"
+
-                "       \t     at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted);
+                       "\t     at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n"
+
+                       "\t     at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted);
     }
 }



Mime
View raw message