Skip to content

Commit a12d6f3

Browse files
Switch to junit 5
1 parent 55de18a commit a12d6f3

17 files changed

+116
-114
lines changed

pom.xml

+9-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ limitations under the License.
3232

3333
<scm>
3434
<connection>scm:git:https://github.com/codehaus-plexus/plexus-xml.git</connection>
35-
<developerConnection>scm:git:https://github.com/codehaus-plexus/plexus-xml.git</developerConnection>
35+
<developerConnection>${project.scm.connection}</developerConnection>
3636
<tag>3.x</tag>
3737
<url>https://github.com/codehaus-plexus/plexus-xml/tree/${project.scm.tag}/</url>
3838
</scm>
@@ -52,12 +52,6 @@ limitations under the License.
5252
</properties>
5353

5454
<dependencies>
55-
<dependency>
56-
<groupId>org.codehaus.plexus</groupId>
57-
<artifactId>plexus-utils</artifactId>
58-
<version>4.0.1</version>
59-
<scope>test</scope>
60-
</dependency>
6155
<dependency>
6256
<groupId>org.openjdk.jmh</groupId>
6357
<artifactId>jmh-core</artifactId>
@@ -71,9 +65,14 @@ limitations under the License.
7165
<scope>test</scope>
7266
</dependency>
7367
<dependency>
74-
<groupId>junit</groupId>
75-
<artifactId>junit</artifactId>
76-
<version>4.13.2</version>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.codehaus.plexus</groupId>
74+
<artifactId>plexus-utils</artifactId>
75+
<version>4.0.1</version>
7776
<scope>test</scope>
7877
</dependency>
7978
</dependencies>

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
import java.util.NoSuchElementException;
2727

2828
import org.codehaus.plexus.util.StringUtils;
29-
import org.junit.After;
30-
import org.junit.Before;
31-
import org.junit.Test;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
3232

33-
import static org.junit.Assert.assertEquals;
34-
import static org.junit.Assert.assertTrue;
35-
import static org.junit.Assert.fail;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assertions.assertTrue;
35+
import static org.junit.jupiter.api.Assertions.fail;
3636

3737
/**
3838
* Test of {@link org.codehaus.plexus.util.xml.PrettyPrintXMLWriter}
@@ -50,15 +50,15 @@ public class PrettyPrintXMLWriterTest {
5050
/**
5151
* <p>setUp.</p>
5252
*/
53-
@Before
53+
@BeforeEach
5454
public void setUp() {
5555
initWriter();
5656
}
5757

