22
22
import java .io .IOException ;
23
23
import java .io .OutputStreamWriter ;
24
24
import java .io .StringWriter ;
25
+ import java .nio .charset .StandardCharsets ;
25
26
import java .nio .file .Files ;
26
27
import java .util .NoSuchElementException ;
27
28
42
43
* @version $Id: $Id
43
44
* @since 3.4.0
44
45
*/
45
- public class PrettyPrintXMLWriterTest {
46
+ class PrettyPrintXMLWriterTest {
46
47
StringWriter w ;
47
48
48
49
PrettyPrintXMLWriter writer ;
@@ -51,15 +52,15 @@ public class PrettyPrintXMLWriterTest {
51
52
* <p>setUp.</p>
52
53
*/
53
54
@ BeforeEach
54
- public void setUp () {
55
+ void setUp () {
55
56
initWriter ();
56
57
}
57
58
58
59
/**
59
60
* <p>tearDown.</p>
60
61
*/
61
62
@ AfterEach
62
- public void tearDown () {
63
+ void tearDown () {
63
64
writer = null ;
64
65
w = null ;
65
66
}
@@ -73,7 +74,7 @@ private void initWriter() {
73
74
* <p>testDefaultPrettyPrintXMLWriter.</p>
74
75
*/
75
76
@ Test
76
- public void testDefaultPrettyPrintXMLWriter () {
77
+ void defaultPrettyPrintXMLWriter () {
77
78
writer .startElement (Tag .HTML .toString ());
78
79
79
80
writeXhtmlHead (writer );
@@ -89,7 +90,7 @@ public void testDefaultPrettyPrintXMLWriter() {
89
90
* <p>testPrettyPrintXMLWriterWithGivenLineSeparator.</p>
90
91
*/
91
92
@ Test
92
- public void testPrettyPrintXMLWriterWithGivenLineSeparator () {
93
+ void prettyPrintXMLWriterWithGivenLineSeparator () {
93
94
writer .setLineSeparator ("\n " );
94
95
95
96
writer .startElement (Tag .HTML .toString ());
@@ -107,7 +108,7 @@ public void testPrettyPrintXMLWriterWithGivenLineSeparator() {
107
108
* <p>testPrettyPrintXMLWriterWithGivenLineIndenter.</p>
108
109
*/
109
110
@ Test
110
- public void testPrettyPrintXMLWriterWithGivenLineIndenter () {
111
+ void prettyPrintXMLWriterWithGivenLineIndenter () {
111
112
writer .setLineIndenter (" " );
112
113
113
114
writer .startElement (Tag .HTML .toString ());
@@ -125,7 +126,7 @@ public void testPrettyPrintXMLWriterWithGivenLineIndenter() {
125
126
* <p>testEscapeXmlAttribute.</p>
126
127
*/
127
128
@ Test
128
- public void testEscapeXmlAttribute () {
129
+ void escapeXmlAttribute () {
129
130
// Windows
130
131
writer .startElement (Tag .DIV .toString ());
131
132
writer .addAttribute ("class" , "sect\r \n ion" );
@@ -151,7 +152,7 @@ public void testEscapeXmlAttribute() {
151
152
* <p>testendElementAlreadyClosed.</p>
152
153
*/
153
154
@ Test
154
- public void testendElementAlreadyClosed () {
155
+ void testendElementAlreadyClosed () {
155
156
try {
156
157
writer .startElement (Tag .DIV .toString ());
157
158
writer .addAttribute ("class" , "someattribute" );
@@ -164,21 +165,22 @@ public void testendElementAlreadyClosed() {
164
165
}
165
166
166
167
/**
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
168
169
* optimization bug is present. Target environment: Java 7 (u79 and u80 verified) running on Windows. Detection
169
170
* strategy: Tries to build a big XML file (~750MB size) and with many nested tags to force the JVM to trigger the
170
171
* concatenation string optimization bug that throws a NoSuchElementException when calling endElement() method.
171
172
*
172
- * @throws java.io. IOException if an I/O error occurs
173
+ * @throws IOException if an I/O error occurs
173
174
*/
174
175
@ Test
175
- public void testIssue51DetectJava7ConcatenationBug () throws IOException {
176
+ void issue51DetectJava7ConcatenationBug () throws IOException {
176
177
File dir = new File ("target/test-xml" );
177
178
if (!dir .exists ()) {
178
179
assertTrue (dir .mkdir (), "cannot create directory test-xml" );
179
180
}
180
181
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 );
182
184
writer = new PrettyPrintXMLWriter (osw );
183
185
184
186
int iterations = 20000 ;
@@ -235,34 +237,29 @@ private String expectedResult(String lineSeparator) {
235
237
}
236
238
237
239
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>" ;
267
264
}
268
265
}
0 commit comments