Skip to content

Commit 134bc1c

Browse files
committed
Tests cleanup
1 parent 0c36a51 commit 134bc1c

18 files changed

+619
-663
lines changed

Diff for: pom.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,26 @@ limitations under the License.
4848
</distributionManagement>
4949

5050
<properties>
51+
<jmhVersion>1.37</jmhVersion>
5152
<project.build.outputTimestamp>2024-05-21T21:12:10Z</project.build.outputTimestamp>
5253
</properties>
5354

5455
<dependencies>
5556
<dependency>
5657
<groupId>org.openjdk.jmh</groupId>
5758
<artifactId>jmh-core</artifactId>
58-
<version>1.37</version>
59+
<version>${jmhVersion}</version>
5960
<scope>test</scope>
6061
</dependency>
6162
<dependency>
6263
<groupId>org.openjdk.jmh</groupId>
6364
<artifactId>jmh-generator-annprocess</artifactId>
64-
<version>1.37</version>
65+
<version>${jmhVersion}</version>
6566
<scope>test</scope>
6667
</dependency>
6768
<dependency>
6869
<groupId>org.junit.jupiter</groupId>
69-
<artifactId>junit-jupiter</artifactId>
70+
<artifactId>junit-jupiter-api</artifactId>
7071
<scope>test</scope>
7172
</dependency>
7273
<dependency>

Diff for: src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java

+38-41
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.io.OutputStreamWriter;
2424
import java.io.StringWriter;
25+
import java.nio.charset.StandardCharsets;
2526
import java.nio.file.Files;
2627
import java.util.NoSuchElementException;
2728

@@ -42,7 +43,7 @@
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\nion");
@@ -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
}

Diff for: src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @version $Id: $Id
3636
* @since 3.4.0
3737
*/
38-
public class XmlStreamReaderTest {
38+
class XmlStreamReaderTest {
3939
/** french */
4040
private static final String TEXT_LATIN1 = "eacute: \u00E9";
4141

@@ -52,7 +52,7 @@ public class XmlStreamReaderTest {
5252
private static final String TEXT_UNICODE =
5353
TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP;
5454

55-
/** see http://unicode.org/faq/utf_bom.html#BOM */
55+
/** see <a href="http://unicode.org/faq/utf_bom.html#BOM">BOM</a> */
5656
private static final byte[] BOM_UTF8 = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF};
5757

5858
private static final byte[] BOM_UTF16BE = {(byte) 0xFE, (byte) 0xFF};
@@ -115,7 +115,7 @@ private static void checkXmlStreamReader(String text, String encoding, String ef
115115
* @throws java.io.IOException if any.
116116
*/
117117
@Test
118-
public void testNoXmlHeader() throws IOException {
118+
void noXmlHeader() throws IOException {
119119
String xml = "<text>text with no XML header</text>";
120120
checkXmlContent(xml, "UTF-8");
121121
checkXmlContent(xml, "UTF-8", BOM_UTF8);
@@ -127,7 +127,7 @@ public void testNoXmlHeader() throws IOException {
127127
* @throws java.io.IOException if any.
128128
*/
129129
@Test
130-
public void testDefaultEncoding() throws IOException {
130+
void defaultEncoding() throws IOException {
131131
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8");
132132
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8);
133133
}
@@ -138,7 +138,7 @@ public void testDefaultEncoding() throws IOException {
138138
* @throws java.io.IOException if any.
139139
*/
140140
@Test
141-
public void testUTF8Encoding() throws IOException {
141+
void utf8Encoding() throws IOException {
142142
checkXmlStreamReader(TEXT_UNICODE, "UTF-8");
143143
checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8);
144144
}
@@ -149,7 +149,7 @@ public void testUTF8Encoding() throws IOException {
149149
* @throws java.io.IOException if any.
150150
*/
151151
@Test
152-
public void testUTF16Encoding() throws IOException {
152+
void utf16Encoding() throws IOException {
153153
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null);
154154
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE);
155155
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE);
@@ -161,7 +161,7 @@ public void testUTF16Encoding() throws IOException {
161161
* @throws java.io.IOException if any.
162162
*/
163163
@Test
164-
public void testUTF16BEEncoding() throws IOException {
164+
void utf16beEncoding() throws IOException {
165165
checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE");
166166
}
167167

@@ -171,7 +171,7 @@ public void testUTF16BEEncoding() throws IOException {
171171
* @throws java.io.IOException if any.
172172
*/
173173
@Test
174-
public void testUTF16LEEncoding() throws IOException {
174+
void utf16leEncoding() throws IOException {
175175
checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE");
176176
}
177177

@@ -181,7 +181,7 @@ public void testUTF16LEEncoding() throws IOException {
181181
* @throws java.io.IOException if any.
182182
*/
183183
@Test
184-
public void testLatin1Encoding() throws IOException {
184+
void latin1Encoding() throws IOException {
185185
checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1");
186186
}
187187

@@ -191,7 +191,7 @@ public void testLatin1Encoding() throws IOException {
191191
* @throws java.io.IOException if any.
192192
*/
193193
@Test
194-
public void testLatin7Encoding() throws IOException {
194+
void latin7Encoding() throws IOException {
195195
checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7");
196196
}
197197

@@ -201,7 +201,7 @@ public void testLatin7Encoding() throws IOException {
201201
* @throws java.io.IOException if any.
202202
*/
203203
@Test
204-
public void testLatin15Encoding() throws IOException {
204+
void latin15Encoding() throws IOException {
205205
checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15");
206206
}
207207

@@ -211,7 +211,7 @@ public void testLatin15Encoding() throws IOException {
211211
* @throws java.io.IOException if any.
212212
*/
213213
@Test
214-
public void testEUC_JPEncoding() throws IOException {
214+
void euc_jpEncoding() throws IOException {
215215
checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP");
216216
}
217217

@@ -221,7 +221,7 @@ public void testEUC_JPEncoding() throws IOException {
221221
* @throws java.io.IOException if any.
222222
*/
223223
@Test
224-
public void testEBCDICEncoding() throws IOException {
224+
void ebcdicEncoding() throws IOException {
225225
checkXmlStreamReader("simple text in EBCDIC", "CP1047");
226226
}
227227

@@ -231,7 +231,7 @@ public void testEBCDICEncoding() throws IOException {
231231
* @throws java.io.IOException if any.
232232
*/
233233
@Test
234-
public void testInappropriateEncoding() throws IOException {
234+
void inappropriateEncoding() throws IOException {
235235
// expected failure, since the encoding does not contain some characters
236236
assertThrows(
237237
AssertionFailedError.class,
@@ -245,7 +245,7 @@ public void testInappropriateEncoding() throws IOException {
245245
* @throws java.io.IOException if any.
246246
*/
247247
@Test
248-
public void testEncodingAttribute() throws IOException {
248+
void encodingAttribute() throws IOException {
249249
String xml = "<?xml version='1.0' encoding='US-ASCII'?><element encoding='attribute value'/>";
250250
checkXmlContent(xml, "US-ASCII");
251251

0 commit comments

Comments
 (0)