Skip to content

Commit 2b32ca0

Browse files
authored
All tests in codec migrated to JUnit 5 (#113)
unit-vintage-engine dropped from pom.xml
1 parent 03ae658 commit 2b32ca0

69 files changed

Lines changed: 1469 additions & 1533 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ limitations under the License.
266266
<scope>test</scope>
267267
</dependency>
268268
<dependency>
269-
<groupId>org.junit.vintage</groupId>
270-
<artifactId>junit-vintage-engine</artifactId>
269+
<groupId>org.junit.jupiter</groupId>
270+
<artifactId>junit-jupiter-params</artifactId>
271271
<scope>test</scope>
272272
</dependency>
273273
</dependencies>

src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
package org.apache.commons.codec;
1919

20-
import static org.junit.Assert.assertThrows;
20+
import org.junit.jupiter.api.Test;
2121

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

2424
/**
2525
*/

src/test/java/org/apache/commons/codec/CharEncodingTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
package org.apache.commons.codec;
1919

20-
import org.junit.Assert;
21-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
2223

2324
/**
2425
* Sanity checks for {@link CharEncoding}.
@@ -36,32 +37,32 @@ public void testConstructor() {
3637

3738
@Test
3839
public void testIso8859_1() {
39-
Assert.assertEquals("ISO-8859-1", CharEncoding.ISO_8859_1);
40+
assertEquals("ISO-8859-1", CharEncoding.ISO_8859_1);
4041
}
4142

4243
@Test
4344
public void testUsAscii() {
44-
Assert.assertEquals("US-ASCII", CharEncoding.US_ASCII);
45+
assertEquals("US-ASCII", CharEncoding.US_ASCII);
4546
}
4647

4748
@Test
4849
public void testUtf16() {
49-
Assert.assertEquals("UTF-16", CharEncoding.UTF_16);
50+
assertEquals("UTF-16", CharEncoding.UTF_16);
5051
}
5152

5253
@Test
5354
public void testUtf16Be() {
54-
Assert.assertEquals("UTF-16BE", CharEncoding.UTF_16BE);
55+
assertEquals("UTF-16BE", CharEncoding.UTF_16BE);
5556
}
5657

5758
@Test
5859
public void testUtf16Le() {
59-
Assert.assertEquals("UTF-16LE", CharEncoding.UTF_16LE);
60+
assertEquals("UTF-16LE", CharEncoding.UTF_16LE);
6061
}
6162

6263
@Test
6364
public void testUtf8() {
64-
Assert.assertEquals("UTF-8", CharEncoding.UTF_8);
65+
assertEquals("UTF-8", CharEncoding.UTF_8);
6566
}
6667

6768
}

src/test/java/org/apache/commons/codec/CharsetsTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
package org.apache.commons.codec;
1919

20+
import org.junit.jupiter.api.Test;
21+
2022
import java.nio.charset.Charset;
2123
import java.nio.charset.StandardCharsets;
2224

23-
import org.junit.Assert;
24-
import org.junit.Test;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
2526

2627
/**
2728
* Sanity checks for {@link Charsets}.
@@ -31,46 +32,46 @@ public class CharsetsTest {
3132

3233
@Test
3334
public void testToCharset() {
34-
Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
35-
Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
36-
Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
37-
Assert.assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(StandardCharsets.UTF_8));
35+
assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
36+
assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
37+
assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
38+
assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(StandardCharsets.UTF_8));
3839
}
3940

4041
@SuppressWarnings("deprecation")
4142
@Test
4243
public void testIso8859_1() {
43-
Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
44+
assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
4445
}
4546

4647
@SuppressWarnings("deprecation")
4748
@Test
4849
public void testUsAscii() {
49-
Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name());
50+
assertEquals("US-ASCII", Charsets.US_ASCII.name());
5051
}
5152

5253
@SuppressWarnings("deprecation")
5354
@Test
5455
public void testUtf16() {
55-
Assert.assertEquals("UTF-16", Charsets.UTF_16.name());
56+
assertEquals("UTF-16", Charsets.UTF_16.name());
5657
}
5758

5859
@SuppressWarnings("deprecation")
5960
@Test
6061
public void testUtf16Be() {
61-
Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
62+
assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
6263
}
6364

6465
@SuppressWarnings("deprecation")
6566
@Test
6667
public void testUtf16Le() {
67-
Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
68+
assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
6869
}
6970

7071
@SuppressWarnings("deprecation")
7172
@Test
7273
public void testUtf8() {
73-
Assert.assertEquals("UTF-8", Charsets.UTF_8.name());
74+
assertEquals("UTF-8", Charsets.UTF_8.name());
7475
}
7576

7677
}

src/test/java/org/apache/commons/codec/DecoderExceptionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
package org.apache.commons.codec;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNull;
20+
import org.junit.jupiter.api.Test;
2221

23-
import org.junit.Test;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
2424

2525
/**
2626
* Tests {@link DecoderException}.

src/test/java/org/apache/commons/codec/EncoderExceptionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
package org.apache.commons.codec;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNull;
20+
import org.junit.jupiter.api.Test;
2221

23-
import org.junit.Test;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
2424

2525
/**
2626
* Tests {@link EncoderException}.

src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
package org.apache.commons.codec;
1919

20+
import org.junit.jupiter.api.Test;
21+
2022
import java.util.Locale;
2123

22-
import org.junit.Assert;
23-
import org.junit.Test;
24+
import static org.junit.jupiter.api.Assertions.*;
2425

2526
/**
2627
*/
@@ -29,7 +30,7 @@ public abstract class StringEncoderAbstractTest<T extends StringEncoder> {
2930
protected T stringEncoder = this.createStringEncoder();
3031

3132
public void checkEncoding(final String expected, final String source) throws EncoderException {
32-
Assert.assertEquals("Source: " + source, expected, this.getStringEncoder().encode(source));
33+
assertEquals(expected, this.getStringEncoder().encode(source), "Source: " + source);
3334
}
3435

3536
protected void checkEncodings(final String[][] data) throws EncoderException {
@@ -66,16 +67,10 @@ public void testEncodeNull() throws EncoderException {
6667

6768
@Test
6869
public void testEncodeWithInvalidObject() throws Exception {
69-
boolean exceptionThrown = false;
70-
try {
71-
final StringEncoder encoder = this.getStringEncoder();
72-
encoder.encode(Float.valueOf(3.4f));
73-
} catch (final Exception e) {
74-
exceptionThrown = true;
75-
}
76-
Assert.assertTrue("An exception was not thrown when we tried to encode " + "a Float object", exceptionThrown);
70+
final StringEncoder encoder = this.getStringEncoder();
71+
assertThrows(EncoderException.class, () -> encoder.encode(Float.valueOf(3.4f)),
72+
"An exception was not thrown when we tried to encode a Float object");
7773
}
78-
7974
@Test
8075
public void testLocaleIndependence() throws Exception {
8176
final StringEncoder encoder = this.getStringEncoder();
@@ -97,9 +92,9 @@ public void testLocaleIndependence() throws Exception {
9792
try {
9893
cur = encoder.encode(element);
9994
} catch (final Exception e) {
100-
Assert.fail(Locale.getDefault().toString() + ": " + e.getMessage());
95+
fail(Locale.getDefault().toString() + ": " + e.getMessage());
10196
}
102-
Assert.assertEquals(Locale.getDefault().toString() + ": ", ref, cur);
97+
assertEquals(ref, cur, Locale.getDefault().toString() + ": ");
10398
}
10499
}
105100
}

src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
package org.apache.commons.codec;
1919

20-
import static org.junit.Assert.assertEquals;
21-
2220
import java.util.Arrays;
2321
import java.util.List;
2422

2523
import org.apache.commons.codec.language.DoubleMetaphone;
2624
import org.apache.commons.codec.language.Soundex;
27-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
2828

2929
/**
3030
* Test cases for the StingEncoderComparator.
@@ -36,8 +36,8 @@ public void testComparatorWithSoundex() throws Exception {
3636
final StringEncoderComparator sCompare =
3737
new StringEncoderComparator( new Soundex() );
3838

39-
assertEquals("O'Brien and O'Brian didn't come out with " +
40-
"the same Soundex, something must be wrong here", 0, sCompare.compare("O'Brien", "O'Brian"));
39+
assertEquals(0, sCompare.compare("O'Brien", "O'Brian"),
40+
"O'Brien and O'Brian didn't come out with the same Soundex, something must be wrong here");
4141
}
4242

4343
@SuppressWarnings("unchecked") // cannot easily avoid this warning
@@ -55,7 +55,8 @@ public void testComparatorWithDoubleMetaphone() throws Exception {
5555
final String[] resultArray = testList.toArray(new String[0]);
5656

5757
for (int i = 0; i < resultArray.length; i++) {
58-
assertEquals("Result Array not Equal to Control Array at index: " + i, controlArray[i], resultArray[i]);
58+
assertEquals(controlArray[i], resultArray[i],
59+
"Result Array not Equal to Control Array at index: " + i);
5960
}
6061
}
6162

@@ -65,7 +66,8 @@ public void testComparatorWithDoubleMetaphoneAndInvalidInput() throws Exception
6566
new StringEncoderComparator( new DoubleMetaphone() );
6667

6768
final int compare = sCompare.compare(Double.valueOf(3.0d), Long.valueOf(3));
68-
assertEquals( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code",
69-
0, compare);
69+
assertEquals(0, compare,
70+
"Trying to compare objects that make no sense to the underlying encoder" +
71+
" should return a zero compare code");
7072
}
7173
}

0 commit comments

Comments
 (0)