5858
/**
5959
* <p>tearDown.</p>
6060
*/
61-
@After
61+
@AfterEach
6262
public void tearDown() {
6363
writer = null;
6464
w = null;
@@ -175,7 +175,7 @@ public void testendElementAlreadyClosed() {
175175
public void testIssue51DetectJava7ConcatenationBug() throws IOException {
176176
File dir = new File("target/test-xml");
177177
if (!dir.exists()) {
178-
assertTrue("cannot create directory test-xml", dir.mkdir());
178+
assertTrue(dir.mkdir(), "cannot create directory test-xml");
179179
}
180180
File xmlFile = new File(dir, "test-issue-51.xml");
181181
OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(xmlFile.toPath()), "UTF-8");

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

+24-9
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
import java.io.InputStream;
2222
import java.io.SequenceInputStream;
2323

24-
import junit.framework.ComparisonFailure;
25-
import junit.framework.TestCase;
2624
import org.codehaus.plexus.util.IOUtil;
25+
import org.junit.jupiter.api.Test;
26+
import org.opentest4j.AssertionFailedError;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertThrows;
2730

2831
/**
2932
* <p>XmlStreamReaderTest class.</p>
@@ -32,7 +35,7 @@
3235
* @version $Id: $Id
3336
* @since 3.4.0
3437
*/
35-
public class XmlStreamReaderTest extends TestCase {
38+
public class XmlStreamReaderTest {
3639
/** french */
3740
private static final String TEXT_LATIN1 = "eacute: \u00E9";
3841

@@ -111,6 +114,7 @@ private static void checkXmlStreamReader(String text, String encoding, String ef
111114
*
112115
* @throws java.io.IOException if any.
113116
*/
117+
@Test
114118
public void testNoXmlHeader() throws IOException {
115119
String xml = "<text>text with no XML header</text>";
116120
checkXmlContent(xml, "UTF-8");
@@ -122,6 +126,7 @@ public void testNoXmlHeader() throws IOException {
122126
*
123127
* @throws java.io.IOException if any.
124128
*/
129+
@Test
125130
public void testDefaultEncoding() throws IOException {
126131
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8");
127132
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8);
@@ -132,6 +137,7 @@ public void testDefaultEncoding() throws IOException {
132137
*
133138
* @throws java.io.IOException if any.
134139
*/
140+
@Test
135141
public void testUTF8Encoding() throws IOException {
136142
checkXmlStreamReader(TEXT_UNICODE, "UTF-8");
137143
checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8);
@@ -142,6 +148,7 @@ public void testUTF8Encoding() throws IOException {
142148
*
143149
* @throws java.io.IOException if any.
144150
*/
151+
@Test
145152
public void testUTF16Encoding() throws IOException {
146153
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null);
147154
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE);
@@ -153,6 +160,7 @@ public void testUTF16Encoding() throws IOException {
153160
*
154161
* @throws java.io.IOException if any.
155162
*/
163+
@Test
156164
public void testUTF16BEEncoding() throws IOException {
157165
checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE");
158166
}
@@ -162,6 +170,7 @@ public void testUTF16BEEncoding() throws IOException {
162170
*
163171
* @throws java.io.IOException if any.
164172
*/
173+
@Test
165174
public void testUTF16LEEncoding() throws IOException {
166175
checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE");
167176
}
@@ -171,6 +180,7 @@ public void testUTF16LEEncoding() throws IOException {
171180
*
172181
* @throws java.io.IOException if any.
173182
*/
183+
@Test
174184
public void testLatin1Encoding() throws IOException {
175185
checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1");
176186
}
@@ -180,6 +190,7 @@ public void testLatin1Encoding() throws IOException {
180190
*
181191
* @throws java.io.IOException if any.
182192
*/
193+
@Test
183194
public void testLatin7Encoding() throws IOException {
184195
checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7");
185196
}
@@ -189,6 +200,7 @@ public void testLatin7Encoding() throws IOException {
189200
*
190201
* @throws java.io.IOException if any.
191202
*/
203+
@Test
192204
public void testLatin15Encoding() throws IOException {
193205
checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15");
194206
}
@@ -198,6 +210,7 @@ public void testLatin15Encoding() throws IOException {
198210
*
199211
* @throws java.io.IOException if any.
200212
*/
213+
@Test
201214
public void testEUC_JPEncoding() throws IOException {
202215
checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP");
203216
}
@@ -207,6 +220,7 @@ public void testEUC_JPEncoding() throws IOException {
207220
*
208221
* @throws java.io.IOException if any.
209222
*/
223+
@Test
210224
public void testEBCDICEncoding() throws IOException {
211225
checkXmlStreamReader("simple text in EBCDIC", "CP1047");
212226
}
@@ -216,20 +230,21 @@ public void testEBCDICEncoding() throws IOException {
216230
*
217231
* @throws java.io.IOException if any.
218232
*/
233+
@Test
219234
public void testInappropriateEncoding() throws IOException {
220-
try {
221-
checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2");
222-
fail("Check should have failed, since some characters are not available in the specified encoding");
223-
} catch (ComparisonFailure cf) {
224-
// expected failure, since the encoding does not contain some characters
225-
}
235+
// expected failure, since the encoding does not contain some characters
236+
assertThrows(
237+
AssertionFailedError.class,
238+
() -> checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2"),
239+
"Check should have failed, since some characters are not available in the specified encoding");
226240
}
227241

228242
/**
229243
* <p>testEncodingAttribute.</p>
230244
*
231245
* @throws java.io.IOException if any.
232246
*/
247+
@Test
233248
public void testEncodingAttribute() throws IOException {
234249
String xml = "<?xml version='1.0' encoding='US-ASCII'?><element encoding='attribute value'/>";
235250
checkXmlContent(xml, "US-ASCII");

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

24-
import static org.junit.Assert.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
2525

2626
/**
2727
* <p>XmlStreamWriterTest class.</p>

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727

2828
import org.codehaus.plexus.util.IOUtil;
2929
import org.codehaus.plexus.util.StringUtils;
30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131

32-
import static org.junit.Assert.assertNotNull;
33-
import static org.junit.Assert.assertTrue;
32+
import static org.junit.jupiter.api.Assertions.*;
3433

3534
/**
3635
* Test the {@link org.codehaus.plexus.util.xml.XmlUtil} class.

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
import java.io.Writer;
2222

2323
import org.codehaus.plexus.util.StringUtils;
24-
import org.junit.After;
25-
import org.junit.Before;
26-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertTrue;
28+
import static org.junit.jupiter.api.Assertions.*;
3029

3130
/**
3231
* <p>XmlWriterUtilTest class.</p>
@@ -47,7 +46,7 @@ public class XmlWriterUtilTest {
4746
*
4847
* @throws java.lang.Exception if any.
4948
*/
50-
@Before
49+
@BeforeEach
5150
public void setUp() throws Exception {
5251
output = new ByteArrayOutputStream();
5352
writer = WriterFactory.newXmlWriter(output);
@@ -59,7 +58,7 @@ public void setUp() throws Exception {
5958
*
6059
* @throws java.lang.Exception if any.
6160
*/
62-
@After
61+
@AfterEach
6362
public void tearDown() throws Exception {
6463
xmlWriter = null;
6564
writer = null;

src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java

+18-23
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
import org.codehaus.plexus.util.xml.pull.MXParser;
2424
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
2525
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertFalse;
30-
import static org.junit.Assert.assertTrue;
28+
import static org.junit.jupiter.api.Assertions.*;
3129

3230
/**
3331
* Test the Xpp3DomBuilder.
@@ -52,7 +50,7 @@ public void testBuildFromReader() throws Exception {
5250

5351
Xpp3Dom expectedDom = createExpectedDom();
5452

55-
assertEquals("check DOMs match", expectedDom, dom);
53+
assertEquals(expectedDom, dom, "check DOMs match");
5654
}
5755

5856
/**
@@ -66,12 +64,11 @@ public void testBuildTrimming() throws Exception {
6664

6765
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);
6866

69-
assertEquals("test with trimming on", "element1", dom.getChild("el1").getValue());
67+
assertEquals("element1", dom.getChild("el1").getValue(), "test with trimming on");
7068

7169
dom = Xpp3DomBuilder.build(new StringReader(domString), false);
7270

73-
assertEquals(
74-
"test with trimming off", " element1\n ", dom.getChild("el1").getValue());
71+
assertEquals(" element1\n ", dom.getChild("el1").getValue(), "test with trimming off");
7572
}
7673

7774
/**
@@ -116,10 +113,10 @@ public void testBuildFromXpp3Dom() throws Exception {
116113
eventType = parser.next();
117114
}
118115

119-
assertEquals("Check DOM matches", expectedDom, dom);
120-
assertFalse("Check closing root was consumed", rootClosed);
121-
assertTrue("Check continued to parse configuration", configurationClosed);
122-
assertTrue("Check continued to parse newRoot", newRootClosed);
116+
assertEquals(expectedDom, dom, "Check DOM matches");
117+
assertFalse(rootClosed, "Check closing root was consumed");
118+
assertTrue(configurationClosed, "Check continued to parse configuration");
119+
assertTrue(newRootClosed, "Check continued to parse newRoot");
123120
}
124121

125122
/**
@@ -149,15 +146,13 @@ public void testUnclosedXml() {
149146
public void testEscapingInContent() throws IOException, XmlPullParserException {
150147
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString()));
151148

152-
assertEquals("Check content value", "\"text\"", dom.getChild("el").getValue());
153-
assertEquals(
154-
"Check content value", "<b>\"text\"</b>", dom.getChild("ela").getValue());
155-
assertEquals(
156-
"Check content value", "<b>\"text\"</b>", dom.getChild("elb").getValue());
149+
assertEquals("\"text\"", dom.getChild("el").getValue(), "Check content value");
150+
assertEquals("<b>\"text\"</b>", dom.getChild("ela").getValue(), "Check content value");
151+
assertEquals("<b>\"text\"</b>", dom.getChild("elb").getValue(), "Check content value");
157152

158153
StringWriter w = new StringWriter();
159154
Xpp3DomWriter.write(w, dom);
160-
assertEquals("Compare stringified DOMs", getExpectedString(), w.toString());
155+
assertEquals(getExpectedString(), w.toString(), "Compare stringified DOMs");
161156
}
162157

163158
/**
@@ -171,12 +166,12 @@ public void testEscapingInAttributes() throws IOException, XmlPullParserExceptio
171166
String s = getAttributeEncodedString();
172167
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s));
173168

174-
assertEquals("Check attribute value", "<foo>", dom.getChild("el").getAttribute("att"));
169+
assertEquals("<foo>", dom.getChild("el").getAttribute("att"), "Check attribute value");
175170

176171
StringWriter w = new StringWriter();
177172
Xpp3DomWriter.write(w, dom);
178173
String newString = w.toString();
179-
assertEquals("Compare stringified DOMs", newString, s);
174+
assertEquals(newString, s, "Compare stringified DOMs");
180175
}
181176

182177
/**
@@ -194,16 +189,16 @@ public Object toInputLocation(XmlPullParser parser) {
194189
};
195190
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(createDomString()), true, ilb);
196191
Xpp3Dom expectedDom = createExpectedDom();
197-
assertEquals("root input location", expectedDom.getInputLocation(), dom.getInputLocation());
192+
assertEquals(expectedDom.getInputLocation(), dom.getInputLocation(), "root input location");
198193
for (int i = 0; i < dom.getChildCount(); i++) {
199194
Xpp3Dom elt = dom.getChild(i);
200195
Xpp3Dom expectedElt = expectedDom.getChild(i);
201-
assertEquals(elt.getName() + " input location", expectedElt.getInputLocation(), elt.getInputLocation());
196+
assertEquals(expectedElt.getInputLocation(), elt.getInputLocation(), elt.getName() + " input location");
202197

203198
if ("el2".equals(elt.getName())) {
204199
Xpp3Dom el3 = elt.getChild(0);
205200
Xpp3Dom expectedEl3 = expectedElt.getChild(0);
206-
assertEquals(el3.getName() + " input location", expectedEl3.getInputLocation(), el3.getInputLocation());
201+
assertEquals(expectedEl3.getInputLocation(), el3.getInputLocation(), el3.getName() + " input location");
207202
}
208203
}
209204
}

0 commit comments

Comments
 (0)