2222import java .io .IOException ;
2323import java .io .OutputStreamWriter ;
2424import java .io .StringWriter ;
25+ import java .nio .charset .StandardCharsets ;
2526import java .nio .file .Files ;
2627import java .util .NoSuchElementException ;
2728
4243 * @version $Id: $Id
4344 * @since 3.4.0
4445 */
45- public class PrettyPrintXMLWriterTest {
46+ class PrettyPrintXMLWriterTest {
4647 StringWriter w ;
4748
4849 PrettyPrintXMLWriter writer ;
@@ -51,15 +52,15 @@ public class PrettyPrintXMLWriterTest {
5152 * <p>setUp.</p>
5253 */
5354 @ BeforeEach
54- public void setUp () {
55+ void setUp () {
5556 initWriter ();
5657 }
5758
5859 /**
5960 * <p>tearDown.</p>
6061 */
6162 @ AfterEach
62- public void tearDown () {
63+ void tearDown () {
6364 writer = null ;
6465 w = null ;
6566 }
@@ -73,7 +74,7 @@ private void initWriter() {
7374 * <p>testDefaultPrettyPrintXMLWriter.</p>
7475 */
7576 @ Test
76- public void testDefaultPrettyPrintXMLWriter () {
77+ void defaultPrettyPrintXMLWriter () {
7778 writer .startElement (Tag .HTML .toString ());
7879
7980 writeXhtmlHead (writer );
@@ -89,7 +90,7 @@ public void testDefaultPrettyPrintXMLWriter() {
8990 * <p>testPrettyPrintXMLWriterWithGivenLineSeparator.</p>
9091 */
9192 @ Test
92- public void testPrettyPrintXMLWriterWithGivenLineSeparator () {
93+ void prettyPrintXMLWriterWithGivenLineSeparator () {
9394 writer .setLineSeparator ("\n " );
9495
9596 writer .startElement (Tag .HTML .toString ());
@@ -107,7 +108,7 @@ public void testPrettyPrintXMLWriterWithGivenLineSeparator() {
107108 * <p>testPrettyPrintXMLWriterWithGivenLineIndenter.</p>
108109 */
109110 @ Test
110- public void testPrettyPrintXMLWriterWithGivenLineIndenter () {
111+ void prettyPrintXMLWriterWithGivenLineIndenter () {
111112 writer .setLineIndenter (" " );
112113
113114 writer .startElement (Tag .HTML .toString ());
@@ -125,7 +126,7 @@ public void testPrettyPrintXMLWriterWithGivenLineIndenter() {
125126 * <p>testEscapeXmlAttribute.</p>
126127 */
127128 @ Test
128- public void testEscapeXmlAttribute () {
129+ void escapeXmlAttribute () {
129130 // Windows
130131 writer .startElement (Tag .DIV .toString ());
131132 writer .addAttribute ("class" , "sect\r \n ion" );
@@ -151,7 +152,7 @@ public void testEscapeXmlAttribute() {
151152 * <p>testendElementAlreadyClosed.</p>
152153 */
153154 @ Test
154- public void testendElementAlreadyClosed () {
155+ void testendElementAlreadyClosed () {
155156 try {
156157 writer .startElement (Tag .DIV .toString ());
157158 writer .addAttribute ("class" , "someattribute" );
@@ -164,21 +165,22 @@ public void testendElementAlreadyClosed() {
164165 }
165166
166167 /**
167- * Issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51 Purpose: test if concatenation string
168+ * Issue #51: <a href=" https://github.com/codehaus-plexus/plexus-utils/issues/51">...</a> Purpose: test if concatenation string
168169 * optimization bug is present. Target environment: Java 7 (u79 and u80 verified) running on Windows. Detection
169170 * strategy: Tries to build a big XML file (~750MB size) and with many nested tags to force the JVM to trigger the
170171 * concatenation string optimization bug that throws a NoSuchElementException when calling endElement() method.
171172 *
172- * @throws java.io. IOException if an I/O error occurs
173+ * @throws IOException if an I/O error occurs
173174 */
174175 @ Test
175- public void testIssue51DetectJava7ConcatenationBug () throws IOException {
176+ void issue51DetectJava7ConcatenationBug () throws IOException {
176177 File dir = new File ("target/test-xml" );
177178 if (!dir .exists ()) {
178179 assertTrue (dir .mkdir (), "cannot create directory test-xml" );
179180 }
180181 File xmlFile = new File (dir , "test-issue-51.xml" );
181- OutputStreamWriter osw = new OutputStreamWriter (Files .newOutputStream (xmlFile .toPath ()), "UTF-8" );
182+ OutputStreamWriter osw =
183+ new OutputStreamWriter (Files .newOutputStream (xmlFile .toPath ()), StandardCharsets .UTF_8 );
182184 writer = new PrettyPrintXMLWriter (osw );
183185
184186 int iterations = 20000 ;
@@ -235,34 +237,29 @@ private String expectedResult(String lineSeparator) {
235237 }
236238
237239 private String expectedResult (String lineIndenter , String lineSeparator ) {
238- StringBuilder expected = new StringBuilder ();
239-
240- expected .append ("<html>" ).append (lineSeparator );
241- expected .append (StringUtils .repeat (lineIndenter , 1 )).append ("<head>" ).append (lineSeparator );
242- expected .append (StringUtils .repeat (lineIndenter , 2 ))
243- .append ("<title>title</title>" )
244- .append (lineSeparator );
245- expected .append (StringUtils .repeat (lineIndenter , 2 ))
246- .append ("<meta name=\" author\" content=\" Author\" />" )
247- .append (lineSeparator );
248- expected .append (StringUtils .repeat (lineIndenter , 2 ))
249- .append ("<meta name=\" date\" content=\" Date\" />" )
250- .append (lineSeparator );
251- expected .append (StringUtils .repeat (lineIndenter , 1 )).append ("</head>" ).append (lineSeparator );
252- expected .append (StringUtils .repeat (lineIndenter , 1 )).append ("<body>" ).append (lineSeparator );
253- expected .append (StringUtils .repeat (lineIndenter , 2 ))
254- .append ("<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>" )
255- .append (lineSeparator );
256- expected .append (StringUtils .repeat (lineIndenter , 2 ))
257- .append ("<div class=\" section\" >" )
258- .append (lineSeparator );
259- expected .append (StringUtils .repeat (lineIndenter , 3 ))
260- .append ("<h2>Section title</h2>" )
261- .append (lineSeparator );
262- expected .append (StringUtils .repeat (lineIndenter , 2 )).append ("</div>" ).append (lineSeparator );
263- expected .append (StringUtils .repeat (lineIndenter , 1 )).append ("</body>" ).append (lineSeparator );
264- expected .append ("</html>" );
265-
266- return expected .toString ();
240+ return "<html>" + lineSeparator + StringUtils .repeat (lineIndenter , 1 )
241+ + "<head>" + lineSeparator + StringUtils .repeat (lineIndenter , 2 )
242+ + "<title>title</title>"
243+ + lineSeparator
244+ + StringUtils .repeat (lineIndenter , 2 )
245+ + "<meta name=\" author\" content=\" Author\" />"
246+ + lineSeparator
247+ + StringUtils .repeat (lineIndenter , 2 )
248+ + "<meta name=\" date\" content=\" Date\" />"
249+ + lineSeparator
250+ + StringUtils .repeat (lineIndenter , 1 )
251+ + "</head>" + lineSeparator + StringUtils .repeat (lineIndenter , 1 )
252+ + "<body>" + lineSeparator + StringUtils .repeat (lineIndenter , 2 )
253+ + "<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>"
254+ + lineSeparator
255+ + StringUtils .repeat (lineIndenter , 2 )
256+ + "<div class=\" section\" >"
257+ + lineSeparator
258+ + StringUtils .repeat (lineIndenter , 3 )
259+ + "<h2>Section title</h2>"
260+ + lineSeparator
261+ + StringUtils .repeat (lineIndenter , 2 )
262+ + "</div>" + lineSeparator + StringUtils .repeat (lineIndenter , 1 )
263+ + "</body>" + lineSeparator + "</html>" ;
267264 }
268265}
0 commit comments