", w.toString());
}
- private void writeXhtmlHead( XMLWriter writer ) throws IOException
- {
- writer.startElement( HTML.Tag.HEAD.toString() );
- writer.startElement( HTML.Tag.TITLE.toString() );
- writer.writeText( "title" );
+ private void writeXhtmlHead(XMLWriter writer) throws IOException {
+ writer.startElement(HTML.Tag.HEAD.toString());
+ writer.startElement(HTML.Tag.TITLE.toString());
+ writer.writeText("title");
writer.endElement(); // Tag.TITLE
- writer.startElement( HTML.Tag.META.toString() );
- writer.addAttribute( "name", "author" );
- writer.addAttribute( "content", "Author" );
+ writer.startElement(HTML.Tag.META.toString());
+ writer.addAttribute("name", "author");
+ writer.addAttribute("content", "Author");
writer.endElement(); // Tag.META
- writer.startElement( HTML.Tag.META.toString() );
- writer.addAttribute( "name", "date" );
- writer.addAttribute( "content", "Date" );
+ writer.startElement(HTML.Tag.META.toString());
+ writer.addAttribute("name", "date");
+ writer.addAttribute("content", "Date");
writer.endElement(); // Tag.META
writer.endElement(); // Tag.HEAD
}
- private void writeXhtmlBody( XMLWriter writer ) throws IOException
- {
- writer.startElement( HTML.Tag.BODY.toString() );
- writer.startElement( HTML.Tag.P.toString() );
- writer.writeText( "Paragraph 1, line 1. Paragraph 1, line 2." );
+ private void writeXhtmlBody(XMLWriter writer) throws IOException {
+ writer.startElement(HTML.Tag.BODY.toString());
+ writer.startElement(HTML.Tag.P.toString());
+ writer.writeText("Paragraph 1, line 1. Paragraph 1, line 2.");
writer.endElement(); // Tag.P
- writer.startElement( HTML.Tag.DIV.toString() );
- writer.addAttribute( "class", "section" );
- writer.startElement( HTML.Tag.H2.toString() );
- writer.writeText( "Section title" );
+ writer.startElement(HTML.Tag.DIV.toString());
+ writer.addAttribute("class", "section");
+ writer.startElement(HTML.Tag.H2.toString());
+ writer.writeText("Section title");
writer.endElement(); // Tag.H2
writer.endElement(); // Tag.DIV
writer.endElement(); // Tag.BODY
}
- private static String expectedResult()
- {
- return expectedResult( " " );
+ private static String expectedResult() {
+ return expectedResult(" ");
}
- private static String expectedResult( String lineIndenter )
- {
-
+ private static String expectedResult(String lineIndenter) {
+
String lineSeparator = "\n";
StringBuilder expected = new StringBuilder();
- expected.append( "" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "
title" )
- .append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 2 ) )
- .append( "
" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "
" )
- .append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 2 ) )
- .append( "
Paragraph 1, line 1. Paragraph 1, line 2.
" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "
" )
- .append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 3 ) ).append( "
Section title
" )
- .append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "" ).append( lineSeparator );
- expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator );
- expected.append( "" );
+ expected.append("").append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 2))
+ .append("
title")
+ .append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 2))
+ .append("
")
+ .append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 2))
+ .append("
")
+ .append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 2))
+ .append("
Paragraph 1, line 1. Paragraph 1, line 2.
")
+ .append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 2))
+ .append("
")
+ .append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 3))
+ .append("
Section title
")
+ .append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 2)).append("").append(lineSeparator);
+ expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator);
+ expected.append("");
return expected.toString();
}
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java b/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java
index 433e5feb..5566ef94 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.utils.xml;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,23 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.utils.xml;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
-import org.apache.maven.shared.utils.StringUtils;
-import org.apache.maven.shared.utils.WriterFactory;
import junit.framework.TestCase;
+import org.apache.maven.shared.utils.StringUtils;
+import org.apache.maven.shared.utils.WriterFactory;
/**
* @author
Vincent Siveton
*
*/
-public class XmlWriterUtilTest
- extends TestCase
-{
+public class XmlWriterUtilTest extends TestCase {
private OutputStream output;
private Writer writer;
@@ -42,14 +39,12 @@ public class XmlWriterUtilTest
private XMLWriter xmlWriter;
/** {@inheritDoc} */
- protected void setUp()
- throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
output = new ByteArrayOutputStream();
- writer = WriterFactory.newXmlWriter( output );
- xmlWriter = new PrettyPrintXMLWriter( writer );
+ writer = WriterFactory.newXmlWriter(output);
+ xmlWriter = new PrettyPrintXMLWriter(writer);
}
/**
@@ -57,12 +52,10 @@ protected void setUp()
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriter()
- throws Exception
- {
- XmlWriterUtil.writeLineBreak( xmlWriter );
+ public void testWriteLineBreakXMLWriter() throws Exception {
+ XmlWriterUtil.writeLineBreak(xmlWriter);
writer.close();
- assertEquals( 1, StringUtils.countMatches( output.toString(), "\r\n" ) );
+ assertEquals(1, StringUtils.countMatches(output.toString(), "\r\n"));
}
/**
@@ -70,12 +63,10 @@ public void testWriteLineBreakXMLWriter()
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriterInt()
- throws Exception
- {
- XmlWriterUtil.writeLineBreak( xmlWriter, 10 );
+ public void testWriteLineBreakXMLWriterInt() throws Exception {
+ XmlWriterUtil.writeLineBreak(xmlWriter, 10);
writer.close();
- assertEquals( 10, StringUtils.countMatches( output.toString(), "\r\n" ) );
+ assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n"));
}
/**
@@ -83,14 +74,14 @@ public void testWriteLineBreakXMLWriterInt()
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriterIntInt()
- throws Exception
- {
- XmlWriterUtil.writeLineBreak( xmlWriter, 10, 2 );
+ public void testWriteLineBreakXMLWriterIntInt() throws Exception {
+ XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2);
writer.close();
- assertEquals( 10, StringUtils.countMatches( output.toString(), "\r\n" ) );
- assertEquals( 1, StringUtils.countMatches( output.toString(), StringUtils
- .repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ) ) );
+ assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n"));
+ assertEquals(
+ 1,
+ StringUtils.countMatches(
+ output.toString(), StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE)));
}
/**
@@ -98,13 +89,11 @@ public void testWriteLineBreakXMLWriterIntInt()
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriterIntIntInt()
- throws Exception
- {
- XmlWriterUtil.writeLineBreak( xmlWriter, 10, 2, 4 );
+ public void testWriteLineBreakXMLWriterIntIntInt() throws Exception {
+ XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2, 4);
writer.close();
- assertEquals( 10, StringUtils.countMatches( output.toString(), "\r\n" ) );
- assertEquals( 1, StringUtils.countMatches( output.toString(), StringUtils.repeat( " ", 2 * 4 ) ) );
+ assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n"));
+ assertEquals(1, StringUtils.countMatches(output.toString(), StringUtils.repeat(" ", 2 * 4)));
}
/**
@@ -112,15 +101,14 @@ public void testWriteLineBreakXMLWriterIntIntInt()
*
* @throws Exception if any
*/
- public void testWriteCommentLineBreakXMLWriter()
- throws Exception
- {
- XmlWriterUtil.writeCommentLineBreak( xmlWriter );
+ public void testWriteCommentLineBreakXMLWriter() throws Exception {
+ XmlWriterUtil.writeCommentLineBreak(xmlWriter);
writer.close();
StringBuilder sb = new StringBuilder();
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() );
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length());
}
/**
@@ -128,18 +116,16 @@ public void testWriteCommentLineBreakXMLWriter()
*
* @throws Exception if any
*/
- public void testWriteCommentLineBreakXMLWriterInt()
- throws Exception
- {
- XmlWriterUtil.writeCommentLineBreak( xmlWriter, 20 );
+ public void testWriteCommentLineBreakXMLWriterInt() throws Exception {
+ XmlWriterUtil.writeCommentLineBreak(xmlWriter, 20);
writer.close();
- assertEquals( output.toString(), "" + "\r\n" );
+ assertEquals(output.toString(), "" + "\r\n");
}
public void testWriteCommentLineBreak() throws IOException {
- XmlWriterUtil.writeCommentLineBreak( xmlWriter, 10 );
+ XmlWriterUtil.writeCommentLineBreak(xmlWriter, 10);
writer.close();
- assertEquals( output.toString(), output.toString(), "" + "\r\n" );
+ assertEquals(output.toString(), output.toString(), "" + "\r\n");
}
/**
@@ -147,37 +133,37 @@ public void testWriteCommentLineBreak() throws IOException {
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterString()
- throws Exception
- {
- XmlWriterUtil.writeComment( xmlWriter, "hello" );
+ public void testWriteCommentXMLWriterString() throws Exception {
+ XmlWriterUtil.writeComment(xmlWriter, "hello");
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() );
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length());
}
-
public void testWriteComment() throws IOException {
- XmlWriterUtil.writeComment( xmlWriter,
- "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" );
+ XmlWriterUtil.writeComment(
+ xmlWriter, "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( "" )
- .append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertTrue( output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE );
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertTrue(output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE);
}
-
+
public void testWriteComment_2() throws IOException {
- XmlWriterUtil.writeComment( xmlWriter, "hello\nworld" );
+ XmlWriterUtil.writeComment(xmlWriter, "hello\nworld");
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( "" ).append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), 2 * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ) );
+ sb.append("")
+ .append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()));
}
/**
@@ -185,33 +171,36 @@ public void testWriteComment_2() throws IOException {
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterStringInt()
- throws Exception
- {
- String indent = StringUtils.repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE );
+ public void testWriteCommentXMLWriterStringInt() throws Exception {
+ String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
- XmlWriterUtil.writeComment( xmlWriter, "hello", 2 );
+ XmlWriterUtil.writeComment(xmlWriter, "hello", 2);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( indent );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2
- * XmlWriterUtil.DEFAULT_INDENTATION_SIZE );
-
+ sb.append(indent);
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(
+ output.toString().length(),
+ XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
}
-
+
public void testWriteComment_3() throws IOException {
- String indent = StringUtils.repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE );
- XmlWriterUtil.writeComment( xmlWriter, "hello\nworld", 2 );
+ String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
+ XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( indent );
- sb.append( "" ).append( "\r\n" );
- sb.append( indent );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), 2 * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ) + 2 * indent.length() );
+ sb.append(indent);
+ sb.append("")
+ .append("\r\n");
+ sb.append(indent);
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(
+ output.toString().length(),
+ 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * indent.length());
}
/**
@@ -219,32 +208,33 @@ public void testWriteComment_3() throws IOException {
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterStringIntInt()
- throws Exception
- {
- String repeat = StringUtils.repeat( " ", 2 * 4 );
+ public void testWriteCommentXMLWriterStringIntInt() throws Exception {
+ String repeat = StringUtils.repeat(" ", 2 * 4);
- XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4 );
+ XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( repeat );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * 4 );
+ sb.append(repeat);
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * 4);
}
-
-
+
public void testWriteCommentXMLWriterStringIntInt_2() throws IOException {
- String repeat = StringUtils.repeat( " ", 2 * 4 );
- XmlWriterUtil.writeComment( xmlWriter, "hello\nworld", 2, 4 );
+ String repeat = StringUtils.repeat(" ", 2 * 4);
+ XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2, 4);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( repeat );
- sb.append( "" ).append( "\r\n" );
- sb.append( repeat );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertTrue( output.toString().length() == 2 * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ) + 2 * repeat.length() );
+ sb.append(repeat);
+ sb.append("")
+ .append("\r\n");
+ sb.append(repeat);
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertTrue(output.toString().length()
+ == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * repeat.length());
}
/**
@@ -252,30 +242,27 @@ public void testWriteCommentXMLWriterStringIntInt_2() throws IOException {
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterStringIntIntInt()
- throws Exception
- {
- String indent = StringUtils.repeat( " ", 2 * 4 );
+ public void testWriteCommentXMLWriterStringIntIntInt() throws Exception {
+ String indent = StringUtils.repeat(" ", 2 * 4);
- XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4, 50 );
+ XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 50);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( indent );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertTrue( output.toString().length() == 50 - 1 + "\r\n".length() + 2 * 4 );
+ sb.append(indent);
+ sb.append("").append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertTrue(output.toString().length() == 50 - 1 + "\r\n".length() + 2 * 4);
}
-
- public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException
- {
- String indent = StringUtils.repeat( " ", 2 * 4 );
- XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4, 10 );
+
+ public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException {
+ String indent = StringUtils.repeat(" ", 2 * 4);
+ XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 10);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( indent );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertTrue( output.toString().length() >= 10 + 2 * 4 );
+ sb.append(indent);
+ sb.append("").append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertTrue(output.toString().length() >= 10 + 2 * 4);
}
/**
@@ -283,71 +270,81 @@ public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException
*
* @throws Exception if any
*/
- public void testWriteCommentTextXMLWriterStringInt()
- throws Exception
- {
- XmlWriterUtil.writeCommentText( xmlWriter, "hello", 0 );
+ public void testWriteCommentTextXMLWriterStringInt() throws Exception {
+ XmlWriterUtil.writeCommentText(xmlWriter, "hello", 0);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- sb.append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), 3 * ( 80 - 1 + "\r\n".length() ) + 2 * "\r\n".length() );
+ sb.append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ sb.append("\r\n");
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), 3 * (80 - 1 + "\r\n".length()) + 2 * "\r\n".length());
}
-
+
public void testWriteCommentTextXMLWriterStringInt_2() throws IOException {
- String indent = StringUtils.repeat( " ", 2 * 2 );
+ String indent = StringUtils.repeat(" ", 2 * 2);
- XmlWriterUtil.writeCommentText( xmlWriter, "hello world with end of line\n and "
- + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", 2 );
+ XmlWriterUtil.writeCommentText(
+ xmlWriter,
+ "hello world with end of line\n and "
+ + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line",
+ 2);
writer.close();
StringBuffer sb = new StringBuffer();
- sb.append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( "\r\n" );
- sb.append( indent );
- assertEquals( output.toString(), sb.toString() );
+ sb.append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append("\r\n");
+ sb.append(indent);
+ assertEquals(output.toString(), sb.toString());
}
-
/**
* Test method for {@link org.apache.maven.shared.utils.xml.XmlWriterUtil#writeCommentText(XMLWriter, java.lang.String, int, int)}.
*
* @throws Exception if any
*/
- public void testWriteCommentTextXMLWriterStringIntInt()
- throws Exception
- {
- String indent = StringUtils.repeat( " ", 2 * 4 );
+ public void testWriteCommentTextXMLWriterStringIntInt() throws Exception {
+ String indent = StringUtils.repeat(" ", 2 * 4);
- XmlWriterUtil.writeCommentText( xmlWriter, "hello", 2, 4 );
+ XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4);
writer.close();
StringBuilder sb = new StringBuilder();
- sb.append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( indent ).append( "" )
- .append( "\r\n" );
- sb.append( "\r\n" );
- sb.append( indent );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), 3 * ( 80 - 1 + "\r\n".length() ) + 4 * 2 * 4 + 2 * "\r\n".length() );
+ sb.append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append("\r\n");
+ sb.append(indent);
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), 3 * (80 - 1 + "\r\n".length()) + 4 * 2 * 4 + 2 * "\r\n".length());
}
/**
@@ -355,22 +352,26 @@ public void testWriteCommentTextXMLWriterStringIntInt()
*
* @throws Exception if any
*/
- public void testWriteCommentTextXMLWriterStringIntIntInt()
- throws Exception
- {
- String indent = StringUtils.repeat( " ", 2 * 4 );
+ public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception {
+ String indent = StringUtils.repeat(" ", 2 * 4);
- XmlWriterUtil.writeCommentText( xmlWriter, "hello", 2, 4, 50 );
+ XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4, 50);
writer.close();
StringBuilder sb = new StringBuilder();
- sb.append( "\r\n" );
- sb.append( indent ).append( "" ).append( "\r\n" );
- sb.append( indent ).append( "" ).append( "\r\n" );
- sb.append( indent ).append( "" ).append( "\r\n" );
- sb.append( "\r\n" );
- sb.append( indent );
- assertEquals( output.toString(), sb.toString() );
- assertEquals( output.toString().length(), 3 * ( 50 - 1 + "\r\n".length() ) + 4 * 2 * 4 + 2 * "\r\n".length() );
+ sb.append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append(indent)
+ .append("")
+ .append("\r\n");
+ sb.append("\r\n");
+ sb.append(indent);
+ assertEquals(output.toString(), sb.toString());
+ assertEquals(output.toString().length(), 3 * (50 - 1 + "\r\n".length()) + 4 * 2 * 4 + 2 * "\r\n".length());
}
/**
@@ -378,14 +379,13 @@ public void testWriteCommentTextXMLWriterStringIntIntInt()
*
* @throws Exception if any
*/
- public void testWriteCommentNull()
- throws Exception
- {
- XmlWriterUtil.writeComment( xmlWriter, null );
+ public void testWriteCommentNull() throws Exception {
+ XmlWriterUtil.writeComment(xmlWriter, null);
writer.close();
StringBuilder sb = new StringBuilder();
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
}
/**
@@ -393,14 +393,13 @@ public void testWriteCommentNull()
*
* @throws Exception if any
*/
- public void testWriteCommentShort()
- throws Exception
- {
- XmlWriterUtil.writeComment( xmlWriter, "This is a short text" );
+ public void testWriteCommentShort() throws Exception {
+ XmlWriterUtil.writeComment(xmlWriter, "This is a short text");
writer.close();
StringBuilder sb = new StringBuilder();
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
}
/**
@@ -408,18 +407,22 @@ public void testWriteCommentShort()
*
* @throws Exception if any
*/
- public void testWriteCommentLong()
- throws Exception
- {
- XmlWriterUtil.writeComment( xmlWriter, "Maven is a software project management and comprehension tool. "
- + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting "
- + "and documentation from a central piece of information." );
+ public void testWriteCommentLong() throws Exception {
+ XmlWriterUtil.writeComment(
+ xmlWriter,
+ "Maven is a software project management and comprehension tool. "
+ + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting "
+ + "and documentation from a central piece of information.");
writer.close();
StringBuilder sb = new StringBuilder();
- sb.append( "" ).append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- sb.append( "" ).append( "\r\n" );
- assertEquals( output.toString(), sb.toString() );
+ sb.append("")
+ .append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ sb.append("")
+ .append("\r\n");
+ assertEquals(output.toString(), sb.toString());
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
index cef681e5..ab921d14 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.utils.xml;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,10 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.utils.xml.pull.XmlPullParserException;
-import org.junit.Assert;
-import org.junit.Test;
+package org.apache.maven.shared.utils.xml;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -31,176 +26,159 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
+import org.apache.maven.shared.utils.xml.pull.XmlPullParserException;
+import org.junit.Assert;
+import org.junit.Test;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
/**
* @author Kristian Rosenvold
*/
-public class Xpp3DomBuilderTest
-{
+public class Xpp3DomBuilderTest {
private static final String XML_DECLARATION = "\n";
@Test
- public void selfClosingTag()
- throws Exception
- {
+ public void selfClosingTag() throws Exception {
String domString = selfClosingTagSource();
- Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ) );
+ Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString));
String expected = expectedSelfClosingTag();
String dom1Str = dom.toString();
- assertEquals( "check DOMs match", expected, dom1Str );
+ assertEquals("check DOMs match", expected, dom1Str);
}
@Test
- public void testUnrecognizedEncoding()
- {
+ public void testUnrecognizedEncoding() {
byte[] data = "
".getBytes(StandardCharsets.UTF_8);
- InputStream in = new ByteArrayInputStream( data );
+ InputStream in = new ByteArrayInputStream(data);
try {
- Xpp3DomBuilder.build( in , "nosuch encoding" );
+ Xpp3DomBuilder.build(in, "nosuch encoding");
fail();
- } catch ( XmlPullParserException expected ) {
- assertTrue( expected.getCause() instanceof UnsupportedEncodingException );
+ } catch (XmlPullParserException expected) {
+ assertTrue(expected.getCause() instanceof UnsupportedEncodingException);
}
-
}
-
@Test
- public void trimming()
- throws Exception
- {
+ public void trimming() throws Exception {
String domString = createDomString();
- Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ), true );
+ Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);
- assertEquals( "element1value", dom.getChild( "element1" ).getValue() );
+ assertEquals("element1value", dom.getChild("element1").getValue());
- assertEquals( " preserve space ", dom.getChild( "element6" ).getValue() );
+ assertEquals(" preserve space ", dom.getChild("element6").getValue());
- dom = Xpp3DomBuilder.build( new StringReader( domString ), false );
+ dom = Xpp3DomBuilder.build(new StringReader(domString), false);
- assertEquals( " element1value\n ", dom.getChild( "element1" ).getValue() );
+ assertEquals(" element1value\n ", dom.getChild("element1").getValue());
- assertEquals( " preserve space ", dom.getChild( "element6" ).getValue() );
+ assertEquals(" preserve space ", dom.getChild("element6").getValue());
}
@Test
- public void testMalformedXml()
- {
+ public void testMalformedXml() {
try {
- Xpp3DomBuilder.build( new StringReader( "
" + createDomString() ) );
- fail( "We're supposed to fail" );
+ Xpp3DomBuilder.build(new StringReader("" + createDomString()));
+ fail("We're supposed to fail");
} catch (XmlPullParserException ex) {
- Assert.assertNotNull( ex.getMessage() );
+ Assert.assertNotNull(ex.getMessage());
}
}
@Test
- public void attributeEscaping()
- throws IOException, XmlPullParserException
- {
+ public void attributeEscaping() throws IOException, XmlPullParserException {
String s = getAttributeEncodedString();
- Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( s ) );
+ Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s));
- assertEquals( "", dom.getChild( "el" ).getAttribute( "att" ) );
+ assertEquals("", dom.getChild("el").getAttribute("att"));
StringWriter w = new StringWriter();
- Xpp3DomWriter.write( w, dom );
+ Xpp3DomWriter.write(w, dom);
String newString = w.toString();
- assertEquals( newString, s );
+ assertEquals(newString, s);
}
@Test
- public void contentEscaping()
- throws IOException, XmlPullParserException
- {
- Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( getEncodedString() ) );
+ public void contentEscaping() throws IOException, XmlPullParserException {
+ Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString()));
- assertEquals( "\"msg\"", dom.getChild( "a1" ).getValue() );
- assertEquals( "\"msg\"", dom.getChild( "a2" ).getValue() );
- assertEquals( "\"msg\"", dom.getChild( "a3" ).getValue() );
+ assertEquals("\"msg\"", dom.getChild("a1").getValue());
+ assertEquals("\"msg\"", dom.getChild("a2").getValue());
+ assertEquals("\"msg\"", dom.getChild("a3").getValue());
StringWriter w = new StringWriter();
- Xpp3DomWriter.write( w, dom );
- assertEquals( getExpectedString(), w.toString() );
+ Xpp3DomWriter.write(w, dom);
+ assertEquals(getExpectedString(), w.toString());
}
- private static String getAttributeEncodedString()
- {
+ private static String getAttributeEncodedString() {
StringBuilder domString = new StringBuilder();
- domString.append( "" );
- domString.append( "\n" );
- domString.append( " bar" );
- domString.append( "\n" );
- domString.append( "" );
+ domString.append("");
+ domString.append("\n");
+ domString.append(" bar");
+ domString.append("\n");
+ domString.append("");
return domString.toString();
}
- private static String getEncodedString()
- {
+ private static String getEncodedString() {
StringBuilder domString = new StringBuilder();
- domString.append( "\n" );
- domString.append( " \"msg\"\n" );
- domString.append( " \"msg\"]]>\n" );
- domString.append( " <b>"msg"</b>\n" );
- domString.append( "" );
+ domString.append("\n");
+ domString.append(" \"msg\"\n");
+ domString.append(" \"msg\"]]>\n");
+ domString.append(" <b>"msg"</b>\n");
+ domString.append("");
return domString.toString();
}
- private static String getExpectedString()
- {
+ private static String getExpectedString() {
StringBuilder domString = new StringBuilder();
- domString.append( "" );
- domString.append( "\n" );
- domString.append( " \"msg\"" );
- domString.append( "\n" );
- domString.append( " <b>\"msg\"</b>" );
- domString.append( "\n" );
- domString.append( " <b>\"msg\"</b>" );
- domString.append( "\n" );
- domString.append( "" );
+ domString.append("");
+ domString.append("\n");
+ domString.append(" \"msg\"");
+ domString.append("\n");
+ domString.append(" <b>\"msg\"</b>");
+ domString.append("\n");
+ domString.append(" <b>\"msg\"</b>");
+ domString.append("\n");
+ domString.append("");
return domString.toString();
}
- private static String createDomString()
- {
+ private static String createDomString() {
StringBuilder buf = new StringBuilder();
- buf.append( "\n" );
- buf.append( " element1value\n \n" );
- buf.append( " \n" );
- buf.append( " element3value\n" );
- buf.append( " \n" );
- buf.append( " \n" );
- buf.append( " \n" );
- buf.append( " preserve space \n" );
- buf.append( "\n" );
+ buf.append("\n");
+ buf.append(" element1value\n \n");
+ buf.append(" \n");
+ buf.append(" element3value\n");
+ buf.append(" \n");
+ buf.append(" \n");
+ buf.append(" \n");
+ buf.append(" preserve space \n");
+ buf.append("\n");
return buf.toString();
}
- private static String selfClosingTagSource()
- {
+ private static String selfClosingTagSource() {
StringBuilder buf = new StringBuilder();
- buf.append( "\n" );
- buf.append( " \n" );
- buf.append( " \n" );
- buf.append( "" );
+ buf.append("\n");
+ buf.append(" \n");
+ buf.append(" \n");
+ buf.append("");
return buf.toString();
}
- private static String expectedSelfClosingTag()
- {
+ private static String expectedSelfClosingTag() {
return XML_DECLARATION + selfClosingTagSource();
}
-
}
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java b/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
index 3d594bf8..fb8315d2 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.utils.xml.pull;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,12 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.utils.xml.pull;
import java.io.IOException;
import java.io.StringReader;
+
import org.apache.maven.shared.utils.xml.Xpp3Dom;
import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
-
import org.junit.Test;
import static org.apache.maven.shared.utils.xml.Xpp3Dom.mergeXpp3Dom;
@@ -32,242 +31,208 @@
/**
* @author Kristian Rosenvold
*/
-public class Xpp3DomTest
-{
+public class Xpp3DomTest {
- private Xpp3Dom createElement( String element, String value )
- {
- Xpp3Dom t1s1 = new Xpp3Dom( element );
- t1s1.setValue( value );
+ private Xpp3Dom createElement(String element, String value) {
+ Xpp3Dom t1s1 = new Xpp3Dom(element);
+ t1s1.setValue(value);
return t1s1;
}
-
@Test
- public void mergePrecedenceSelfClosed()
- throws XmlPullParserException, IOException
- {
- Xpp3Dom parentConfig = build( " " );
- Xpp3Dom childConfig = build( "- ooopise
" );
-
- Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig );
- Xpp3Dom items = result.getChild( "items" );
-
- assertEquals( 1, items.getChildCount() );
- Xpp3Dom item = items.getChild( 0 );
- assertEquals( "ooopise", item.getValue() );
+ public void mergePrecedenceSelfClosed() throws XmlPullParserException, IOException {
+ Xpp3Dom parentConfig = build(" ");
+ Xpp3Dom childConfig = build("- ooopise
");
+
+ Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(childConfig, parentConfig);
+ Xpp3Dom items = result.getChild("items");
+
+ assertEquals(1, items.getChildCount());
+ Xpp3Dom item = items.getChild(0);
+ assertEquals("ooopise", item.getValue());
}
@Test
- public void mergePrecedenceOpenClose()
- throws XmlPullParserException, IOException
- {
- Xpp3Dom parentConfig = build( " " );
- Xpp3Dom childConfig = build( "- ooopise
" );
-
- Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig );
- Xpp3Dom items = result.getChild( "items" );
-
- assertEquals( 1, items.getChildCount() );
- Xpp3Dom item = items.getChild( 0 );
- assertEquals( "ooopise", item.getValue() );
+ public void mergePrecedenceOpenClose() throws XmlPullParserException, IOException {
+ Xpp3Dom parentConfig = build(" ");
+ Xpp3Dom childConfig = build("- ooopise
");
+
+ Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(childConfig, parentConfig);
+ Xpp3Dom items = result.getChild("items");
+
+ assertEquals(1, items.getChildCount());
+ Xpp3Dom item = items.getChild(0);
+ assertEquals("ooopise", item.getValue());
}
@Test
- public void selfOverrideOnRootNode()
- {
+ public void selfOverrideOnRootNode() {
// Todo: This does not work when loaded. Probably a bug related to null vs "" handling
// Xpp3Dom t1 = build( "" );
- Xpp3Dom t1 = new Xpp3Dom( "top" );
- t1.setAttribute( "attr", "value" );
+ Xpp3Dom t1 = new Xpp3Dom("top");
+ t1.setAttribute("attr", "value");
- t1.setAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_OVERRIDE );
+ t1.setAttribute(Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_OVERRIDE);
- Xpp3Dom t2 = build( "val2" );
- Xpp3Dom result = mergeXpp3Dom( t1, t2 );
+ Xpp3Dom t2 = build("val2");
+ Xpp3Dom result = mergeXpp3Dom(t1, t2);
- assertEquals( 2, result.getAttributeNames().length );
- assertNull( result.getValue() );
+ assertEquals(2, result.getAttributeNames().length);
+ assertNull(result.getValue());
}
@Test
- public void mergeValuesOnRootNode()
- {
- Xpp3Dom t1 = build( "" );
- Xpp3Dom t2 = build( "t2Val" );
- Xpp3Dom result = mergeXpp3Dom( t1, t2 );
- assertEquals( 2, result.getAttributeNames().length );
- assertEquals( result.getValue(), t2.getValue() );
+ public void mergeValuesOnRootNode() {
+ Xpp3Dom t1 = build("");
+ Xpp3Dom t2 = build("t2Val");
+ Xpp3Dom result = mergeXpp3Dom(t1, t2);
+ assertEquals(2, result.getAttributeNames().length);
+ assertEquals(result.getValue(), t2.getValue());
}
@Test
- public void mergeAttributesOnRootNode()
- {
- Xpp3Dom t1 = build( "" );
- Xpp3Dom t2 = build( "" );
+ public void mergeAttributesOnRootNode() {
+ Xpp3Dom t1 = build("");
+ Xpp3Dom t2 = build("");
- Xpp3Dom dom = mergeXpp3Dom( t1, t2 );
- assertEquals( 3, dom.getAttributeNames().length );
+ Xpp3Dom dom = mergeXpp3Dom(t1, t2);
+ assertEquals(3, dom.getAttributeNames().length);
}
@Test
- public void combineAppend()
- {
- Xpp3Dom t1 = new Xpp3Dom( "root" );
- t1.setAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND );
- t1.addChild( createElement( "sub", "s1Value" ) );
+ public void combineAppend() {
+ Xpp3Dom t1 = new Xpp3Dom("root");
+ t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND);
+ t1.addChild(createElement("sub", "s1Value"));
- Xpp3Dom t2 = new Xpp3Dom( "root" );
- t2.addChild( createElement( "sub", "s1Value" ) );
+ Xpp3Dom t2 = new Xpp3Dom("root");
+ t2.addChild(createElement("sub", "s1Value"));
- Xpp3Dom result = mergeXpp3Dom( t1, t2 );
+ Xpp3Dom result = mergeXpp3Dom(t1, t2);
- assertEquals( 2, result.getChildren( "sub" ).length );
+ assertEquals(2, result.getChildren("sub").length);
}
@Test
- public void mergeOverride()
- {
- Xpp3Dom t1 = new Xpp3Dom( "root" );
- t1.setAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND );
- t1.addChild( createElement( "sub", "s1Value" ) );
+ public void mergeOverride() {
+ Xpp3Dom t1 = new Xpp3Dom("root");
+ t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND);
+ t1.addChild(createElement("sub", "s1Value"));
- Xpp3Dom t2 = new Xpp3Dom( "root" );
- t2.addChild( createElement( "sub", "s1Value" ) );
+ Xpp3Dom t2 = new Xpp3Dom("root");
+ t2.addChild(createElement("sub", "s1Value"));
- Xpp3Dom result = mergeXpp3Dom( t1, t2, Boolean.TRUE );
+ Xpp3Dom result = mergeXpp3Dom(t1, t2, Boolean.TRUE);
- assertEquals( 1, result.getChildren( "sub" ).length );
+ assertEquals(1, result.getChildren("sub").length);
}
-
- @Test( expected = NullPointerException.class )
- public void nullValue()
- {
+ @Test(expected = NullPointerException.class)
+ public void nullValue() {
//noinspection ConstantConditions
- new Xpp3Dom( "top" ).setAttribute( null, "value" );
+ new Xpp3Dom("top").setAttribute(null, "value");
}
- @Test( expected = NullPointerException.class )
- public void nullAttribute()
- {
+ @Test(expected = NullPointerException.class)
+ public void nullAttribute() {
//noinspection ConstantConditions
- new Xpp3Dom( "root" ).setAttribute( "attr", null );
+ new Xpp3Dom("root").setAttribute("attr", null);
}
-
@Test
- public void testEquals()
- {
- Xpp3Dom dom = new Xpp3Dom( "single" );
- dom.addChild( new Xpp3Dom( "kid" ) );
+ public void testEquals() {
+ Xpp3Dom dom = new Xpp3Dom("single");
+ dom.addChild(new Xpp3Dom("kid"));
- Xpp3Dom other = new Xpp3Dom( "single" );
- other.addChild( new Xpp3Dom( "kid2" ) );
+ Xpp3Dom other = new Xpp3Dom("single");
+ other.addChild(new Xpp3Dom("kid2"));
- assertEquals( dom, dom );
+ assertEquals(dom, dom);
//noinspection ObjectEqualsNull
- assertFalse( dom.equals( null ) );
- assertFalse( dom.equals( new Xpp3Dom( (String) null ) ) );
- assertFalse( dom.equals( other ) );
+ assertFalse(dom.equals(null));
+ assertFalse(dom.equals(new Xpp3Dom((String) null)));
+ assertFalse(dom.equals(other));
}
@Test
- public void dominantWinsCollections()
- throws XmlPullParserException
- {
- Xpp3Dom parent = build( "unodos" );
- Xpp3Dom dominant = build( "tres" );
+ public void dominantWinsCollections() throws XmlPullParserException {
+ Xpp3Dom parent = build("unodos");
+ Xpp3Dom dominant = build("tres");
- Xpp3Dom result = mergeXpp3Dom( dominant, parent );
+ Xpp3Dom result = mergeXpp3Dom(dominant, parent);
- Xpp3Dom items = result.getChild( "entries" );
- assertEquals( 1, items.getChildCount() );
+ Xpp3Dom items = result.getChild("entries");
+ assertEquals(1, items.getChildCount());
- assertElemEquals( "tres", items.getChild( 0 ) );
+ assertElemEquals("tres", items.getChild(0));
}
@Test
- public void combineChildrenAppendTest()
- throws XmlPullParserException
- {
+ public void combineChildrenAppendTest() throws XmlPullParserException {
Xpp3Dom parent =
- build( "unodostres" );
- Xpp3Dom child = build( "quatro" );
+ build("unodostres");
+ Xpp3Dom child = build("quatro");
- Xpp3Dom result = mergeXpp3Dom( child, parent );
+ Xpp3Dom result = mergeXpp3Dom(child, parent);
- Xpp3Dom items = result.getChild( "entries" );
- assertEquals( 4, items.getChildCount() );
+ Xpp3Dom items = result.getChild("entries");
+ assertEquals(4, items.getChildCount());
Xpp3Dom[] item = items.getChildren();
- assertElemEquals( "uno", item[0] );
- assertElemEquals( "dos", item[1] );
- assertElemEquals( "tres", item[2] );
- assertElemEquals( "quatro", item[3] );
+ assertElemEquals("uno", item[0]);
+ assertElemEquals("dos", item[1]);
+ assertElemEquals("tres", item[2]);
+ assertElemEquals("quatro", item[3]);
}
@Test
- public void unchangedWithFirstOrLastEmpty()
- throws Exception
- {
+ public void unchangedWithFirstOrLastEmpty() throws Exception {
String configStr = "test";
- Xpp3Dom dominant = build( configStr );
- Xpp3Dom duplicatedDominant = build( configStr );
- validateEntries( dominant );
- Xpp3Dom result = mergeXpp3Dom( dominant, duplicatedDominant );
- validateEntries( result );
+ Xpp3Dom dominant = build(configStr);
+ Xpp3Dom duplicatedDominant = build(configStr);
+ validateEntries(dominant);
+ Xpp3Dom result = mergeXpp3Dom(dominant, duplicatedDominant);
+ validateEntries(result);
}
- private void validateEntries( Xpp3Dom result )
- {
- Xpp3Dom entries = result.getChild( "entries" );
- assertEquals( 3, entries.getChildCount() );
- assertXpp3Null( entries.getChild( 0 ) );
- assertEquals( "test", entries.getChild( 1 ).getValue() );
- assertXpp3Null( entries.getChild( 2 ) );
+ private void validateEntries(Xpp3Dom result) {
+ Xpp3Dom entries = result.getChild("entries");
+ assertEquals(3, entries.getChildCount());
+ assertXpp3Null(entries.getChild(0));
+ assertEquals("test", entries.getChild(1).getValue());
+ assertXpp3Null(entries.getChild(2));
}
-
- static void assertElemEquals( String value, Xpp3Dom element )
- {
- assertEquals( value, element.getValue() );
+ static void assertElemEquals(String value, Xpp3Dom element) {
+ assertEquals(value, element.getValue());
}
-
- void assertXpp3Null( Xpp3Dom entry )
- {
+ void assertXpp3Null(Xpp3Dom entry) {
// Todo: When we used xpp3dom, all methods using this assert used to return null
- assertEquals( "", entry.getValue() );
+ assertEquals("", entry.getValue());
}
@Test
- public void recessiveChildrenIncludedWhenDominantEmpty()
- throws Exception
- {
+ public void recessiveChildrenIncludedWhenDominantEmpty() throws Exception {
String dominant = "bazzy";
String recessive = "barry";
- Xpp3Dom merged = mergeXpp3Dom( build( dominant ), build( recessive ) );
+ Xpp3Dom merged = mergeXpp3Dom(build(dominant), build(recessive));
- assertEquals( 2, merged.getChildCount() );
- assertEquals( "bazzy", merged.getChild( "baz" ).getValue() );
- assertEquals( "barry", merged.getChild( "bar" ).getValue() );
+ assertEquals(2, merged.getChildCount());
+ assertEquals("bazzy", merged.getChild("baz").getValue());
+ assertEquals("barry", merged.getChild("bar").getValue());
}
- static Xpp3Dom build( String stringContent )
- {
- return Xpp3DomBuilder.build( new StringReader( stringContent ) );
+ static Xpp3Dom build(String stringContent) {
+ return Xpp3DomBuilder.build(new StringReader(stringContent));
}
@Test
- public void duplicatedChildren()
- throws IOException, XmlPullParserException
- {
+ public void duplicatedChildren() throws IOException, XmlPullParserException {
String dupes = "xy";
- assertEquals( "y", build( dupes ).getChild( "baz" ).getValue() );
+ assertEquals("y", build(dupes).getChild("baz").getValue());
}
-
}