26
26
import java .nio .file .Files ;
27
27
import java .util .NoSuchElementException ;
28
28
29
- import org .codehaus .plexus .util .StringUtils ;
30
29
import org .junit .jupiter .api .AfterEach ;
31
30
import org .junit .jupiter .api .BeforeEach ;
31
+ import org .junit .jupiter .api .Disabled ;
32
32
import org .junit .jupiter .api .Test ;
33
33
34
34
import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -172,20 +172,19 @@ void testendElementAlreadyClosed() {
172
172
*
173
173
* @throws IOException if an I/O error occurs
174
174
*/
175
+ @ Disabled ("This test is only relevant on JDK 1.7, which is not supported anymore" )
175
176
@ Test
176
177
void issue51DetectJava7ConcatenationBug () throws IOException {
177
178
File dir = new File ("target/test-xml" );
178
179
if (!dir .exists ()) {
179
180
assertTrue (dir .mkdir (), "cannot create directory test-xml" );
180
181
}
181
182
File xmlFile = new File (dir , "test-issue-51.xml" );
182
- OutputStreamWriter osw =
183
- new OutputStreamWriter (Files .newOutputStream (xmlFile .toPath ()), StandardCharsets .UTF_8 );
184
- writer = new PrettyPrintXMLWriter (osw );
185
183
186
184
int iterations = 20000 ;
187
-
188
- try {
185
+ try (OutputStreamWriter osw =
186
+ new OutputStreamWriter (Files .newOutputStream (xmlFile .toPath ()), StandardCharsets .UTF_8 )) {
187
+ writer = new PrettyPrintXMLWriter (osw );
189
188
for (int i = 0 ; i < iterations ; ++i ) {
190
189
writer .startElement (Tag .DIV .toString () + i );
191
190
writer .addAttribute ("class" , "someattribute" );
@@ -195,10 +194,6 @@ void issue51DetectJava7ConcatenationBug() throws IOException {
195
194
}
196
195
} catch (NoSuchElementException e ) {
197
196
fail ("Should not throw a NoSuchElementException" );
198
- } finally {
199
- if (osw != null ) {
200
- osw .close ();
201
- }
202
197
}
203
198
}
204
199
@@ -237,29 +232,29 @@ private String expectedResult(String lineSeparator) {
237
232
}
238
233
239
234
private String expectedResult (String lineIndenter , String lineSeparator ) {
240
- return "<html>" + lineSeparator + StringUtils . repeat ( lineIndenter , 1 )
241
- + "<head>" + lineSeparator + StringUtils . repeat ( lineIndenter , 2 )
235
+ return "<html>" + lineSeparator + lineIndenter
236
+ + "<head>" + lineSeparator + lineIndenter + lineIndenter
242
237
+ "<title>title</title>"
243
238
+ lineSeparator
244
- + StringUtils . repeat ( lineIndenter , 2 )
239
+ + lineIndenter + lineIndenter
245
240
+ "<meta name=\" author\" content=\" Author\" />"
246
241
+ lineSeparator
247
- + StringUtils . repeat ( lineIndenter , 2 )
242
+ + lineIndenter + lineIndenter
248
243
+ "<meta name=\" date\" content=\" Date\" />"
249
244
+ lineSeparator
250
- + StringUtils . repeat ( lineIndenter , 1 )
251
- + "</head>" + lineSeparator + StringUtils . repeat ( lineIndenter , 1 )
252
- + "<body>" + lineSeparator + StringUtils . repeat ( lineIndenter , 2 )
245
+ + lineIndenter
246
+ + "</head>" + lineSeparator + lineIndenter
247
+ + "<body>" + lineSeparator + lineIndenter + lineIndenter
253
248
+ "<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>"
254
249
+ lineSeparator
255
- + StringUtils . repeat ( lineIndenter , 2 )
250
+ + lineIndenter + lineIndenter
256
251
+ "<div class=\" section\" >"
257
252
+ lineSeparator
258
- + StringUtils . repeat ( lineIndenter , 3 )
253
+ + lineIndenter + lineIndenter + lineIndenter
259
254
+ "<h2>Section title</h2>"
260
255
+ lineSeparator
261
- + StringUtils . repeat ( lineIndenter , 2 )
262
- + "</div>" + lineSeparator + StringUtils . repeat ( lineIndenter , 1 )
256
+ + lineIndenter + lineIndenter
257
+ + "</div>" + lineSeparator + lineIndenter
263
258
+ "</body>" + lineSeparator + "</html>" ;
264
259
}
265
260
}
0 commit comments