Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf03664

Browse filesBrowse files
committed
Cleanup tests and drop dependency to plexus-utils
1 parent 5a1f0a3 commit bf03664
Copy full SHA for bf03664

File tree

Expand file treeCollapse file tree

9 files changed

+125
-99
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+125
-99
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ limitations under the License.
4949

5050
<properties>
5151
<javaVersion>17</javaVersion>
52+
<jmhVersion>1.37</jmhVersion>
5253
<project.build.outputTimestamp>2024-05-21T21:02:17Z</project.build.outputTimestamp>
5354
</properties>
5455

@@ -67,24 +68,23 @@ limitations under the License.
6768
<dependency>
6869
<groupId>org.openjdk.jmh</groupId>
6970
<artifactId>jmh-core</artifactId>
70-
<version>1.37</version>
71+
<version>${jmhVersion}</version>
7172
<scope>test</scope>
7273
</dependency>
7374
<dependency>
7475
<groupId>org.openjdk.jmh</groupId>
7576
<artifactId>jmh-generator-annprocess</artifactId>
76-
<version>1.37</version>
77+
<version>${jmhVersion}</version>
7778
<scope>test</scope>
7879
</dependency>
7980
<dependency>
8081
<groupId>org.junit.jupiter</groupId>
81-
<artifactId>junit-jupiter</artifactId>
82+
<artifactId>junit-jupiter-api</artifactId>
8283
<scope>test</scope>
8384
</dependency>
8485
<dependency>
85-
<groupId>org.codehaus.plexus</groupId>
86-
<artifactId>plexus-utils</artifactId>
87-
<version>4.0.2</version>
86+
<groupId>org.junit.jupiter</groupId>
87+
<artifactId>junit-jupiter-params</artifactId>
8888
<scope>test</scope>
8989
</dependency>
9090
</dependencies>

‎src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java
+25-31Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.file.Files;
2727
import java.util.NoSuchElementException;
2828

29-
import org.codehaus.plexus.util.StringUtils;
3029
import org.junit.jupiter.api.AfterEach;
3130
import org.junit.jupiter.api.BeforeEach;
3231
import org.junit.jupiter.api.Disabled;
@@ -165,7 +164,7 @@ void testendElementAlreadyClosed() {
165164
}
166165

