Skip to content

Commit cb1f9f4

Browse files
authored
Switch to junit 5 (#2)
1 parent 300a4e4 commit cb1f9f4

17 files changed

+128
-143
lines changed

Diff for: pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ limitations under the License.
7171
<scope>test</scope>
7272
</dependency>
7373
<dependency>
74-
<groupId>junit</groupId>
75-
<artifactId>junit</artifactId>
76-
<version>4.13.2</version>
74+
<groupId>org.junit.jupiter</groupId>
75+
<artifactId>junit-jupiter</artifactId>
76+
<version>5.9.2</version>
7777
<scope>test</scope>
7878
</dependency>
7979
</dependencies>

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

+15-28
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.fail;
22-
2319
import java.io.File;
2420
import java.io.IOException;
2521
import java.io.OutputStreamWriter;
@@ -30,9 +26,14 @@
3026
import javax.swing.text.html.HTML.Tag;
3127

3228
import org.codehaus.plexus.util.StringUtils;
33-
import org.junit.After;
34-
import org.junit.Before;
35-
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;
32+
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assertions.assertThrows;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
36+
import static org.junit.jupiter.api.Assertions.fail;
3637

3738
/**
3839
* Test of {@link org.codehaus.plexus.util.xml.PrettyPrintXMLWriter}
@@ -51,7 +52,7 @@ public class PrettyPrintXMLWriterTest
5152
/**
5253
* <p>setUp.</p>
5354
*/
54-
@Before
55+
@BeforeEach
5556
public void setUp()
5657
{
5758
initWriter();
@@ -60,7 +61,7 @@ public void setUp()
6061
/**
6162
* <p>tearDown.</p>
6263
*/
63-
@After
64+
@AfterEach
6465
public void tearDown()
6566
{
6667
writer = null;
@@ -161,18 +162,12 @@ public void testEscapeXmlAttribute()
161162
@Test
162163
public void testendElementAlreadyClosed()
163164
{
164-
try
165-
{
165+
assertThrows(NoSuchElementException.class, () -> {
166166
writer.startElement( Tag.DIV.toString() );
167167
writer.addAttribute( "class", "someattribute" );
168168
writer.endElement(); // Tag.DIV closed
169169
writer.endElement(); // Tag.DIV already closed, and there is no other outer tag!
170-
fail( "Should throw a NoSuchElementException" );
171-
}
172-
catch ( NoSuchElementException e )
173-
{
174-
assert ( true );
175-
}
170+
});
176171
}
177172

178173
/**
@@ -190,16 +185,15 @@ public void testIssue51DetectJava7ConcatenationBug()
190185
File dir = new File( "target/test-xml" );
191186
if ( !dir.exists() )
192187
{
193-
assertTrue( "cannot create directory test-xml", dir.mkdir() );
188+
assertTrue( dir.mkdir(), "cannot create directory test-xml" );
194189
}
195190
File xmlFile = new File( dir, "test-issue-51.xml" );
196-
OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream( xmlFile.toPath() ), "UTF-8" );
197-
writer = new PrettyPrintXMLWriter( osw );
198191

199192
int iterations = 20000;
200193

201-
try
194+
try ( OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream( xmlFile.toPath() ), "UTF-8" ) )
202195
{
196+
writer = new PrettyPrintXMLWriter( osw );
203197
for ( int i = 0; i < iterations; ++i )
204198
{
205199
writer.startElement( Tag.DIV.toString() + i );
@@ -214,13 +208,6 @@ public void testIssue51DetectJava7ConcatenationBug()
214208
{
215209
fail( "Should not throw a NoSuchElementException" );
216210
}
217-
finally
218-
{
219-
if ( osw != null )
220-
{
221-
osw.close();
222-
}
223-
}
224211
}
225212

226213
private void writeXhtmlHead( XMLWriter writer )

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

+24-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323

2424
import org.codehaus.plexus.util.IOUtil;
2525

26-
import junit.framework.ComparisonFailure;
27-
import junit.framework.TestCase;
26+
import org.junit.jupiter.api.Test;
27+
import org.opentest4j.AssertionFailedError;
28+
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertThrows;
31+
import static org.junit.jupiter.api.Assertions.fail;
2832

2933
/**
3034
* <p>XmlStreamReaderTest class.</p>
@@ -34,7 +38,6 @@
3438
* @since 3.4.0
3539
*/
3640
public class XmlStreamReaderTest
37-
extends TestCase
3841
{
3942
/** french */
4043
private static final String TEXT_LATIN1 = "eacute: \u00E9";
@@ -127,6 +130,7 @@ private static void checkXmlStreamReader( String text, String encoding, String e
127130
*
128131
* @throws java.io.IOException if any.
129132
*/
133+
@Test
130134
public void testNoXmlHeader()
131135
throws IOException
132136
{
@@ -140,6 +144,7 @@ public void testNoXmlHeader()
140144
*
141145
* @throws java.io.IOException if any.
142146
*/
147+
@Test
143148
public void testDefaultEncoding()
144149
throws IOException
145150
{
@@ -152,6 +157,7 @@ public void testDefaultEncoding()
152157
*
153158
* @throws java.io.IOException if any.
154159
*/
160+
@Test
155161
public void testUTF8Encoding()
156162
throws IOException
157163
{
@@ -164,6 +170,7 @@ public void testUTF8Encoding()
164170
*
165171
* @throws java.io.IOException if any.
166172
*/
173+
@Test
167174
public void testUTF16Encoding()
168175
throws IOException
169176
{
@@ -177,6 +184,7 @@ public void testUTF16Encoding()
177184
*
178185
* @throws java.io.IOException if any.
179186
*/
187+
@Test
180188
public void testUTF16BEEncoding()
181189
throws IOException
182190
{
@@ -188,6 +196,7 @@ public void testUTF16BEEncoding()
188196
*
189197
* @throws java.io.IOException if any.
190198
*/
199+
@Test
191200
public void testUTF16LEEncoding()
192201
throws IOException
193202
{
@@ -199,6 +208,7 @@ public void testUTF16LEEncoding()
199208
*
200209
* @throws java.io.IOException if any.
201210
*/
211+
@Test
202212
public void testLatin1Encoding()
203213
throws IOException
204214
{
@@ -210,6 +220,7 @@ public void testLatin1Encoding()
210220
*
211221
* @throws java.io.IOException if any.
212222
*/
223+
@Test
213224
public void testLatin7Encoding()
214225
throws IOException
215226
{
@@ -221,6 +232,7 @@ public void testLatin7Encoding()
221232
*
222233
* @throws java.io.IOException if any.
223234
*/
235+
@Test
224236
public void testLatin15Encoding()
225237
throws IOException
226238
{
@@ -232,6 +244,7 @@ public void testLatin15Encoding()
232244
*
233245
* @throws java.io.IOException if any.
234246
*/
247+
@Test
235248
public void testEUC_JPEncoding()
236249
throws IOException
237250
{
@@ -243,6 +256,7 @@ public void testEUC_JPEncoding()
243256
*
244257
* @throws java.io.IOException if any.
245258
*/
259+
@Test
246260
public void testEBCDICEncoding()
247261
throws IOException
248262
{
@@ -254,25 +268,23 @@ public void testEBCDICEncoding()
254268
*
255269
* @throws java.io.IOException if any.
256270
*/
271+
@Test
257272
public void testInappropriateEncoding()
258273
throws IOException
259274
{
260-
try
261-
{
262-
checkXmlStreamReader( TEXT_UNICODE, "ISO-8859-2" );
263-
fail( "Check should have failed, since some characters are not available in the specified encoding" );
264-
}
265-
catch ( ComparisonFailure cf )
266-
{
267-
// expected failure, since the encoding does not contain some characters
268-
}
275+
// expected failure, since the encoding does not contain some characters
276+
assertThrows(AssertionFailedError.class, () ->
277+
checkXmlStreamReader( TEXT_UNICODE, "ISO-8859-2" ),
278+
"Check should have failed, since some characters are not available in the specified encoding"
279+
);
269280
}
270281

271282
/**
272283
* <p>testEncodingAttribute.</p>
273284
*
274285
* @throws java.io.IOException if any.
275286
*/
287+
@Test
276288
public void testEncodingAttribute()
277289
throws IOException
278290
{

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.codehaus.plexus.util.xml;
22

3-
import static org.junit.Assert.assertEquals;
4-
53
/*
64
* Copyright The Codehaus Foundation.
75
*
@@ -21,7 +19,9 @@
2119
import java.io.ByteArrayOutputStream;
2220
import java.io.IOException;
2321

24-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
2525

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

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertNotNull;
20-
import static org.junit.Assert.assertTrue;
21-
2219
import java.io.File;
2320
import java.io.IOException;
2421
import java.io.InputStream;
@@ -30,7 +27,9 @@
3027

3128
import org.codehaus.plexus.util.IOUtil;
3229
import org.codehaus.plexus.util.StringUtils;
33-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
31+
32+
import static org.junit.jupiter.api.Assertions.*;
3433

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

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
* limitations under the License.
1717
*/
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
21-
2219
import java.io.ByteArrayOutputStream;
2320
import java.io.OutputStream;
2421
import java.io.Writer;
2522

2623
import org.codehaus.plexus.util.StringUtils;
27-
import org.junit.After;
28-
import org.junit.Before;
29-
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;
27+
28+
import static org.junit.jupiter.api.Assertions.*;
3029

3130
/**
3231
* <p>XmlWriterUtilTest class.</p>
@@ -48,7 +47,7 @@ public class XmlWriterUtilTest
4847
*
4948
* @throws java.lang.Exception if any.
5049
*/
51-
@Before
50+
@BeforeEach
5251
public void setUp()
5352
throws Exception
5453
{
@@ -62,7 +61,7 @@ public void setUp()
6261
*
6362
* @throws java.lang.Exception if any.
6463
*/
65-
@After
64+
@AfterEach
6665
public void tearDown()
6766
throws Exception
6867
{

0 commit comments

Comments
 (0)