sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1425044 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/io/ test/java/org/apache/sis/io/ test/java/org/apache/sis/test/suite/
Date Fri, 21 Dec 2012 17:40:12 GMT
Author: desruisseaux
Date: Fri Dec 21 17:40:11 2012
New Revision: 1425044

URL: http://svn.apache.org/viewvc?rev=1425044&view=rev
Log:
Bug fix in LineFormatter: last soft-hyphen on a line shall not be removed.
As a side effect of this bug fix, re-splitted the test case in various sub-classes.
This is a more classical JUnit approach than the previous "parameterized tests" approach.
We reverted to this classical approach because experience with this bug has show that the
"parameterized test" approach is unconvenient to debug.

Added:
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LeftMarginTest.java
      - copied, changed from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/TabulationExpansionTest.java
      - copied, changed from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapTest.java
      - copied, changed from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapWithLineSeparatorTest.java
      - copied, changed from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/FormatterTestCase.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java?rev=1425044&r1=1425043&r2=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java Fri Dec 21 17:40:11 2012
@@ -312,7 +312,7 @@ public class LineFormatter extends Filte
      */
     private void endOfLine() throws IOException {
         buffer.setLength(printableLength); // Reduce the amount of work for StringBuilder.deleteCharAt(int).
-        deleteSoftHyphen();
+        deleteSoftHyphen(printableLength - 1);
         transfer(printableLength);
         printableLength  = 0;
         codePointCount   = 0;
@@ -323,9 +323,13 @@ public class LineFormatter extends Filte
     /**
      * Removes the soft hyphen characters from the given buffer. This is invoked
      * when the buffer is about to be written without being split on two lines.
+     *
+     * @param i Index after the last character to check. This is either {@link printableLength}
+     *          for checking all characters, or {@code printableLength-1} for preserving the last
+     *          soft hyphen on the line (while removing all others).
      */
-    private void deleteSoftHyphen() {
-        for (int i=printableLength; --i >= 0;) {
+    private void deleteSoftHyphen(int i) {
+        while (--i >= 0) {
             if (buffer.charAt(i) == Characters.SOFT_HYPHEN) {
                 buffer.deleteCharAt(i);
                 printableLength--;
@@ -392,7 +396,7 @@ public class LineFormatter extends Filte
          */
         if (Character.isWhitespace(c)) {
             if (printableLength != 0) {
-                deleteSoftHyphen();
+                deleteSoftHyphen(printableLength);
                 transfer(printableLength);
                 printableLength = 0;
             }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/FormatterTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/FormatterTestCase.java?rev=1425044&r1=1425043&r2=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/FormatterTestCase.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/FormatterTestCase.java Fri Dec 21 17:40:11 2012
@@ -26,6 +26,7 @@ import static org.apache.sis.test.Assert
 
 /**
  * Base class for the testing {@code *Formatter} implementation.
+ * This is public because JUnit requires it, but should be considered as an implementation details.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
@@ -56,6 +57,29 @@ public abstract class FormatterTestCase 
     }
 
     /**
+     * Run the test. This method is where the test is actually performed.
+     * Implementations shall write in the {@link #formatter}, then test
+     * the result with {@link #assertOutputEquals(String)}.
+     *
+     * @param  lineSeparator The line separator to use.
+     * @throws IOException Should never happen.
+     */
+    abstract void run(final String lineSeparator) throws IOException;
+
+    /**
+     * Ensures that the buffer content is equals to the given string.
+     *
+     * @param  expected The expected content.
+     * @throws IOException Should never happen.
+     */
+    final void assertOutputEquals(final String expected) throws IOException {
+        IO.flush(formatter);
+        final String actual = buffer.toString();
+        assertMultilinesEquals("Ignoring line separators.", expected, actual);
+        assertEquals          ("Checking line separators.", expected, actual);
+    }
+
+    /**
      * Uses a formatter which will redirect every {@link Appendable#append(CharSequence)}
      * calls to a sequence of {@link Appendable#append(char)} calls.
      */
@@ -161,25 +185,4 @@ public abstract class FormatterTestCase 
     public void testSequencesWithUnicode() throws IOException {
         run("\u2028");
     }
-
-    /**
-     * Run the test.
-     *
-     * @param  lineSeparator The line separator to use.
-     * @throws IOException Should never happen.
-     */
-    abstract void run(final String lineSeparator) throws IOException;
-
-    /**
-     * Ensures that the buffer content is equals to the given string.
-     *
-     * @param expected The expected content.
-     * @throws IOException Should never happen.
-     */
-    final void assertOutputEquals(final String expected) throws IOException {
-        IO.flush(formatter);
-        final String actual = buffer.toString();
-        assertMultilinesEquals("Ignoring line separators.", expected, actual);
-        assertEquals          ("Checking line separators.", expected, actual);
-    }
 }

Copied: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LeftMarginTest.java (from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LeftMarginTest.java?p2=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LeftMarginTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java&r1=1424846&r2=1425044&rev=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LeftMarginTest.java Fri Dec 21 17:40:11 2012
@@ -16,245 +16,57 @@
  */
 package org.apache.sis.io;
 
-import java.util.List;
-import java.util.Arrays;
 import java.io.IOException;
 import org.apache.sis.test.DependsOn;
-import org.apache.sis.internal.util.X364;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.Before;
 
 import static org.junit.Assert.*;
-import static org.apache.sis.util.Characters.SOFT_HYPHEN;
 
 
 /**
- * Tests {@link LineFormatter} implementation. This class will run the {@link FormatterTestCase}
- * test methods many time, testing each time a different {@code LineFormatter} aspect identified
- * by the {@link Aspect} enumeration.
+ * Tests {@link LineFormatter} implementation when used for inserting a margin before every line.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
  * @module
+ *
+ * @see LineFormatter#onLineBegin(boolean)
  */
-@RunWith(Parameterized.class)
-@DependsOn({
-  org.apache.sis.util.CharSequencesTest.class,
-  org.apache.sis.internal.util.X364Test.class
-})
-public final strictfp class LineFormatterTest extends FormatterTestCase {
-    /**
-     * Returns all {@link LineFormatter} aspects to test. Each element of the returned list is
-     * the list of arguments given by JUnit to the {@linkplain #LineFormatterTest constructor}.
-     *
-     * @return All aspects to test.
-     */
-    @Parameterized.Parameters
-    public static List<Aspect[]> aspects() {
-        final Aspect[] aspects = Aspect.values();
-        final Aspect[][] args = new Aspect[aspects.length][];
-        for (int i=0; i<aspects.length; i++) {
-            args[i] = new Aspect[] {aspects[i]};
-        }
-        return Arrays.asList(args);
-    }
-
+@DependsOn(LineFormatterTest.class)
+public final strictfp class LeftMarginTest extends LineFormatterTest {
     /**
-     * The {@link LineFormatter} aspect being tested.
+     * Creates and configure the {@link LineFormatter} to test.
      */
-    private final Aspect aspect;
-
-    /**
-     * Creates a new test which will test the given aspect of {@link LineFormatter}.
-     *
-     * @param aspect The aspect to test.
-     */
-    public LineFormatterTest(final Aspect aspect) {
-        this.aspect = aspect;
-        formatter = aspect.create(formatter);
+    @Before
+    @Override
+    public void createLineFormatter() {
+        formatter = new LineFormatter(formatter) {
+            @Override
+            protected void onLineBegin(boolean isContinuation) throws IOException {
+                out.append("    ");
+            }
+        };
     }
 
     /**
-     * Runs the test.
+     * Runs the test using an extract from Arthur RIMBAUD (1854-1891), "Le bateau ivre".
      *
      * @param  lineSeparator The line separator to use in the test strings.
      * @throws IOException Should never happen, since we are writing in a {@link StringBuilder}.
      */
     @Override
     void run(final String lineSeparator) throws IOException {
-        final Appendable out = formatter;
-        if (out instanceof LineFormatter) {
-            aspect.preCondition((LineFormatter) out);
-        }
-        assertOutputEquals(aspect.run(out, lineSeparator));
+        final Appendable f = formatter;
+        assertSame(f, f.append("Comme je descendais des Fleuves impassibles,\r"
+                             + "Je ne me sentis plus guidé par les haleurs :\n"));
+        assertSame(f, f.append("Des Peaux-Rouges criards les avaient pris pour cibles,\r\n"));
+        assertSame(f, f.append("Les ayant cloués nus "));
+        assertSame(f, f.append("aux poteaux de couleurs." + lineSeparator));
+
+        assertOutputEquals("    Comme je descendais des Fleuves impassibles,"           + '\r'
+                         + "    Je ne me sentis plus guidé par les haleurs :"           + '\n'
+                         + "    Des Peaux-Rouges criards les avaient pris pour cibles," + "\r\n"
+                         + "    Les ayant cloués nus aux poteaux de couleurs."          + lineSeparator);
     }
-
-    /**
-     * The {@link LineFormatter} aspects to test.
-     *
-     * @author  Martin Desruisseaux (Geomatys)
-     * @since   0.3 (derived from geotk-3.00)
-     * @version 0.3
-     * @module
-     */
-    public static enum Aspect {
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for changing the line separator.
-         *
-         * @see LineFormatter#setLineSeparator(String)
-         */
-        LINE_SEPARATOR {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, " ", false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getLineSeparator", " ", out.getLineSeparator());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Le vrai" + lineSeparator + "policitien, "));
-                assertSame(out, out.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls.
-                assertSame(out, out.append("\narrive à garder " + lineSeparator));
-                assertSame(out, out.append("son\ridéal   " + lineSeparator + 't'));
-                assertSame(out, out.append("out en perdant"));
-                assertSame(out, out.append(lineSeparator + "ses illusions."));
-                return "Le vrai policitien, c'est celui qui arrive à garder son idéal tout en perdant ses illusions.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for expanding tabulations to spaces.
-         *
-         * @see LineFormatter#setTabulationExpanded(boolean)
-         */
-        TABULATION {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, null, true);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getTabWidth", 8, out.getTabulationWidth());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("12\t8"   + lineSeparator));
-                assertSame(out, out.append("1234\t8" + lineSeparator));
-                assertSame(out, out.append("A tabulation\tin the middle."));
-                return "12      8" + lineSeparator
-                     + "1234    8" + lineSeparator
-                     + "A tabulation    in the middle.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for wrapping lines to 80 characters.
-         *
-         * @see LineFormatter#setMaximalLineLength(int)
-         */
-        WORD_WRAP {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, 10, false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getMaximalLineLength", 10, out.getMaximalLineLength());
-            };
-
-            /*
-             * Extract from Émile Nelligan (1879-1941) with soft hyphen and X3.64 sequences added.
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                final String BLUE    = X364.FOREGROUND_BLUE   .sequence();
-                final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence();
-                assertSame(out, out.append("Ah! comme la " + BLUE + "neige" + DEFAULT + " a neigé!" + lineSeparator));
-                assertSame(out, out.append("Ma vitre est un jar" + SOFT_HYPHEN + "din de givre."    + lineSeparator));
-                /*
-                 * If our test case is using the wrapper which will send the data once character at time,
-                 * our LineFormatter implementation will not be able to detect the line separator and
-                 * will fallback on the default one. So we set the line separator to the one actually used
-                 * not because this is the class contract (quite the opposite, this is a limitation in our
-                 * implementation), but simply in order to allow the test to pass.
-                 */
-                String insertedLineSeparator = lineSeparator;
-                if (out instanceof SingleCharAppendable) {
-                    insertedLineSeparator = System.lineSeparator();
-                }
-                return "Ah! comme"                             + insertedLineSeparator
-                     + "la " + BLUE + "neige" + DEFAULT + " a" + insertedLineSeparator
-                     + "neigé!"                                +         lineSeparator
-                     + "Ma vitre"                              + insertedLineSeparator
-                     + "est un jar" + SOFT_HYPHEN              + insertedLineSeparator
-                     + "din de"                                + insertedLineSeparator
-                     + "givre."                                +         lineSeparator;
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for inserting a margin before every line.
-         *
-         * @see LineFormatter#onLineBegin(boolean)
-         */
-        ON_LINE_BEGIN {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out) {
-                    @Override
-                    protected void onLineBegin(boolean isContinuation) throws IOException {
-                        out.append("    ");
-                    }
-                };
-            }
-
-            /*
-             * Extract from Arthur RIMBAUD (1854-1891), "Le bateau ivre"
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Comme je descendais des Fleuves impassibles,\r"
-                                         + "Je ne me sentis plus guidé par les haleurs :\n"));
-                assertSame(out, out.append("Des Peaux-Rouges criards les avaient pris pour cibles,\r\n"));
-                assertSame(out, out.append("Les ayant cloués nus "));
-                assertSame(out, out.append("aux poteaux de couleurs." + lineSeparator));
-
-                return "    Comme je descendais des Fleuves impassibles,"           + '\r'
-                     + "    Je ne me sentis plus guidé par les haleurs :"           + '\n'
-                     + "    Des Peaux-Rouges criards les avaient pris pour cibles," + "\r\n"
-                     + "    Les ayant cloués nus aux poteaux de couleurs."          + lineSeparator;
-            }
-        };
-
-        /**
-         * Creates and configure the {@link LineFormatter} for the aspect to test.
-         */
-        abstract LineFormatter create(Appendable out);
-
-        /**
-         * Optionally test pre-conditions before to run the test.
-         */
-        void preCondition(LineFormatter formatter) {};
-
-        /**
-         * Appends string in the given buffer and returns the expected result.
-         *
-         * @param  out Where to append the string.
-         * @param  lineSeparator The line separator to insert in the test string.
-         * @return The expected result.
-         */
-        abstract String run(Appendable out, String lineSeparator) throws IOException;
-    };
 }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java?rev=1425044&r1=1425043&r2=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java Fri Dec 21 17:40:11 2012
@@ -16,63 +16,41 @@
  */
 package org.apache.sis.io;
 
-import java.util.List;
-import java.util.Arrays;
 import java.io.IOException;
 import org.apache.sis.test.DependsOn;
-import org.apache.sis.internal.util.X364;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.Before;
 
 import static org.junit.Assert.*;
-import static org.apache.sis.util.Characters.SOFT_HYPHEN;
 
 
 /**
- * Tests {@link LineFormatter} implementation. This class will run the {@link FormatterTestCase}
- * test methods many time, testing each time a different {@code LineFormatter} aspect identified
- * by the {@link Aspect} enumeration.
+ * Tests various aspects of {@link LineFormatter}.
+ * This base class tests {@code LineFormatter} when used for changing the line separator,
+ * which is a problematic involved in every tests. Subclasses will test other aspects.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
  * @module
  */
-@RunWith(Parameterized.class)
 @DependsOn({
   org.apache.sis.util.CharSequencesTest.class,
   org.apache.sis.internal.util.X364Test.class
 })
-public final strictfp class LineFormatterTest extends FormatterTestCase {
+public strictfp class LineFormatterTest extends FormatterTestCase {
     /**
-     * Returns all {@link LineFormatter} aspects to test. Each element of the returned list is
-     * the list of arguments given by JUnit to the {@linkplain #LineFormatterTest constructor}.
-     *
-     * @return All aspects to test.
+     * Creates a new test. Subclasses shall override the {@link #createLineFormatter()} method
+     * in order to create the instance to test.
      */
-    @Parameterized.Parameters
-    public static List<Aspect[]> aspects() {
-        final Aspect[] aspects = Aspect.values();
-        final Aspect[][] args = new Aspect[aspects.length][];
-        for (int i=0; i<aspects.length; i++) {
-            args[i] = new Aspect[] {aspects[i]};
-        }
-        return Arrays.asList(args);
+    public LineFormatterTest() {
     }
 
     /**
-     * The {@link LineFormatter} aspect being tested.
-     */
-    private final Aspect aspect;
-
-    /**
-     * Creates a new test which will test the given aspect of {@link LineFormatter}.
-     *
-     * @param aspect The aspect to test.
+     * Creates and configure the {@link LineFormatter} to test.
      */
-    public LineFormatterTest(final Aspect aspect) {
-        this.aspect = aspect;
-        formatter = aspect.create(formatter);
+    @Before
+    public void createLineFormatter() {
+        formatter = new LineFormatter(formatter, " ", false);
     }
 
     /**
@@ -83,178 +61,16 @@ public final strictfp class LineFormatte
      */
     @Override
     void run(final String lineSeparator) throws IOException {
-        final Appendable out = formatter;
-        if (out instanceof LineFormatter) {
-            aspect.preCondition((LineFormatter) out);
+        final Appendable f = formatter;
+        if (f instanceof LineFormatter) {
+            assertEquals("getLineSeparator", " ", ((LineFormatter) f).getLineSeparator());
         }
-        assertOutputEquals(aspect.run(out, lineSeparator));
+        assertSame(f, f.append("Le vrai" + lineSeparator + "policitien, "));
+        assertSame(f, f.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls.
+        assertSame(f, f.append("\narrive à garder " + lineSeparator));
+        assertSame(f, f.append("son\ridéal   " + lineSeparator + 't'));
+        assertSame(f, f.append("out en perdant"));
+        assertSame(f, f.append(lineSeparator + "ses illusions."));
+        assertOutputEquals("Le vrai policitien, c'est celui qui arrive à garder son idéal tout en perdant ses illusions.");
     }
-
-    /**
-     * The {@link LineFormatter} aspects to test.
-     *
-     * @author  Martin Desruisseaux (Geomatys)
-     * @since   0.3 (derived from geotk-3.00)
-     * @version 0.3
-     * @module
-     */
-    public static enum Aspect {
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for changing the line separator.
-         *
-         * @see LineFormatter#setLineSeparator(String)
-         */
-        LINE_SEPARATOR {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, " ", false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getLineSeparator", " ", out.getLineSeparator());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Le vrai" + lineSeparator + "policitien, "));
-                assertSame(out, out.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls.
-                assertSame(out, out.append("\narrive à garder " + lineSeparator));
-                assertSame(out, out.append("son\ridéal   " + lineSeparator + 't'));
-                assertSame(out, out.append("out en perdant"));
-                assertSame(out, out.append(lineSeparator + "ses illusions."));
-                return "Le vrai policitien, c'est celui qui arrive à garder son idéal tout en perdant ses illusions.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for expanding tabulations to spaces.
-         *
-         * @see LineFormatter#setTabulationExpanded(boolean)
-         */
-        TABULATION {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, null, true);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getTabWidth", 8, out.getTabulationWidth());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("12\t8"   + lineSeparator));
-                assertSame(out, out.append("1234\t8" + lineSeparator));
-                assertSame(out, out.append("A tabulation\tin the middle."));
-                return "12      8" + lineSeparator
-                     + "1234    8" + lineSeparator
-                     + "A tabulation    in the middle.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for wrapping lines to 80 characters.
-         *
-         * @see LineFormatter#setMaximalLineLength(int)
-         */
-        WORD_WRAP {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, 10, false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getMaximalLineLength", 10, out.getMaximalLineLength());
-            };
-
-            /*
-             * Extract from Émile Nelligan (1879-1941) with soft hyphen and X3.64 sequences added.
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                final String BLUE    = X364.FOREGROUND_BLUE   .sequence();
-                final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence();
-                assertSame(out, out.append("Ah! comme la " + BLUE + "neige" + DEFAULT + " a neigé!" + lineSeparator));
-                assertSame(out, out.append("Ma vitre est un jar" + SOFT_HYPHEN + "din de givre."    + lineSeparator));
-                /*
-                 * If our test case is using the wrapper which will send the data once character at time,
-                 * our LineFormatter implementation will not be able to detect the line separator and
-                 * will fallback on the default one. So we set the line separator to the one actually used
-                 * not because this is the class contract (quite the opposite, this is a limitation in our
-                 * implementation), but simply in order to allow the test to pass.
-                 */
-                String insertedLineSeparator = lineSeparator;
-                if (out instanceof SingleCharAppendable) {
-                    insertedLineSeparator = System.lineSeparator();
-                }
-                return "Ah! comme"                             + insertedLineSeparator
-                     + "la " + BLUE + "neige" + DEFAULT + " a" + insertedLineSeparator
-                     + "neigé!"                                +         lineSeparator
-                     + "Ma vitre"                              + insertedLineSeparator
-                     + "est un jar" + SOFT_HYPHEN              + insertedLineSeparator
-                     + "din de"                                + insertedLineSeparator
-                     + "givre."                                +         lineSeparator;
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for inserting a margin before every line.
-         *
-         * @see LineFormatter#onLineBegin(boolean)
-         */
-        ON_LINE_BEGIN {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out) {
-                    @Override
-                    protected void onLineBegin(boolean isContinuation) throws IOException {
-                        out.append("    ");
-                    }
-                };
-            }
-
-            /*
-             * Extract from Arthur RIMBAUD (1854-1891), "Le bateau ivre"
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Comme je descendais des Fleuves impassibles,\r"
-                                         + "Je ne me sentis plus guidé par les haleurs :\n"));
-                assertSame(out, out.append("Des Peaux-Rouges criards les avaient pris pour cibles,\r\n"));
-                assertSame(out, out.append("Les ayant cloués nus "));
-                assertSame(out, out.append("aux poteaux de couleurs." + lineSeparator));
-
-                return "    Comme je descendais des Fleuves impassibles,"           + '\r'
-                     + "    Je ne me sentis plus guidé par les haleurs :"           + '\n'
-                     + "    Des Peaux-Rouges criards les avaient pris pour cibles," + "\r\n"
-                     + "    Les ayant cloués nus aux poteaux de couleurs."          + lineSeparator;
-            }
-        };
-
-        /**
-         * Creates and configure the {@link LineFormatter} for the aspect to test.
-         */
-        abstract LineFormatter create(Appendable out);
-
-        /**
-         * Optionally test pre-conditions before to run the test.
-         */
-        void preCondition(LineFormatter formatter) {};
-
-        /**
-         * Appends string in the given buffer and returns the expected result.
-         *
-         * @param  out Where to append the string.
-         * @param  lineSeparator The line separator to insert in the test string.
-         * @return The expected result.
-         */
-        abstract String run(Appendable out, String lineSeparator) throws IOException;
-    };
 }

Copied: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/TabulationExpansionTest.java (from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/TabulationExpansionTest.java?p2=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/TabulationExpansionTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java&r1=1424846&r2=1425044&rev=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/TabulationExpansionTest.java Fri Dec 21 17:40:11 2012
@@ -16,63 +16,32 @@
  */
 package org.apache.sis.io;
 
-import java.util.List;
-import java.util.Arrays;
 import java.io.IOException;
 import org.apache.sis.test.DependsOn;
-import org.apache.sis.internal.util.X364;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.Before;
 
 import static org.junit.Assert.*;
-import static org.apache.sis.util.Characters.SOFT_HYPHEN;
 
 
 /**
- * Tests {@link LineFormatter} implementation. This class will run the {@link FormatterTestCase}
- * test methods many time, testing each time a different {@code LineFormatter} aspect identified
- * by the {@link Aspect} enumeration.
+ * Tests {@link LineFormatter} implementation when used for expanding tabulations to spaces.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
  * @module
+ *
+ * @see LineFormatter#setTabulationExpanded(boolean)
  */
-@RunWith(Parameterized.class)
-@DependsOn({
-  org.apache.sis.util.CharSequencesTest.class,
-  org.apache.sis.internal.util.X364Test.class
-})
-public final strictfp class LineFormatterTest extends FormatterTestCase {
-    /**
-     * Returns all {@link LineFormatter} aspects to test. Each element of the returned list is
-     * the list of arguments given by JUnit to the {@linkplain #LineFormatterTest constructor}.
-     *
-     * @return All aspects to test.
-     */
-    @Parameterized.Parameters
-    public static List<Aspect[]> aspects() {
-        final Aspect[] aspects = Aspect.values();
-        final Aspect[][] args = new Aspect[aspects.length][];
-        for (int i=0; i<aspects.length; i++) {
-            args[i] = new Aspect[] {aspects[i]};
-        }
-        return Arrays.asList(args);
-    }
-
+@DependsOn(LineFormatterTest.class)
+public final strictfp class TabulationExpansionTest extends LineFormatterTest {
     /**
-     * The {@link LineFormatter} aspect being tested.
+     * Creates and configure the {@link LineFormatter} to test.
      */
-    private final Aspect aspect;
-
-    /**
-     * Creates a new test which will test the given aspect of {@link LineFormatter}.
-     *
-     * @param aspect The aspect to test.
-     */
-    public LineFormatterTest(final Aspect aspect) {
-        this.aspect = aspect;
-        formatter = aspect.create(formatter);
+    @Before
+    @Override
+    public void createLineFormatter() {
+        formatter = new LineFormatter(formatter, null, true);
     }
 
     /**
@@ -83,178 +52,15 @@ public final strictfp class LineFormatte
      */
     @Override
     void run(final String lineSeparator) throws IOException {
-        final Appendable out = formatter;
-        if (out instanceof LineFormatter) {
-            aspect.preCondition((LineFormatter) out);
+        final Appendable f = formatter;
+        if (f instanceof LineFormatter) {
+            assertEquals("getTabWidth", 8, ((LineFormatter) f).getTabulationWidth());
         }
-        assertOutputEquals(aspect.run(out, lineSeparator));
+        assertSame(f, f.append("12\t8"   + lineSeparator));
+        assertSame(f, f.append("1234\t8" + lineSeparator));
+        assertSame(f, f.append("A tabulation\tin the middle."));
+        assertOutputEquals("12      8" + lineSeparator
+                         + "1234    8" + lineSeparator
+                         + "A tabulation    in the middle.");
     }
-
-    /**
-     * The {@link LineFormatter} aspects to test.
-     *
-     * @author  Martin Desruisseaux (Geomatys)
-     * @since   0.3 (derived from geotk-3.00)
-     * @version 0.3
-     * @module
-     */
-    public static enum Aspect {
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for changing the line separator.
-         *
-         * @see LineFormatter#setLineSeparator(String)
-         */
-        LINE_SEPARATOR {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, " ", false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getLineSeparator", " ", out.getLineSeparator());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Le vrai" + lineSeparator + "policitien, "));
-                assertSame(out, out.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls.
-                assertSame(out, out.append("\narrive à garder " + lineSeparator));
-                assertSame(out, out.append("son\ridéal   " + lineSeparator + 't'));
-                assertSame(out, out.append("out en perdant"));
-                assertSame(out, out.append(lineSeparator + "ses illusions."));
-                return "Le vrai policitien, c'est celui qui arrive à garder son idéal tout en perdant ses illusions.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for expanding tabulations to spaces.
-         *
-         * @see LineFormatter#setTabulationExpanded(boolean)
-         */
-        TABULATION {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, null, true);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getTabWidth", 8, out.getTabulationWidth());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("12\t8"   + lineSeparator));
-                assertSame(out, out.append("1234\t8" + lineSeparator));
-                assertSame(out, out.append("A tabulation\tin the middle."));
-                return "12      8" + lineSeparator
-                     + "1234    8" + lineSeparator
-                     + "A tabulation    in the middle.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for wrapping lines to 80 characters.
-         *
-         * @see LineFormatter#setMaximalLineLength(int)
-         */
-        WORD_WRAP {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, 10, false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getMaximalLineLength", 10, out.getMaximalLineLength());
-            };
-
-            /*
-             * Extract from Émile Nelligan (1879-1941) with soft hyphen and X3.64 sequences added.
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                final String BLUE    = X364.FOREGROUND_BLUE   .sequence();
-                final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence();
-                assertSame(out, out.append("Ah! comme la " + BLUE + "neige" + DEFAULT + " a neigé!" + lineSeparator));
-                assertSame(out, out.append("Ma vitre est un jar" + SOFT_HYPHEN + "din de givre."    + lineSeparator));
-                /*
-                 * If our test case is using the wrapper which will send the data once character at time,
-                 * our LineFormatter implementation will not be able to detect the line separator and
-                 * will fallback on the default one. So we set the line separator to the one actually used
-                 * not because this is the class contract (quite the opposite, this is a limitation in our
-                 * implementation), but simply in order to allow the test to pass.
-                 */
-                String insertedLineSeparator = lineSeparator;
-                if (out instanceof SingleCharAppendable) {
-                    insertedLineSeparator = System.lineSeparator();
-                }
-                return "Ah! comme"                             + insertedLineSeparator
-                     + "la " + BLUE + "neige" + DEFAULT + " a" + insertedLineSeparator
-                     + "neigé!"                                +         lineSeparator
-                     + "Ma vitre"                              + insertedLineSeparator
-                     + "est un jar" + SOFT_HYPHEN              + insertedLineSeparator
-                     + "din de"                                + insertedLineSeparator
-                     + "givre."                                +         lineSeparator;
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for inserting a margin before every line.
-         *
-         * @see LineFormatter#onLineBegin(boolean)
-         */
-        ON_LINE_BEGIN {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out) {
-                    @Override
-                    protected void onLineBegin(boolean isContinuation) throws IOException {
-                        out.append("    ");
-                    }
-                };
-            }
-
-            /*
-             * Extract from Arthur RIMBAUD (1854-1891), "Le bateau ivre"
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Comme je descendais des Fleuves impassibles,\r"
-                                         + "Je ne me sentis plus guidé par les haleurs :\n"));
-                assertSame(out, out.append("Des Peaux-Rouges criards les avaient pris pour cibles,\r\n"));
-                assertSame(out, out.append("Les ayant cloués nus "));
-                assertSame(out, out.append("aux poteaux de couleurs." + lineSeparator));
-
-                return "    Comme je descendais des Fleuves impassibles,"           + '\r'
-                     + "    Je ne me sentis plus guidé par les haleurs :"           + '\n'
-                     + "    Des Peaux-Rouges criards les avaient pris pour cibles," + "\r\n"
-                     + "    Les ayant cloués nus aux poteaux de couleurs."          + lineSeparator;
-            }
-        };
-
-        /**
-         * Creates and configure the {@link LineFormatter} for the aspect to test.
-         */
-        abstract LineFormatter create(Appendable out);
-
-        /**
-         * Optionally test pre-conditions before to run the test.
-         */
-        void preCondition(LineFormatter formatter) {};
-
-        /**
-         * Appends string in the given buffer and returns the expected result.
-         *
-         * @param  out Where to append the string.
-         * @param  lineSeparator The line separator to insert in the test string.
-         * @return The expected result.
-         */
-        abstract String run(Appendable out, String lineSeparator) throws IOException;
-    };
 }

Copied: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapTest.java (from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapTest.java?p2=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java&r1=1424846&r2=1425044&rev=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapTest.java Fri Dec 21 17:40:11 2012
@@ -16,245 +16,81 @@
  */
 package org.apache.sis.io;
 
-import java.util.List;
-import java.util.Arrays;
 import java.io.IOException;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.internal.util.X364;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.Before;
 
 import static org.junit.Assert.*;
 import static org.apache.sis.util.Characters.SOFT_HYPHEN;
 
 
 /**
- * Tests {@link LineFormatter} implementation. This class will run the {@link FormatterTestCase}
- * test methods many time, testing each time a different {@code LineFormatter} aspect identified
- * by the {@link Aspect} enumeration.
+ * Tests {@link LineFormatter} implementation when used for wrapping lines to 80 characters.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
  * @module
+ *
+ * @see LineFormatter#setMaximalLineLength(int)
  */
-@RunWith(Parameterized.class)
-@DependsOn({
-  org.apache.sis.util.CharSequencesTest.class,
-  org.apache.sis.internal.util.X364Test.class
-})
-public final strictfp class LineFormatterTest extends FormatterTestCase {
+@DependsOn(LineFormatterTest.class)
+public strictfp class WordWrapTest extends LineFormatterTest {
     /**
-     * Returns all {@link LineFormatter} aspects to test. Each element of the returned list is
-     * the list of arguments given by JUnit to the {@linkplain #LineFormatterTest constructor}.
-     *
-     * @return All aspects to test.
+     * Creates and configure the {@link LineFormatter} to test.
      */
-    @Parameterized.Parameters
-    public static List<Aspect[]> aspects() {
-        final Aspect[] aspects = Aspect.values();
-        final Aspect[][] args = new Aspect[aspects.length][];
-        for (int i=0; i<aspects.length; i++) {
-            args[i] = new Aspect[] {aspects[i]};
-        }
-        return Arrays.asList(args);
+    @Before
+    @Override
+    public void createLineFormatter() {
+        formatter = new LineFormatter(formatter, 10, false);
     }
 
     /**
-     * The {@link LineFormatter} aspect being tested.
-     */
-    private final Aspect aspect;
-
-    /**
-     * Creates a new test which will test the given aspect of {@link LineFormatter}.
-     *
-     * @param aspect The aspect to test.
+     * Returns the line separator expected by this test. The default implementation returns
+     * the given line separator unchanged. The {@link WordWrapWithLineSeparatorTest} subclass
+     * override this method with a hard-coded line separator.
      */
-    public LineFormatterTest(final Aspect aspect) {
-        this.aspect = aspect;
-        formatter = aspect.create(formatter);
+    String expectedLineSeparator(final String lineSeparator) {
+        return lineSeparator;
     }
 
     /**
-     * Runs the test.
+     * Runs the test using an extract from Émile Nelligan (1879-1941)
+     * with soft hyphen and X3.64 sequences added.
      *
      * @param  lineSeparator The line separator to use in the test strings.
      * @throws IOException Should never happen, since we are writing in a {@link StringBuilder}.
      */
     @Override
     void run(final String lineSeparator) throws IOException {
-        final Appendable out = formatter;
-        if (out instanceof LineFormatter) {
-            aspect.preCondition((LineFormatter) out);
+        final Appendable f = formatter;
+        if (f instanceof LineFormatter) {
+            assertEquals("getMaximalLineLength", 10, ((LineFormatter) f).getMaximalLineLength());
+        }
+        final String BLUE    = X364.FOREGROUND_BLUE   .sequence();
+        final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence();
+        assertSame(f, f.append("Ah! comme la " + BLUE + "neige" + DEFAULT + " a neigé!" + lineSeparator));
+        assertSame(f, f.append("Ma vitre est un jar" + SOFT_HYPHEN + "din de givre."    + lineSeparator));
+        /*
+         * If our test case is using the wrapper which will send the data once character at time,
+         * our LineFormatter implementation will not be able to detect the line separator and
+         * will fallback on the default one. So we set the line separator to the one actually used
+         * not because this is the class contract (quite the opposite, this is a limitation in our
+         * implementation), but simply in order to allow the test to pass.
+         */
+        String insertedLineSeparator = lineSeparator;
+        if (f instanceof SingleCharAppendable) {
+            insertedLineSeparator = System.lineSeparator();
         }
-        assertOutputEquals(aspect.run(out, lineSeparator));
+        insertedLineSeparator = expectedLineSeparator(insertedLineSeparator);
+        final String expectedLineSeparator = expectedLineSeparator(lineSeparator);
+        assertOutputEquals("Ah! comme"                             + insertedLineSeparator
+                         + "la " + BLUE + "neige" + DEFAULT + " a" + insertedLineSeparator
+                         + "neigé!"                                + expectedLineSeparator
+                         + "Ma vitre"                              + insertedLineSeparator
+                         + "est un jar" + SOFT_HYPHEN              + insertedLineSeparator
+                         + "din de"                                + insertedLineSeparator
+                         + "givre."                                + expectedLineSeparator);
     }
-
-    /**
-     * The {@link LineFormatter} aspects to test.
-     *
-     * @author  Martin Desruisseaux (Geomatys)
-     * @since   0.3 (derived from geotk-3.00)
-     * @version 0.3
-     * @module
-     */
-    public static enum Aspect {
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for changing the line separator.
-         *
-         * @see LineFormatter#setLineSeparator(String)
-         */
-        LINE_SEPARATOR {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, " ", false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getLineSeparator", " ", out.getLineSeparator());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Le vrai" + lineSeparator + "policitien, "));
-                assertSame(out, out.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls.
-                assertSame(out, out.append("\narrive à garder " + lineSeparator));
-                assertSame(out, out.append("son\ridéal   " + lineSeparator + 't'));
-                assertSame(out, out.append("out en perdant"));
-                assertSame(out, out.append(lineSeparator + "ses illusions."));
-                return "Le vrai policitien, c'est celui qui arrive à garder son idéal tout en perdant ses illusions.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for expanding tabulations to spaces.
-         *
-         * @see LineFormatter#setTabulationExpanded(boolean)
-         */
-        TABULATION {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, null, true);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getTabWidth", 8, out.getTabulationWidth());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("12\t8"   + lineSeparator));
-                assertSame(out, out.append("1234\t8" + lineSeparator));
-                assertSame(out, out.append("A tabulation\tin the middle."));
-                return "12      8" + lineSeparator
-                     + "1234    8" + lineSeparator
-                     + "A tabulation    in the middle.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for wrapping lines to 80 characters.
-         *
-         * @see LineFormatter#setMaximalLineLength(int)
-         */
-        WORD_WRAP {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, 10, false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getMaximalLineLength", 10, out.getMaximalLineLength());
-            };
-
-            /*
-             * Extract from Émile Nelligan (1879-1941) with soft hyphen and X3.64 sequences added.
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                final String BLUE    = X364.FOREGROUND_BLUE   .sequence();
-                final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence();
-                assertSame(out, out.append("Ah! comme la " + BLUE + "neige" + DEFAULT + " a neigé!" + lineSeparator));
-                assertSame(out, out.append("Ma vitre est un jar" + SOFT_HYPHEN + "din de givre."    + lineSeparator));
-                /*
-                 * If our test case is using the wrapper which will send the data once character at time,
-                 * our LineFormatter implementation will not be able to detect the line separator and
-                 * will fallback on the default one. So we set the line separator to the one actually used
-                 * not because this is the class contract (quite the opposite, this is a limitation in our
-                 * implementation), but simply in order to allow the test to pass.
-                 */
-                String insertedLineSeparator = lineSeparator;
-                if (out instanceof SingleCharAppendable) {
-                    insertedLineSeparator = System.lineSeparator();
-                }
-                return "Ah! comme"                             + insertedLineSeparator
-                     + "la " + BLUE + "neige" + DEFAULT + " a" + insertedLineSeparator
-                     + "neigé!"                                +         lineSeparator
-                     + "Ma vitre"                              + insertedLineSeparator
-                     + "est un jar" + SOFT_HYPHEN              + insertedLineSeparator
-                     + "din de"                                + insertedLineSeparator
-                     + "givre."                                +         lineSeparator;
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for inserting a margin before every line.
-         *
-         * @see LineFormatter#onLineBegin(boolean)
-         */
-        ON_LINE_BEGIN {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out) {
-                    @Override
-                    protected void onLineBegin(boolean isContinuation) throws IOException {
-                        out.append("    ");
-                    }
-                };
-            }
-
-            /*
-             * Extract from Arthur RIMBAUD (1854-1891), "Le bateau ivre"
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Comme je descendais des Fleuves impassibles,\r"
-                                         + "Je ne me sentis plus guidé par les haleurs :\n"));
-                assertSame(out, out.append("Des Peaux-Rouges criards les avaient pris pour cibles,\r\n"));
-                assertSame(out, out.append("Les ayant cloués nus "));
-                assertSame(out, out.append("aux poteaux de couleurs." + lineSeparator));
-
-                return "    Comme je descendais des Fleuves impassibles,"           + '\r'
-                     + "    Je ne me sentis plus guidé par les haleurs :"           + '\n'
-                     + "    Des Peaux-Rouges criards les avaient pris pour cibles," + "\r\n"
-                     + "    Les ayant cloués nus aux poteaux de couleurs."          + lineSeparator;
-            }
-        };
-
-        /**
-         * Creates and configure the {@link LineFormatter} for the aspect to test.
-         */
-        abstract LineFormatter create(Appendable out);
-
-        /**
-         * Optionally test pre-conditions before to run the test.
-         */
-        void preCondition(LineFormatter formatter) {};
-
-        /**
-         * Appends string in the given buffer and returns the expected result.
-         *
-         * @param  out Where to append the string.
-         * @param  lineSeparator The line separator to insert in the test string.
-         * @return The expected result.
-         */
-        abstract String run(Appendable out, String lineSeparator) throws IOException;
-    };
 }

Copied: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapWithLineSeparatorTest.java (from r1424846, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapWithLineSeparatorTest.java?p2=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapWithLineSeparatorTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java&r1=1424846&r2=1425044&rev=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/WordWrapWithLineSeparatorTest.java Fri Dec 21 17:40:11 2012
@@ -16,245 +16,37 @@
  */
 package org.apache.sis.io;
 
-import java.util.List;
-import java.util.Arrays;
-import java.io.IOException;
+import org.junit.Before;
 import org.apache.sis.test.DependsOn;
-import org.apache.sis.internal.util.X364;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import static org.junit.Assert.*;
-import static org.apache.sis.util.Characters.SOFT_HYPHEN;
 
 
 /**
- * Tests {@link LineFormatter} implementation. This class will run the {@link FormatterTestCase}
- * test methods many time, testing each time a different {@code LineFormatter} aspect identified
- * by the {@link Aspect} enumeration.
+ * Tests {@link LineFormatter} implementation when used for wrapping lines to 80 characters,
+ * chained with another {@code LineFormatter}. Such chaining should not be needed since a
+ * single {@code LineFormatter} can handle many operations. But if such situation happens
+ * anyway, we want it to work.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
  * @version 0.3
  * @module
  */
-@RunWith(Parameterized.class)
-@DependsOn({
-  org.apache.sis.util.CharSequencesTest.class,
-  org.apache.sis.internal.util.X364Test.class
-})
-public final strictfp class LineFormatterTest extends FormatterTestCase {
+@DependsOn(WordWrapTest.class)
+public final strictfp class WordWrapWithLineSeparatorTest extends WordWrapTest {
     /**
-     * Returns all {@link LineFormatter} aspects to test. Each element of the returned list is
-     * the list of arguments given by JUnit to the {@linkplain #LineFormatterTest constructor}.
-     *
-     * @return All aspects to test.
+     * Creates and configure the {@link LineFormatter} to test.
      */
-    @Parameterized.Parameters
-    public static List<Aspect[]> aspects() {
-        final Aspect[] aspects = Aspect.values();
-        final Aspect[][] args = new Aspect[aspects.length][];
-        for (int i=0; i<aspects.length; i++) {
-            args[i] = new Aspect[] {aspects[i]};
-        }
-        return Arrays.asList(args);
-    }
-
-    /**
-     * The {@link LineFormatter} aspect being tested.
-     */
-    private final Aspect aspect;
-
-    /**
-     * Creates a new test which will test the given aspect of {@link LineFormatter}.
-     *
-     * @param aspect The aspect to test.
-     */
-    public LineFormatterTest(final Aspect aspect) {
-        this.aspect = aspect;
-        formatter = aspect.create(formatter);
+    @Before
+    @Override
+    public void createLineFormatter() {
+        formatter = new LineFormatter(new LineFormatter(formatter, "\r", false), 10, false);
     }
 
     /**
-     * Runs the test.
-     *
-     * @param  lineSeparator The line separator to use in the test strings.
-     * @throws IOException Should never happen, since we are writing in a {@link StringBuilder}.
+     * Returns the line separator used by this test.
      */
     @Override
-    void run(final String lineSeparator) throws IOException {
-        final Appendable out = formatter;
-        if (out instanceof LineFormatter) {
-            aspect.preCondition((LineFormatter) out);
-        }
-        assertOutputEquals(aspect.run(out, lineSeparator));
+    String expectedLineSeparator(final String lineSeparator) {
+        return "\r";
     }
-
-    /**
-     * The {@link LineFormatter} aspects to test.
-     *
-     * @author  Martin Desruisseaux (Geomatys)
-     * @since   0.3 (derived from geotk-3.00)
-     * @version 0.3
-     * @module
-     */
-    public static enum Aspect {
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for changing the line separator.
-         *
-         * @see LineFormatter#setLineSeparator(String)
-         */
-        LINE_SEPARATOR {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, " ", false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getLineSeparator", " ", out.getLineSeparator());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Le vrai" + lineSeparator + "policitien, "));
-                assertSame(out, out.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls.
-                assertSame(out, out.append("\narrive à garder " + lineSeparator));
-                assertSame(out, out.append("son\ridéal   " + lineSeparator + 't'));
-                assertSame(out, out.append("out en perdant"));
-                assertSame(out, out.append(lineSeparator + "ses illusions."));
-                return "Le vrai policitien, c'est celui qui arrive à garder son idéal tout en perdant ses illusions.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for expanding tabulations to spaces.
-         *
-         * @see LineFormatter#setTabulationExpanded(boolean)
-         */
-        TABULATION {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, null, true);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getTabWidth", 8, out.getTabulationWidth());
-            };
-
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("12\t8"   + lineSeparator));
-                assertSame(out, out.append("1234\t8" + lineSeparator));
-                assertSame(out, out.append("A tabulation\tin the middle."));
-                return "12      8" + lineSeparator
-                     + "1234    8" + lineSeparator
-                     + "A tabulation    in the middle.";
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for wrapping lines to 80 characters.
-         *
-         * @see LineFormatter#setMaximalLineLength(int)
-         */
-        WORD_WRAP {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out, 10, false);
-            }
-
-            @Override
-            void preCondition(LineFormatter out) {
-                assertEquals("getMaximalLineLength", 10, out.getMaximalLineLength());
-            };
-
-            /*
-             * Extract from Émile Nelligan (1879-1941) with soft hyphen and X3.64 sequences added.
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                final String BLUE    = X364.FOREGROUND_BLUE   .sequence();
-                final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence();
-                assertSame(out, out.append("Ah! comme la " + BLUE + "neige" + DEFAULT + " a neigé!" + lineSeparator));
-                assertSame(out, out.append("Ma vitre est un jar" + SOFT_HYPHEN + "din de givre."    + lineSeparator));
-                /*
-                 * If our test case is using the wrapper which will send the data once character at time,
-                 * our LineFormatter implementation will not be able to detect the line separator and
-                 * will fallback on the default one. So we set the line separator to the one actually used
-                 * not because this is the class contract (quite the opposite, this is a limitation in our
-                 * implementation), but simply in order to allow the test to pass.
-                 */
-                String insertedLineSeparator = lineSeparator;
-                if (out instanceof SingleCharAppendable) {
-                    insertedLineSeparator = System.lineSeparator();
-                }
-                return "Ah! comme"                             + insertedLineSeparator
-                     + "la " + BLUE + "neige" + DEFAULT + " a" + insertedLineSeparator
-                     + "neigé!"                                +         lineSeparator
-                     + "Ma vitre"                              + insertedLineSeparator
-                     + "est un jar" + SOFT_HYPHEN              + insertedLineSeparator
-                     + "din de"                                + insertedLineSeparator
-                     + "givre."                                +         lineSeparator;
-            }
-        },
-
-        /**
-         * Tests the {@link LineFormatter} implementation
-         * when used for inserting a margin before every line.
-         *
-         * @see LineFormatter#onLineBegin(boolean)
-         */
-        ON_LINE_BEGIN {
-            @Override
-            LineFormatter create(final Appendable out) {
-                return new LineFormatter(out) {
-                    @Override
-                    protected void onLineBegin(boolean isContinuation) throws IOException {
-                        out.append("    ");
-                    }
-                };
-            }
-
-            /*
-             * Extract from Arthur RIMBAUD (1854-1891), "Le bateau ivre"
-             */
-            @Override
-            String run(final Appendable out, final String lineSeparator) throws IOException {
-                assertSame(out, out.append("Comme je descendais des Fleuves impassibles,\r"
-                                         + "Je ne me sentis plus guidé par les haleurs :\n"));
-                assertSame(out, out.append("Des Peaux-Rouges criards les avaient pris pour cibles,\r\n"));
-                assertSame(out, out.append("Les ayant cloués nus "));
-                assertSame(out, out.append("aux poteaux de couleurs." + lineSeparator));
-
-                return "    Comme je descendais des Fleuves impassibles,"           + '\r'
-                     + "    Je ne me sentis plus guidé par les haleurs :"           + '\n'
-                     + "    Des Peaux-Rouges criards les avaient pris pour cibles," + "\r\n"
-                     + "    Les ayant cloués nus aux poteaux de couleurs."          + lineSeparator;
-            }
-        };
-
-        /**
-         * Creates and configure the {@link LineFormatter} for the aspect to test.
-         */
-        abstract LineFormatter create(Appendable out);
-
-        /**
-         * Optionally test pre-conditions before to run the test.
-         */
-        void preCondition(LineFormatter formatter) {};
-
-        /**
-         * Appends string in the given buffer and returns the expected result.
-         *
-         * @param  out Where to append the string.
-         * @param  lineSeparator The line separator to insert in the test string.
-         * @return The expected result.
-         */
-        abstract String run(Appendable out, String lineSeparator) throws IOException;
-    };
 }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1425044&r1=1425043&r2=1425044&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java Fri Dec 21 17:40:11 2012
@@ -72,6 +72,10 @@ import org.junit.runners.Suite;
     org.apache.sis.measure.AngleTest.class,
     org.apache.sis.internal.util.X364Test.class,
     org.apache.sis.io.LineFormatterTest.class,
+    org.apache.sis.io.LeftMarginTest.class,
+    org.apache.sis.io.TabulationExpansionTest.class,
+    org.apache.sis.io.WordWrapTest.class,
+    org.apache.sis.io.WordWrapWithLineSeparatorTest.class,
     org.apache.sis.io.TableFormatterTest.class,
     org.apache.sis.util.collection.TreeTableFormatTest.class,
 



Mime
View raw message