167166
/**
168-
* Issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51 Purpose: test if concatenation string
167+
* Issue #51: <a href="https://github.com/codehaus-plexus/plexus-utils/issues/51">Issue 51</a> Purpose: test if concatenation string
169168
* optimization bug is present. Target environment: Java 7 (u79 and u80 verified) running on Windows. Detection
170169
* strategy: Tries to build a big XML file (~750MB size) and with many nested tags to force the JVM to trigger the
171170
* concatenation string optimization bug that throws a NoSuchElementException when calling endElement() method.
@@ -232,34 +231,29 @@ private String expectedResult(String lineSeparator) {
232231
}
233232

234233
private String expectedResult(String lineIndenter, String lineSeparator) {
235-
StringBuilder expected = new StringBuilder();
236-
237-
expected.append("<html>").append(lineSeparator);
238-
expected.append(StringUtils.repeat(lineIndenter, 1)).append("<head>").append(lineSeparator);
239-
expected.append(StringUtils.repeat(lineIndenter, 2))
240-
.append("<title>title</title>")
241-
.append(lineSeparator);
242-
expected.append(StringUtils.repeat(lineIndenter, 2))
243-
.append("<meta name=\"author\" content=\"Author\"/>")
244-
.append(lineSeparator);
245-
expected.append(StringUtils.repeat(lineIndenter, 2))
246-
.append("<meta name=\"date\" content=\"Date\"/>")
247-
.append(lineSeparator);
248-
expected.append(StringUtils.repeat(lineIndenter, 1)).append("</head>").append(lineSeparator);
249-
expected.append(StringUtils.repeat(lineIndenter, 1)).append("<body>").append(lineSeparator);
250-
expected.append(StringUtils.repeat(lineIndenter, 2))
251-
.append("<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>")
252-
.append(lineSeparator);
253-
expected.append(StringUtils.repeat(lineIndenter, 2))
254-
.append("<div class=\"section\">")
255-
.append(lineSeparator);
256-
expected.append(StringUtils.repeat(lineIndenter, 3))
257-
.append("<h2>Section title</h2>")
258-
.append(lineSeparator);
259-
expected.append(StringUtils.repeat(lineIndenter, 2)).append("</div>").append(lineSeparator);
260-
expected.append(StringUtils.repeat(lineIndenter, 1)).append("</body>").append(lineSeparator);
261-
expected.append("</html>");
262-
263-
return expected.toString();
234+
return "<html>" + lineSeparator + lineIndenter
235+
+ "<head>" + lineSeparator + lineIndenter
236+
+ lineIndenter + "<title>title</title>"
237+
+ lineSeparator
238+
+ lineIndenter
239+
+ lineIndenter + "<meta name=\"author\" content=\"Author\"/>"
240+
+ lineSeparator
241+
+ lineIndenter
242+
+ lineIndenter + "<meta name=\"date\" content=\"Date\"/>"
243+
+ lineSeparator
244+
+ lineIndenter
245+
+ "</head>" + lineSeparator + lineIndenter
246+
+ "<body>" + lineSeparator + lineIndenter
247+
+ lineIndenter + "<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>"
248+
+ lineSeparator
249+
+ lineIndenter
250+
+ lineIndenter + "<div class=\"section\">"
251+
+ lineSeparator
252+
+ lineIndenter
253+
+ lineIndenter + lineIndenter + "<h2>Section title</h2>"
254+
+ lineSeparator
255+
+ lineIndenter
256+
+ lineIndenter + "</div>" + lineSeparator + lineIndenter
257+
+ "</body>" + lineSeparator + "</html>";
264258
}
265259
}
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.codehaus.plexus.util.xml;
2+
3+
import java.io.IOException;
4+
import java.io.Reader;
5+
import java.io.StringWriter;
6+
7+
public class TestUtils {
8+
9+
public static String readAllFrom(Reader input) throws IOException {
10+
StringWriter output = new StringWriter();
11+
char[] buffer = new char[16384];
12+
int n = 0;
13+
while (0 <= (n = input.read(buffer))) {
14+
output.write(buffer, 0, n);
15+
}
16+
output.flush();
17+
return output.toString();
18+
}
19+
/**
20+
* <p>
21+
* How many times is the substring in the larger String.
22+
* </p>
23+
* <p>
24+
* <code>null</code> returns <code>0</code>.
25+
* </p>
26+
*
27+
* @param str the String to check
28+
* @param sub the substring to count
29+
* @return the number of occurrences, 0 if the String is <code>null</code>
30+
* @throws NullPointerException if sub is <code>null</code>
31+
*/
32+
public static int countMatches(String str, String sub) {
33+
if (sub.isEmpty()) {
34+
return 0;
35+
}
36+
if (str == null) {
37+
return 0;
38+
}
39+
int count = 0;
40+
int idx = 0;
41+
while ((idx = str.indexOf(sub, idx)) != -1) {
42+
count++;
43+
idx += sub.length();
44+
}
45+
return count;
46+
}
47+
}

‎src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import java.io.InputStream;
2222
import java.io.SequenceInputStream;
2323

24-
import org.codehaus.plexus.util.IOUtil;
2524
import org.junit.jupiter.api.Test;
2625
import org.opentest4j.AssertionFailedError;
2726

27+
import static org.codehaus.plexus.util.xml.TestUtils.readAllFrom;
2828
import static org.junit.jupiter.api.Assertions.assertEquals;
2929
import static org.junit.jupiter.api.Assertions.assertThrows;
3030

@@ -68,8 +68,7 @@ private static String createXmlContent(String text, String encoding) {
6868
if (encoding != null) {
6969
xmlDecl = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>";
7070
}
71-
String xml = xmlDecl + "\n<text>" + text + "</text>";
72-
return xml;
71+
return xmlDecl + "\n<text>" + text + "</text>";
7372
}
7473

7574
private static void checkXmlContent(String xml, String encoding) throws IOException {
@@ -86,8 +85,7 @@ private static void checkXmlContent(String xml, String encoding, byte... bom) th
8685

8786
XmlStreamReader reader = new XmlStreamReader(in);
8887
assertEquals(encoding, reader.getEncoding());
89-
String result = IOUtil.toString(reader);
90-
assertEquals(xml, result);
88+
assertEquals(xml, readAllFrom(reader));
9189
}
9290

