From 2029d67430016670d7e23a489e5eefec6b831c1b Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 8 Feb 2024 19:00:55 +0100 Subject: [PATCH 1/2] Do not adjust system property "line.separator" as it otherwise diverges from System.lineSeparator() Fix all test cases to use platform specific line separators --- .../maven/doxia/AbstractModuleTest.java | 12 ----- .../maven/doxia/module/apt/AptSinkTest.java | 16 +++--- .../doxia/module/xdoc/XdocParserTest.java | 10 ++-- .../maven/doxia/module/xdoc/XdocSinkTest.java | 27 +++++----- .../doxia/module/xhtml5/Xhtml5SinkTest.java | 54 ++++++++++--------- 5 files changed, 55 insertions(+), 64 deletions(-) diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java index 9a6611616..41092fc35 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java @@ -41,18 +41,6 @@ @PlexusTest public abstract class AbstractModuleTest implements Markup { - /* - * Set the system properties: - * - */ - static { - // Safety - System.setProperty("line.separator", "\n"); - } - // ---------------------------------------------------------------------- // Methods for creating test reader and writer // ---------------------------------------------------------------------- diff --git a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java index 3e23c073e..54cffbcf1 100644 --- a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java +++ b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java @@ -195,14 +195,14 @@ protected String getTableBlock(String cell, String caption) { @Override protected String getTableWithHeaderBlock(String... rowPrefixes) { - return "\n" - + "*----+--:--*\n" - + "|" + rowPrefixes[0] + "0||" + rowPrefixes[0] + "1||" + rowPrefixes[0] + "2|\n" - + "*----+--:--*\n" - + rowPrefixes[1] + "0|" + rowPrefixes[1] + "1|" + rowPrefixes[1] + "2|\n" - + "*----+--:--*\n" - + rowPrefixes[2] + "0|" + rowPrefixes[2] + "1|" + rowPrefixes[2] + "2|\n" - + "*----+--:--*\n"; + return EOL + + "*----+--:--*" + EOL + + "|" + rowPrefixes[0] + "0||" + rowPrefixes[0] + "1||" + rowPrefixes[0] + "2|" + EOL + + "*----+--:--*" + EOL + + rowPrefixes[1] + "0|" + rowPrefixes[1] + "1|" + rowPrefixes[1] + "2|" + EOL + + "*----+--:--*" + EOL + + rowPrefixes[2] + "0|" + rowPrefixes[2] + "1|" + rowPrefixes[2] + "2|" + EOL + + "*----+--:--*" + EOL; } /** {@inheritDoc} */ diff --git a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java index f8bff32ab..ed10107d4 100644 --- a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java +++ b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java @@ -406,11 +406,11 @@ public void testEntities() throws Exception { @Test public void testStyleWithCData() throws Exception { // DOXIA-449 - final String text = ""; SinkEventTestingSink sink = new SinkEventTestingSink(); diff --git a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java index de16c6afe..f25501f31 100644 --- a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java +++ b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java @@ -184,17 +184,17 @@ protected String getFooterBlock() { /** {@inheritDoc} */ protected String getListBlock(String item) { - return ""; + return ""; } /** {@inheritDoc} */ protected String getNumberedListBlock(String item) { - return "
    \n
  1. " + item + "
"; + return "
    " + EOL + "
  1. " + item + "
"; } /** {@inheritDoc} */ protected String getDefinitionListBlock(String definum, String definition) { - return "
\n
" + definum + "
\n
" + definition + "
"; + return "
" + EOL + "
" + definum + "
" + EOL + "
" + definition + "
"; } /** {@inheritDoc} */ @@ -209,20 +209,21 @@ protected String getFigureBlock(String source, String caption) { /** {@inheritDoc} */ protected String getTableBlock(String cell, String caption) { - return "\n\n
" + caption + "
" + cell - + "
"; + return "" + EOL + "" + EOL + + "
" + caption + "
" + cell + "
"; } @Override protected String getTableWithHeaderBlock(String... rowPrefixes) { - return "\n\n\n\n\n" - + "\n\n\n\n" - + "\n\n\n" + return "
" + rowPrefixes[0] + "0" + rowPrefixes[0] + "1" - + rowPrefixes[0] + "2
" + rowPrefixes[1] - + "0" + rowPrefixes[1] - + "1" + rowPrefixes[1] + "2
" + rowPrefixes[2] - + "0" + rowPrefixes[2] - + "1" + rowPrefixes[2] + "2
" + EOL + "" + EOL + "" + EOL + "" + EOL + "" + EOL + + "" + EOL + "" + EOL + "" + EOL + "" + EOL + + "" + EOL + "" + EOL + "" + EOL + "" + "
" + rowPrefixes[0] + "0" + + rowPrefixes[0] + "1" + + rowPrefixes[0] + "2
" + rowPrefixes[1] + + "0" + rowPrefixes[1] + + "1" + rowPrefixes[1] + "2
" + rowPrefixes[2] + + "0" + rowPrefixes[2] + + "1" + rowPrefixes[2] + "2
"; } diff --git a/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java b/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java index 875c246a1..c832e756b 100644 --- a/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java +++ b/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java @@ -95,8 +95,8 @@ protected String getDateBlock(String date) { /** {@inheritDoc} */ protected String getHeadBlock() { - return "" - + "\n\n\n"; + return "" + "" + EOL + "" + EOL + + "" + EOL + ""; } /** {@inheritDoc} */ @@ -126,32 +126,32 @@ protected String getSectionTitleBlock(String title) { /** {@inheritDoc} */ protected String getSection1Block(String title) { - return "
\n

" + title + "

"; + return "
" + EOL + "

" + title + "

"; } /** {@inheritDoc} */ protected String getSection2Block(String title) { - return "
\n

" + title + "

"; + return "
" + EOL + "

" + title + "

"; } /** {@inheritDoc} */ protected String getSection3Block(String title) { - return "
\n

" + title + "

"; + return "
" + EOL + "

" + title + "

"; } /** {@inheritDoc} */ protected String getSection4Block(String title) { - return "
\n

" + title + "

"; + return "
" + EOL + "

" + title + "

"; } /** {@inheritDoc} */ protected String getSection5Block(String title) { - return "
\n
" + title + "
"; + return "
" + EOL + "
" + title + "
"; } /** {@inheritDoc} */ protected String getSection6Block(String title) { - return "
\n
" + title + "
"; + return "
" + EOL + "
" + title + "
"; } /** {@inheritDoc} */ @@ -171,17 +171,17 @@ protected String getFooterBlock() { /** {@inheritDoc} */ protected String getListBlock(String item) { - return ""; + return ""; } /** {@inheritDoc} */ protected String getNumberedListBlock(String item) { - return "
    \n
  1. " + item + "
"; + return "
    " + EOL + "
  1. " + item + "
"; } /** {@inheritDoc} */ protected String getDefinitionListBlock(String definum, String definition) { - return "
\n
" + definum + "
\n
" + definition + "
"; + return "
" + EOL + "
" + definum + "
" + EOL + "
" + definition + "
"; } /** {@inheritDoc} */ @@ -197,24 +197,24 @@ protected String getFigureBlock(String source, String caption) { /** {@inheritDoc} */ protected String getTableBlock(String cell, String caption) { return "" - + "\n" + + "" + EOL + "" + "
Table caption
cell
Table caption
cell
"; } @Override protected String getTableWithHeaderBlock(String... rowPrefixes) { - return "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" + return "
" + rowPrefixes[0] + "0" + rowPrefixes[0] + "1" + rowPrefixes[0] + "2
" + rowPrefixes[1] + "0" + rowPrefixes[1] + "1" + rowPrefixes[1] + "2
" + rowPrefixes[2] + "0" + rowPrefixes[2] + "1
" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + + "" + EOL + "" + "
" + rowPrefixes[0] + "0" + rowPrefixes[0] + "1" + rowPrefixes[0] + "2
" + rowPrefixes[1] + "0" + rowPrefixes[1] + "1" + rowPrefixes[1] + "2
" + rowPrefixes[2] + "0" + rowPrefixes[2] + "1" + rowPrefixes[2] + "2
"; } @@ -367,7 +367,9 @@ public void testEntities() { sink.close(); } - assertEquals("
\n

&

\n

&

", writer.toString()); + assertEquals( + "
" + EOL + "

&

" + EOL + "

&

", + writer.toString()); } /** @@ -398,7 +400,7 @@ public void testHead() { } String expected = - "\nTitle" + "" + EOL + "Title" + ""; String actual = writer.toString(); assertTrue(actual.contains(expected), actual); From def9718aa23d384aef7dc85ba30051872f6534df Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Tue, 12 Mar 2024 20:01:25 +0100 Subject: [PATCH 2/2] some more cleanup --- .../main/java/org/apache/maven/doxia/markup/Markup.java | 4 ++-- .../java/org/apache/maven/doxia/AbstractModuleTest.java | 8 -------- .../apache/maven/doxia/sink/impl/AbstractSinkTest.java | 4 ++-- .../apache/maven/doxia/sink/impl/SinkTestDocument.java | 3 +-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java b/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java index 43722e5d1..553519815 100644 --- a/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java +++ b/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java @@ -26,8 +26,8 @@ */ @SuppressWarnings("checkstyle:interfaceistype") public interface Markup { - /** The vm line separator */ - String EOL = System.getProperty("line.separator"); + /** The OS dependent line separator */ + String EOL = System.lineSeparator(); // ---------------------------------------------------------------------- // Generic separator characters diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java index 41092fc35..53ed7fe3f 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/AbstractModuleTest.java @@ -83,14 +83,6 @@ protected Writer getXmlTestWriter(String baseName) throws IOException { return getXmlTestWriter(baseName, outputExtension()); } - protected static String normalizeLineEnds(String s) { - if (s != null) { - return s.replaceAll("\r\n", "\n").replaceAll("\r", "\n"); - } else { - return null; - } - } - /** * Returns an XML FileWriter to write to a file with the given name * in the test target output directory. diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java index e109bad15..1e3db271f 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java @@ -185,8 +185,8 @@ public void testHead() { sink.flush(); sink.close(); - String actual = normalizeLineEnds(testWriter.toString()); - String expected = normalizeLineEnds(getHeadBlock()); + String actual = testWriter.toString(); + String expected = getHeadBlock(); assertEquals(expected, actual, "Wrong head!"); } diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java index 35220f2a8..357476757 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/SinkTestDocument.java @@ -241,7 +241,6 @@ public static void generateNumberedList(Sink sink) { * @param sink The sink to receive the events. */ public static void generateDefinitionList(Sink sink) { - String eol = System.getProperty("line.separator"); sink.definitionList(); @@ -262,7 +261,7 @@ public static void generateDefinitionList(Sink sink) { sink.text("of definition list."); sink.verbatim(); sink.inline(SinkEventAttributeSet.Semantics.CODE); - sink.text("Verbatim source text" + eol + " in a box "); + sink.text("Verbatim source text" + System.lineSeparator() + " in a box "); sink.inline_(); sink.verbatim_(); sink.definition_();