Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.After;

import java.io.*;
import java.util.regex.Matcher;

import static org.junit.Assert.fail;

Expand Down Expand Up @@ -59,13 +60,13 @@ protected File getSnippetFileName(File directory, String name) {
}

protected String createFooter() {
return "</section>\n";
return String.format("</section>%n");
}

protected String createHeader() {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE section PUBLIC \"-//OASIS//DTD DocBook XML V4.4//EN\" \"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd\">\n" +
"<section>\n";
return String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" +
"<!DOCTYPE section PUBLIC \"-//OASIS//DTD DocBook XML V4.4//EN\" \"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd\">%n" +
"<section>%n");
}

protected String createTitle() {
Expand All @@ -81,10 +82,10 @@ protected String createText() {
}

protected String createSnippet() {
return String.format("<example>\n" +
" <title>%s</title>\n" +
" <programlisting language=\"java\"><![CDATA[%s]]></programlisting>\n" +
" </example>\n", snippetTitle, collectSnippet());
return String.format("<example>%n" +
" <title>%s</title>%n" +
" <programlisting language=\"java\"><![CDATA[%s]]></programlisting>%n" +
" </example>%n", snippetTitle, collectSnippet());
}

protected String collectSnippet() {
Expand All @@ -99,7 +100,7 @@ protected String collectSnippet() {
continue;
}
if (inSnippet) {
snippetText.append(line).append("\n");
snippetText.append(line).append(String.format("%n"));
}
}
reader.close();
Expand All @@ -110,7 +111,7 @@ protected String collectSnippet() {
}

protected File getJavaFile() {
final String javaFileName = getClass().getName().replaceAll("\\.", File.separator) + ".java";
final String javaFileName = getClass().getName().replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".java";
final File javaFile = new File(testSourceDirectory(), javaFileName);
if (!javaFile.exists()) fail("Snippet File " + javaFile + " does not exist ");
return javaFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public class DocumentingTestBaseTest extends DocumentingTestBase {

@Test
public void testTitle() {
assertEquals("<title>Documents DocumentingTestBase</title>\n",createTitle());
assertEquals(String.format("<title>Documents DocumentingTestBase</title>%n"),createTitle());
}
@Test
public void testParagraphs() {
assertEquals("<para>\nThis documents the documenting test base\n</para>\n"+
"<para>\nAnd this is a second paragraph\n</para>\n"
assertEquals(String.format("<para>%nThis documents the documenting test base%n</para>%n"+
"<para>%nAnd this is a second paragraph%n</para>%n")
,createText());
}
@Test
public void testCreateSnippet() {
assertEquals(" {\n" +
" title=\"Documents DocumentingTestBase\";\n" +
" }\n" +
" snippetTitle = \"SnippetTitle\";\n",collectSnippet());
assertEquals(String.format(" {%n" +
" title=\"Documents DocumentingTestBase\";%n" +
" }%n" +
" snippetTitle = \"SnippetTitle\";%n"),collectSnippet());
}
}