9391
private static void checkXmlStreamReader(String text, String encoding, String effectiveEncoding)
@@ -228,10 +226,9 @@ void ebcdicEncoding() throws IOException {
228226
/**
229227
* <p>testInappropriateEncoding.</p>
230228
*
231-
* @throws java.io.IOException if any.
232229
*/
233230
@Test
234-
void inappropriateEncoding() throws IOException {
231+
void inappropriateEncoding() {
235232
// expected failure, since the encoding does not contain some characters
236233
assertThrows(
237234
AssertionFailedError.class,

‎src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ private static String createXmlContent(String text, String encoding) {
5252
if (encoding != null) {
5353
xmlDecl = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>";
5454
}
55-
String xml = xmlDecl + "\n<text>" + text + "</text>";
56-
return xml;
55+
return xmlDecl + "\n<text>" + text + "</text>";
5756
}
5857

5958
private static void checkXmlContent(String xml, String encoding) throws IOException {

‎src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
import java.io.Writer;
2626
import java.nio.file.Files;
2727

28-
import org.codehaus.plexus.util.IOUtil;
29-
import org.codehaus.plexus.util.StringUtils;
3028
import org.junit.jupiter.api.Test;
3129

30+
import static org.codehaus.plexus.util.xml.TestUtils.readAllFrom;
3231
import static org.junit.jupiter.api.Assertions.assertNotNull;
3332
import static org.junit.jupiter.api.Assertions.assertTrue;
3433

@@ -116,18 +115,20 @@ void prettyFormatString() throws Exception {
116115

117116
String content;
118117
try (Reader reader = new XmlStreamReader(testDocument)) {
119-
content = IOUtil.toString(reader);
118+
content = readAllFrom(reader);
120119
}
121120

122-
Writer writer = new StringWriter();
121+
String contentPretty;
123122
try (Reader reader = new XmlStreamReader(testDocument)) {
123+
Writer writer = new StringWriter();
124124
XmlUtil.prettyFormat(reader, writer);
125+
contentPretty = writer.toString();
125126
}
126127

127128
assertNotNull(content);
128129

129-
int countEOL = StringUtils.countMatches(content, XmlUtil.DEFAULT_LINE_SEPARATOR);
130-
assertTrue(countEOL < StringUtils.countMatches(writer.toString(), XmlUtil.DEFAULT_LINE_SEPARATOR));
130+
int countEOL = TestUtils.countMatches(content, XmlUtil.DEFAULT_LINE_SEPARATOR);
131+
assertTrue(countEOL < TestUtils.countMatches(contentPretty, XmlUtil.DEFAULT_LINE_SEPARATOR));
131132
}
132133

133134
/**

‎src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java
+12-16Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.OutputStream;
2121
import java.io.Writer;
2222

23-
import org.codehaus.plexus.util.StringUtils;
2423
import org.junit.jupiter.api.AfterEach;
2524
import org.junit.jupiter.api.BeforeEach;
2625
import org.junit.jupiter.api.Test;
@@ -76,7 +75,7 @@ void tearDown() throws Exception {
7675
void writeLineBreakXMLWriter() throws Exception {
7776
XmlWriterUtil.writeLineBreak(xmlWriter);
7877
writer.close();
79-
assertEquals(1, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS));
78+
assertEquals(1, TestUtils.countMatches(output.toString(), XmlWriterUtil.LS));
8079
}
8180

8281
/**
@@ -89,7 +88,7 @@ void writeLineBreakXMLWriter() throws Exception {
8988
void writeLineBreakXMLWriterInt() throws Exception {
9089
XmlWriterUtil.writeLineBreak(xmlWriter, 10);
9190
writer.close();
92-
assertEquals(10, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS));
91+
assertEquals(10, TestUtils.countMatches(output.toString(), XmlWriterUtil.LS));
9392
}
9493

9594
/**
@@ -102,11 +101,8 @@ void writeLineBreakXMLWriterInt() throws Exception {
102101
void writeLineBreakXMLWriterIntInt() throws Exception {
103102
XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2);
104103
writer.close();
105-
assertEquals(10, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS));
106-
assertEquals(
107-
1,
108-
StringUtils.countMatches(
109-
output.toString(), StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE)));
104+
assertEquals(10, TestUtils.countMatches(output.toString(), XmlWriterUtil.LS));
105+
assertEquals(1, TestUtils.countMatches(output.toString(), " ")); //
110106
}
111107

112108
/**
@@ -119,8 +115,8 @@ void writeLineBreakXMLWriterIntInt() throws Exception {
119115
void writeLineBreakXMLWriterIntIntInt() throws Exception {
120116
XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2, 4);
121117
writer.close();
122-
assertEquals(10, StringUtils.countMatches(output.toString(), XmlWriterUtil.LS));
123-
assertEquals(1, StringUtils.countMatches(output.toString(), StringUtils.repeat(" ", 2 * 4)));
118+
assertEquals(10, TestUtils.countMatches(output.toString(), XmlWriterUtil.LS));
119+
assertEquals(1, TestUtils.countMatches(output.toString(), " "));
124120
}
125121

126122
/**
@@ -211,7 +207,7 @@ void writeCommentXMLWriterString() throws Exception {
211207
*/
212208
@Test
213209
void writeCommentXMLWriterStringInt() throws Exception {
214-
String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
210+
String indent = " ";
215211

216212
XmlWriterUtil.writeComment(xmlWriter, "hello", 2);
217213
writer.close();
@@ -253,7 +249,7 @@ void writeCommentXMLWriterStringInt() throws Exception {
253249
*/
254250
@Test
255251
void writeCommentXMLWriterStringIntInt() throws Exception {
256-
String repeat = StringUtils.repeat(" ", 2 * 4);
252+
String repeat = " ";
257253

258254
XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4);
259255
writer.close();
@@ -291,7 +287,7 @@ void writeCommentXMLWriterStringIntInt() throws Exception {
291287
*/
292288
@Test
293289
void writeCommentXMLWriterStringIntIntInt() throws Exception {
294-
String indent = StringUtils.repeat(" ", 2 * 4);
290+
String indent = " ";
295291

296292
XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 50);
297293
writer.close();
@@ -339,7 +335,7 @@ void writeCommentTextXMLWriterStringInt() throws Exception {
339335
tearDown();
340336
setUp();
341337

342-
String indent = StringUtils.repeat(" ", 2 * 2);
338+
String indent = " ";
343339

344340
XmlWriterUtil.writeCommentText(
345341
xmlWriter,
@@ -380,7 +376,7 @@ void writeCommentTextXMLWriterStringInt() throws Exception {
380376
*/
381377
@Test
382378
void writeCommentTextXMLWriterStringIntInt() throws Exception {
383-
String indent = StringUtils.repeat(" ", 2 * 4);
379+
String indent = " ";
384380

385381
XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4);
386382
writer.close();
@@ -411,7 +407,7 @@ void writeCommentTextXMLWriterStringIntInt() throws Exception {
411407
*/
412408
@Test
413409
void writeCommentTextXMLWriterStringIntIntInt() throws Exception {
414-
String indent = StringUtils.repeat(" ", 2 * 4);
410+
String indent = " ";
415411

416412
XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4, 50);
417413
writer.close();

‎src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java
+6-13Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,11 @@ void shouldNotMergeValues() {
194194
@Test
195195
void nullAttributeNameOrValue() {
196196
Xpp3Dom t1 = new Xpp3Dom("top");
197-
try {
198-
t1.setAttribute("attr", null);
199-
fail("null attribute values shouldn't be allowed");
200-
} catch (NullPointerException e) {
201-
}
202-
t1.toString();
203-
try {
204-
t1.setAttribute(null, "value");
205-
fail("null attribute names shouldn't be allowed");
206-
} catch (NullPointerException e) {
207-
}
208-
t1.toString();
197+
assertThrows(NullPointerException.class, () -> t1.setAttribute("attr", null));
198+
assertNotNull(t1.toString());
199+
200+
assertThrows(NullPointerException.class, () -> t1.setAttribute(null, "value"));
201+
assertNotNull(t1.toString());
209202
}
210203

211204
/**
@@ -217,7 +210,7 @@ void equals() {
217210

218211
assertEquals(dom, dom);
219212
assertNotEquals(null, dom);
220-
assertNotEquals(dom, new Xpp3Dom(""));
213+
assertNotEquals(new Xpp3Dom(""), dom);
221214
}
222215

223216
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.