All tests in codec migrated to JUnit 5 (#113)
unit-vintage-engine dropped from pom.xml
diff --git a/pom.xml b/pom.xml
index 4e808b6..84eb694 100644
--- a/pom.xml
+++ b/pom.xml
@@ -266,8 +266,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java b/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
index bf96e33..27bca3c 100644
--- a/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
+++ b/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
@@ -17,9 +17,9 @@
package org.apache.commons.codec;
-import static org.junit.Assert.assertThrows;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
*/
diff --git a/src/test/java/org/apache/commons/codec/CharEncodingTest.java b/src/test/java/org/apache/commons/codec/CharEncodingTest.java
index eb0e24c..3fca77a 100644
--- a/src/test/java/org/apache/commons/codec/CharEncodingTest.java
+++ b/src/test/java/org/apache/commons/codec/CharEncodingTest.java
@@ -17,8 +17,9 @@
package org.apache.commons.codec;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Sanity checks for {@link CharEncoding}.
@@ -36,32 +37,32 @@
@Test
public void testIso8859_1() {
- Assert.assertEquals("ISO-8859-1", CharEncoding.ISO_8859_1);
+ assertEquals("ISO-8859-1", CharEncoding.ISO_8859_1);
}
@Test
public void testUsAscii() {
- Assert.assertEquals("US-ASCII", CharEncoding.US_ASCII);
+ assertEquals("US-ASCII", CharEncoding.US_ASCII);
}
@Test
public void testUtf16() {
- Assert.assertEquals("UTF-16", CharEncoding.UTF_16);
+ assertEquals("UTF-16", CharEncoding.UTF_16);
}
@Test
public void testUtf16Be() {
- Assert.assertEquals("UTF-16BE", CharEncoding.UTF_16BE);
+ assertEquals("UTF-16BE", CharEncoding.UTF_16BE);
}
@Test
public void testUtf16Le() {
- Assert.assertEquals("UTF-16LE", CharEncoding.UTF_16LE);
+ assertEquals("UTF-16LE", CharEncoding.UTF_16LE);
}
@Test
public void testUtf8() {
- Assert.assertEquals("UTF-8", CharEncoding.UTF_8);
+ assertEquals("UTF-8", CharEncoding.UTF_8);
}
}
diff --git a/src/test/java/org/apache/commons/codec/CharsetsTest.java b/src/test/java/org/apache/commons/codec/CharsetsTest.java
index b9e3c19..63c5b1a 100644
--- a/src/test/java/org/apache/commons/codec/CharsetsTest.java
+++ b/src/test/java/org/apache/commons/codec/CharsetsTest.java
@@ -17,11 +17,12 @@
package org.apache.commons.codec;
+import org.junit.jupiter.api.Test;
+
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Sanity checks for {@link Charsets}.
@@ -31,46 +32,46 @@
@Test
public void testToCharset() {
- Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
- Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
- Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
- Assert.assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(StandardCharsets.UTF_8));
+ assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
+ assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
+ assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
+ assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(StandardCharsets.UTF_8));
}
@SuppressWarnings("deprecation")
@Test
public void testIso8859_1() {
- Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
+ assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
}
@SuppressWarnings("deprecation")
@Test
public void testUsAscii() {
- Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name());
+ assertEquals("US-ASCII", Charsets.US_ASCII.name());
}
@SuppressWarnings("deprecation")
@Test
public void testUtf16() {
- Assert.assertEquals("UTF-16", Charsets.UTF_16.name());
+ assertEquals("UTF-16", Charsets.UTF_16.name());
}
@SuppressWarnings("deprecation")
@Test
public void testUtf16Be() {
- Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
+ assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
}
@SuppressWarnings("deprecation")
@Test
public void testUtf16Le() {
- Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
+ assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
}
@SuppressWarnings("deprecation")
@Test
public void testUtf8() {
- Assert.assertEquals("UTF-8", Charsets.UTF_8.name());
+ assertEquals("UTF-8", Charsets.UTF_8.name());
}
}
diff --git a/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java b/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java
index 109d840..1da3641 100644
--- a/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java
+++ b/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java
@@ -17,10 +17,10 @@
package org.apache.commons.codec;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests {@link DecoderException}.
diff --git a/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java b/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java
index d2d2036..4e71961 100644
--- a/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java
+++ b/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java
@@ -17,10 +17,10 @@
package org.apache.commons.codec;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests {@link EncoderException}.
diff --git a/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java b/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java
index a3d28df..83f34bd 100644
--- a/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java
+++ b/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java
@@ -17,10 +17,11 @@
package org.apache.commons.codec;
+import org.junit.jupiter.api.Test;
+
import java.util.Locale;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
/**
*/
@@ -29,7 +30,7 @@
protected T stringEncoder = this.createStringEncoder();
public void checkEncoding(final String expected, final String source) throws EncoderException {
- Assert.assertEquals("Source: " + source, expected, this.getStringEncoder().encode(source));
+ assertEquals(expected, this.getStringEncoder().encode(source), "Source: " + source);
}
protected void checkEncodings(final String[][] data) throws EncoderException {
@@ -66,16 +67,10 @@
@Test
public void testEncodeWithInvalidObject() throws Exception {
- boolean exceptionThrown = false;
- try {
- final StringEncoder encoder = this.getStringEncoder();
- encoder.encode(Float.valueOf(3.4f));
- } catch (final Exception e) {
- exceptionThrown = true;
- }
- Assert.assertTrue("An exception was not thrown when we tried to encode " + "a Float object", exceptionThrown);
+ final StringEncoder encoder = this.getStringEncoder();
+ assertThrows(EncoderException.class, () -> encoder.encode(Float.valueOf(3.4f)),
+ "An exception was not thrown when we tried to encode a Float object");
}
-
@Test
public void testLocaleIndependence() throws Exception {
final StringEncoder encoder = this.getStringEncoder();
@@ -97,9 +92,9 @@
try {
cur = encoder.encode(element);
} catch (final Exception e) {
- Assert.fail(Locale.getDefault().toString() + ": " + e.getMessage());
+ fail(Locale.getDefault().toString() + ": " + e.getMessage());
}
- Assert.assertEquals(Locale.getDefault().toString() + ": ", ref, cur);
+ assertEquals(ref, cur, Locale.getDefault().toString() + ": ");
}
}
}
diff --git a/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java b/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java
index e6d8627..5d445db 100644
--- a/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java
+++ b/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java
@@ -17,14 +17,14 @@
package org.apache.commons.codec;
-import static org.junit.Assert.assertEquals;
-
import java.util.Arrays;
import java.util.List;
import org.apache.commons.codec.language.DoubleMetaphone;
import org.apache.commons.codec.language.Soundex;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test cases for the StingEncoderComparator.
@@ -36,8 +36,8 @@
final StringEncoderComparator sCompare =
new StringEncoderComparator( new Soundex() );
- assertEquals("O'Brien and O'Brian didn't come out with " +
- "the same Soundex, something must be wrong here", 0, sCompare.compare("O'Brien", "O'Brian"));
+ assertEquals(0, sCompare.compare("O'Brien", "O'Brian"),
+ "O'Brien and O'Brian didn't come out with the same Soundex, something must be wrong here");
}
@SuppressWarnings("unchecked") // cannot easily avoid this warning
@@ -55,7 +55,8 @@
final String[] resultArray = testList.toArray(new String[0]);
for (int i = 0; i < resultArray.length; i++) {
- assertEquals("Result Array not Equal to Control Array at index: " + i, controlArray[i], resultArray[i]);
+ assertEquals(controlArray[i], resultArray[i],
+ "Result Array not Equal to Control Array at index: " + i);
}
}
@@ -65,7 +66,8 @@
new StringEncoderComparator( new DoubleMetaphone() );
final int compare = sCompare.compare(Double.valueOf(3.0d), Long.valueOf(3));
- assertEquals( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code",
- 0, compare);
+ assertEquals(0, compare,
+ "Trying to compare objects that make no sense to the underlying encoder" +
+ " should return a zero compare code");
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base16InputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base16InputStreamTest.java
index 14d56b0..504c6b2 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base16InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base16InputStreamTest.java
@@ -17,16 +17,13 @@
package org.apache.commons.codec.binary;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @since 1.15
@@ -170,18 +167,18 @@
try (final InputStream in = new Base16InputStream(new ByteArrayInputStream(decoded), true, lowerCase)) {
final byte[] output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming Base16 encode", encoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(encoded, output, "Streaming Base16 encode");
}
// Now let's try decode.
try (final InputStream in = new Base16InputStream(new ByteArrayInputStream(encoded), false, lowerCase)) {
final byte[] output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming Base16 decode", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming Base16 decode");
}
// wrap encoder with decoder
@@ -191,9 +188,9 @@
final byte[] output = BaseNTestData.streamToBytes(inDecode);
- assertEquals("EOF", -1, inDecode.read());
- assertEquals("Still EOF", -1, inDecode.read());
- assertArrayEquals("Streaming Base16 wrap-wrap!", decoded, output);
+ assertEquals(-1, inDecode.read(), "EOF");
+ assertEquals(-1, inDecode.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming Base16 wrap-wrap!");
}
}
@@ -233,9 +230,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming Base16 encode", encoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(encoded, output, "Streaming Base16 encode");
}
// Now let's try decode.
@@ -245,9 +242,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming Base16 decode", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming Base16 decode");
}
// wrap encoder with decoder
@@ -260,9 +257,9 @@
output[i] = (byte) inDecode.read();
}
- assertEquals("EOF", -1, inDecode.read());
- assertEquals("Still EOF", -1, inDecode.read());
- assertArrayEquals("Streaming Base16 wrap-wrap!", decoded, output);
+ assertEquals(-1, inDecode.read(), "EOF");
+ assertEquals(-1, inDecode.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming Base16 wrap-wrap!");
}
}
@@ -277,7 +274,7 @@
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base16InputStream in = new Base16InputStream(bin, true)) {
// Always returns false for now.
- assertFalse("Base16InputStream.markSupported() is false", in.markSupported());
+ assertFalse(in.markSupported(), "Base16InputStream.markSupported() is false");
}
}
@@ -294,7 +291,7 @@
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base16InputStream in = new Base16InputStream(bin, true)) {
bytesRead = in.read(buf, 0, 0);
- assertEquals("Base16InputStream.read(buf, 0, 0) returns 0", 0, bytesRead);
+ assertEquals(0, bytesRead, "Base16InputStream.read(buf, 0, 0) returns 0");
}
}
@@ -308,7 +305,8 @@
final byte[] decoded = StringUtils.getBytesUtf8(STRING_FIXTURE);
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base16InputStream in = new Base16InputStream(bin, true)) {
- assertThrows(NullPointerException.class, () -> in.read(null, 0, 0));
+ assertThrows(NullPointerException.class, () -> in.read(null, 0, 0),
+ "Base16InputStream.read(null, 0, 0)");
}
}
@@ -323,10 +321,10 @@
final byte[] buf = new byte[1024];
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base16InputStream in = new Base16InputStream(bin, true)) {
- assertThrows("Base16InputStream.read(buf, -1, 0)", IndexOutOfBoundsException.class, () -> in.read(buf, -1, 0));
- assertThrows("Base16InputStream.read(buf, 0, -1)", IndexOutOfBoundsException.class, () -> in.read(buf, 0, -1));
- assertThrows("Base16InputStream.read(buf, buf.length + 1, 0)", IndexOutOfBoundsException.class, () -> in.read(buf, buf.length + 1, 0));
- assertThrows("Base16InputStream.read(buf, buf.length - 1, 2)", IndexOutOfBoundsException.class, () -> in.read(buf, buf.length - 1, 2));
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, -1, 0), "Base16InputStream.read(buf, -1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, 0, -1), "Base16InputStream.read(buf, 0, -1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, buf.length + 1, 0), "Base16InputStream.read(buf, buf.length + 1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, buf.length - 1, 2), "Base16InputStream.read(buf, buf.length - 1, 2)");
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base16OutputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base16OutputStreamTest.java
index bac1304..37cb5ab 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base16OutputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base16OutputStreamTest.java
@@ -17,14 +17,14 @@
package org.apache.commons.codec.binary;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @since 1.15
@@ -134,7 +134,7 @@
final OutputStream out = new Base16OutputStream(byteOut, true, lowerCase)) {
out.write(decoded);
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked base16 encode", encoded, output);
+ assertArrayEquals(encoded, output, "Streaming chunked base16 encode");
}
// Now let's try decode.
@@ -142,7 +142,7 @@
final OutputStream out = new Base16OutputStream(byteOut, false, lowerCase)) {
out.write(encoded);
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked base16 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming chunked base16 decode");
}
// wrap encoder with decoder
@@ -153,7 +153,7 @@
encoderOut.write(decoded);
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked base16 wrap-wrap!", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming chunked base16 wrap-wrap!");
}
}
@@ -192,7 +192,7 @@
out.write(element);
}
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte base16 encode", encoded, output);
+ assertArrayEquals(encoded, output, "Streaming byte-by-byte base16 encode");
}
// Now let's try decode.
@@ -202,7 +202,7 @@
out.write(element);
}
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte base16 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte base16 decode");
}
// Now let's try decode with tonnes of flushes.
@@ -213,7 +213,7 @@
out.flush();
}
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte flush() base16 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte flush() base16 decode");
}
// wrap encoder with decoder
@@ -224,7 +224,7 @@
encoderOut.write(element);
}
final byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte base16 wrap-wrap!", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte base16 wrap-wrap!");
}
}
@@ -238,10 +238,10 @@
final byte[] buf = new byte[1024];
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
try (final Base16OutputStream out = new Base16OutputStream(bout)) {
- assertThrows("Base16InputStream.write(buf, -1, 0)", IndexOutOfBoundsException.class, () -> out.write(buf, -1, 1));
- assertThrows("Base16InputStream.write(buf, 1, -1)", IndexOutOfBoundsException.class, () -> out.write(buf, 1, -1));
- assertThrows("Base16InputStream.write(buf, buf.length + 1, 0)", IndexOutOfBoundsException.class, () -> out.write(buf, buf.length + 1, 0));
- assertThrows("Base16InputStream.write(buf, buf.length - 1, 2)", IndexOutOfBoundsException.class, () -> out.write(buf, buf.length - 1, 2));
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, -1, 1), "Base16InputStream.write(buf, -1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, 1, -1), "Base16InputStream.write(buf, 1, -1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, buf.length + 1, 0), "Base16InputStream.write(buf, buf.length + 1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, buf.length - 1, 2), "Base16InputStream.write(buf, buf.length - 1, 2)");
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base16Test.java b/src/test/java/org/apache/commons/codec/binary/Base16Test.java
index e957673..a015c69 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base16Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base16Test.java
@@ -21,18 +21,13 @@
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.lang3.ArrayUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Random;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Test cases for Base16 class.
@@ -60,11 +55,11 @@
final String content = "Hello World";
final byte[] encodedBytes = new Base16().encode(StringUtils.getBytesUtf8(content));
final String encodedContent = StringUtils.newStringUtf8(encodedBytes);
- assertEquals("encoding hello world", "48656C6C6F20576F726C64", encodedContent);
+ assertEquals("48656C6C6F20576F726C64", encodedContent, "encoding hello world");
final byte[] decodedBytes = new Base16().decode(encodedBytes);
final String decodedContent = StringUtils.newStringUtf8(decodedBytes);
- assertEquals("decoding hello world", content, decodedContent);
+ assertEquals(content, decodedContent, "decoding hello world");
}
@Test
@@ -90,7 +85,7 @@
buffer = ArrayUtils.addAll(new byte[startPasSize], buffer);
final byte[] encodedBytes = new Base16().encode(buffer, startPasSize, bytesUtf8.length);
encodedContent = StringUtils.newStringUtf8(encodedBytes);
- assertEquals("encoding hello world", "48656C6C6F20576F726C64", encodedContent);
+ assertEquals("48656C6C6F20576F726C64", encodedContent, "encoding hello world");
}
/**
@@ -119,7 +114,7 @@
final byte[] encoded = base16.encode(BaseNTestData.DECODED);
final String expectedResult = Base16TestData.ENCODED_UTF8_LOWERCASE;
final String result = StringUtils.newStringUtf8(encoded);
- assertEquals("new Base16(true)", expectedResult, result);
+ assertEquals(expectedResult, result, "new Base16(true)");
}
@Test
@@ -128,7 +123,7 @@
final byte[] encoded = base16.encode(BaseNTestData.DECODED);
final String expectedResult = Base16TestData.ENCODED_UTF8_UPPERCASE;
final String result = StringUtils.newStringUtf8(encoded);
- assertEquals("new base16(false, CodecPolicy.STRICT)", result, expectedResult);
+ assertEquals(result, expectedResult, "new base16(false, CodecPolicy.STRICT)");
}
/**
@@ -138,16 +133,16 @@
public void testEmptyBase16() {
byte[] empty = {};
byte[] result = new Base16().encode(empty);
- assertEquals("empty Base16 encode", 0, result.length);
- assertNull("empty Base16 encode", new Base16().encode(null));
+ assertEquals(0, result.length, "empty Base16 encode");
+ assertNull(new Base16().encode(null), "empty Base16 encode");
result = new Base16().encode(empty, 0, 1);
- assertEquals("empty Base16 encode with offset", 0, result.length);
- assertNull("empty Base16 encode with offset", new Base16().encode(null));
+ assertEquals(0, result.length, "empty Base16 encode with offset");
+ assertNull(new Base16().encode(null), "empty Base16 encode with offset");
empty = new byte[0];
result = new Base16().decode(empty);
- assertEquals("empty Base16 decode", 0, result.length);
- assertNull("empty Base16 encode", new Base16().decode((byte[]) null));
+ assertEquals(0, result.length, "empty Base16 decode");
+ assertNull(new Base16().decode((byte[]) null), "empty Base16 encode");
}
// encode/decode a large random array
@@ -171,7 +166,7 @@
this.getRandom().nextBytes(data);
final byte[] enc = new Base16().encode(data);
final byte[] data2 = new Base16().decode(enc);
- assertArrayEquals(toString(data) + " equals " + toString(data2), data, data2);
+ assertArrayEquals(data, data2, toString(data) + " equals " + toString(data2));
}
}
@@ -212,7 +207,7 @@
final byte[] encoded = new byte[1];
for (final byte invalidEncodedChar : invalidEncodedChars) {
encoded[0] = invalidEncodedChar;
- assertThrows("Invalid Base16 char: " + (char) invalidEncodedChar, IllegalArgumentException.class, () -> new Base16().decode(encoded));
+ assertThrows(IllegalArgumentException.class, () -> new Base16().decode(encoded), "Invalid Base16 char: " + (char) invalidEncodedChar);
}
}
@@ -231,7 +226,7 @@
final byte[] baDecoded = (byte[]) oDecoded;
final String dest = new String(baDecoded);
- assertEquals("dest string does not equal original", original, dest);
+ assertEquals(original, dest, "dest string does not equal original");
}
@Test
@@ -248,13 +243,13 @@
final byte[] bArray = new Base16().decode((byte[]) oEncoded);
final String dest = new String(bArray);
- assertEquals("dest string does not equal original", original, dest);
+ assertEquals(original, dest, "dest string does not equal original");
}
@Test
public void testObjectEncode() {
final Base16 b16 = new Base16();
- assertEquals("48656C6C6F20576F726C64", new String(b16.encode("Hello World".getBytes(CHARSET_UTF8))));
+ assertEquals(new String(b16.encode("Hello World".getBytes(CHARSET_UTF8))), "48656C6C6F20576F726C64");
}
@Test
@@ -423,12 +418,12 @@
final byte[] b2 = {};
final byte[] b3 = null;
- assertEquals("byteToString Hello World", "48656C6C6F20576F726C64", base16.encodeToString(b1));
- assertEquals("byteToString static Hello World", "48656C6C6F20576F726C64", StringUtils.newStringUtf8(new Base16().encode(b1)));
- assertEquals("byteToString \"\"", "", base16.encodeToString(b2));
- assertEquals("byteToString static \"\"", "", StringUtils.newStringUtf8(new Base16().encode(b2)));
- assertNull("byteToString null", base16.encodeToString(b3));
- assertNull("byteToString static null", StringUtils.newStringUtf8(new Base16().encode(b3)));
+ assertEquals("48656C6C6F20576F726C64", base16.encodeToString(b1), "byteToString Hello World");
+ assertEquals("48656C6C6F20576F726C64", StringUtils.newStringUtf8(new Base16().encode(b1)), "byteToString static Hello World");
+ assertEquals("", base16.encodeToString(b2), "byteToString \"\"");
+ assertEquals("", StringUtils.newStringUtf8(new Base16().encode(b2)), "byteToString static \"\"");
+ assertNull(base16.encodeToString(b3), "byteToString null");
+ assertNull(StringUtils.newStringUtf8(new Base16().encode(b3)), "byteToString static null");
}
@Test
@@ -438,15 +433,13 @@
final String s2 = "";
final String s3 = null;
- assertEquals("StringToByte Hello World", "Hello World", StringUtils.newStringUtf8(base16.decode(s1)));
- assertEquals("StringToByte Hello World", "Hello World",
- StringUtils.newStringUtf8((byte[]) new Base16().decode((Object) s1)));
- assertEquals("StringToByte static Hello World", "Hello World",
- StringUtils.newStringUtf8(new Base16().decode(s1)));
- assertEquals("StringToByte \"\"", "", StringUtils.newStringUtf8(new Base16().decode(s2)));
- assertEquals("StringToByte static \"\"", "", StringUtils.newStringUtf8(new Base16().decode(s2)));
- assertNull("StringToByte null", StringUtils.newStringUtf8(new Base16().decode(s3)));
- assertNull("StringToByte static null", StringUtils.newStringUtf8(new Base16().decode(s3)));
+ assertEquals("Hello World", StringUtils.newStringUtf8(base16.decode(s1)), "StringToByte Hello World");
+ assertEquals("Hello World", StringUtils.newStringUtf8((byte[]) new Base16().decode((Object) s1)), "StringToByte Hello World");
+ assertEquals("Hello World", StringUtils.newStringUtf8(new Base16().decode(s1)), "StringToByte static Hello World");
+ assertEquals("", StringUtils.newStringUtf8(new Base16().decode(s2)), "StringToByte \"\"");
+ assertEquals("", StringUtils.newStringUtf8(new Base16().decode(s2)), "StringToByte static \"\"");
+ assertNull(StringUtils.newStringUtf8(new Base16().decode(s3)), "StringToByte null");
+ assertNull(StringUtils.newStringUtf8(new Base16().decode(s3)), "StringToByte static null");
}
private String toString(final byte[] data) {
diff --git a/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
index 06deca8..b7da9bb 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
@@ -23,13 +23,9 @@
import java.io.InputStream;
import org.apache.commons.codec.CodecPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
public class Base32InputStreamTest {
@@ -288,17 +284,17 @@
in = new Base32InputStream(new ByteArrayInputStream(decoded), true, chunkSize, separator);
byte[] output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base32 encode", encoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(encoded, output, "Streaming base32 encode");
// Now let's try decode.
in = new Base32InputStream(new ByteArrayInputStream(encoded));
output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base32 decode", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base32 decode");
// I always wanted to do this! (wrap encoder with decoder etc etc).
in = new ByteArrayInputStream(decoded);
@@ -308,9 +304,9 @@
}
output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base32 wrap-wrap-wrap!", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base32 wrap-wrap-wrap!");
in.close();
}
@@ -342,9 +338,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base32 encode", encoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(encoded, output, "Streaming base32 encode");
in.close();
@@ -355,9 +351,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base32 decode", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base32 decode");
in.close();
@@ -372,9 +368,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base32 wrap-wrap-wrap!", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base32 wrap-wrap-wrap!");
}
/**
@@ -389,7 +385,7 @@
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base32InputStream in = new Base32InputStream(bin, true, 4, new byte[] { 0, 0, 0 })) {
// Always returns false for now.
- assertFalse("Base32InputStream.markSupported() is false", in.markSupported());
+ assertFalse(in.markSupported(), "Base32InputStream.markSupported() is false");
}
}
@@ -407,7 +403,7 @@
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base32InputStream in = new Base32InputStream(bin, true, 4, new byte[] { 0, 0, 0 })) {
bytesRead = in.read(buf, 0, 0);
- assertEquals("Base32InputStream.read(buf, 0, 0) returns 0", 0, bytesRead);
+ assertEquals(0, bytesRead, "Base32InputStream.read(buf, 0, 0) returns 0");
}
}
@@ -438,10 +434,10 @@
final byte[] buf = new byte[1024];
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base32InputStream in = new Base32InputStream(bin, true, 4, new byte[] { 0, 0, 0 })) {
- assertThrows("Base32InputStream.read(buf, -1, 0)", IndexOutOfBoundsException.class, () -> in.read(buf, -1, 0));
- assertThrows("Base32InputStream.read(buf, 0, -1)", IndexOutOfBoundsException.class, () -> in.read(buf, 0, -1));
- assertThrows("Base32InputStream.read(buf, buf.length + 1, 0)", IndexOutOfBoundsException.class, () -> in.read(buf, buf.length + 1, 0));
- assertThrows("Base32InputStream.read(buf, buf.length - 1, 2)", IndexOutOfBoundsException.class, () -> in.read(buf, buf.length - 1, 2));
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, -1, 0), "Base32InputStream.read(buf, -1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, 0, -1), "Base32InputStream.read(buf, 0, -1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, buf.length + 1, 0), "Base32InputStream.read(buf, buf.length + 1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, buf.length - 1, 2), "Base32InputStream.read(buf, buf.length - 1, 2)");
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java
index 27660af..0780da3 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32OutputStreamTest.java
@@ -21,12 +21,9 @@
import java.io.OutputStream;
import org.apache.commons.codec.CodecPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
public class Base32OutputStreamTest {
@@ -185,7 +182,7 @@
out.write(decoded);
out.close();
byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked Base32 encode", encoded, output);
+ assertArrayEquals(encoded, output, "Streaming chunked Base32 encode");
// Now let's try decode.
byteOut = new ByteArrayOutputStream();
@@ -193,7 +190,7 @@
out.write(encoded);
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked Base32 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming chunked Base32 decode");
// I always wanted to do this! (wrap encoder with decoder etc etc).
byteOut = new ByteArrayOutputStream();
@@ -206,7 +203,7 @@
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked Base32 wrap-wrap-wrap!", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming chunked Base32 wrap-wrap-wrap!");
}
/**
@@ -237,7 +234,7 @@
}
out.close();
byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte Base32 encode", encoded, output);
+ assertArrayEquals(encoded, output, "Streaming byte-by-byte Base32 encode");
// Now let's try decode.
byteOut = new ByteArrayOutputStream();
@@ -247,7 +244,7 @@
}
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte Base32 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte Base32 decode");
// Now let's try decode with tonnes of flushes.
byteOut = new ByteArrayOutputStream();
@@ -258,7 +255,7 @@
}
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte flush() Base32 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte flush() Base32 decode");
// I always wanted to do this! (wrap encoder with decoder etc etc).
byteOut = new ByteArrayOutputStream();
@@ -273,7 +270,7 @@
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte Base32 wrap-wrap-wrap!", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte Base32 wrap-wrap-wrap!");
}
/**
@@ -287,10 +284,10 @@
final byte[] buf = new byte[1024];
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
try (final Base32OutputStream out = new Base32OutputStream(bout)) {
- assertThrows("Base32OutputStream.write(buf, -1, 1)", IndexOutOfBoundsException.class, () -> out.write(buf, -1, 1));
- assertThrows("Base32OutputStream.write(buf, 1, -1)", IndexOutOfBoundsException.class, () -> out.write(buf, 1, -1));
- assertThrows("Base32OutputStream.write(buf, buf, buf.length + 1, 0)", IndexOutOfBoundsException.class, () -> out.write(buf, buf.length + 1, 0));
- assertThrows("Base32OutputStream.write(buf, buf, buf.length - 1, 2)", IndexOutOfBoundsException.class, () -> out.write(buf, buf.length - 1, 2));
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, -1, 1), "Base32OutputStream.write(buf, -1, 1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, 1, -1), "Base32OutputStream.write(buf, 1, -1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, buf.length + 1, 0), "Base32OutputStream.write(buf, buf, buf.length + 1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, buf.length - 1, 2), "Base32OutputStream.write(buf, buf, buf.length - 1, 2)");
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base32Test.java b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
index 713c80d..3b04b3e 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
@@ -17,26 +17,18 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.apache.commons.codec.CodecPolicy;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.lang3.ArrayUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class Base32Test {
-
private static final Charset CHARSET_UTF8 = StandardCharsets.UTF_8;
private static final String [][] BASE32_TEST_CASES = { // RFC 4648
@@ -252,12 +244,13 @@
// even when line length is negative.
base32 = new Base32(-1, new byte[] {'A'});
base32 = new Base32(32, new byte[] {'$'}); // OK
- assertThrows("null line separator", IllegalArgumentException.class, () -> new Base32(32, null));
- assertThrows("'A' as a line separator", IllegalArgumentException.class, () -> new Base32(32, new byte[] {'A'}));
- assertThrows("'=' as a line separator", IllegalArgumentException.class, () -> new Base32(32, new byte[] {'='}));
- assertThrows("'A$' as a line separator", IllegalArgumentException.class, () -> new Base32(32, new byte[] {'A', '$'}));
- assertThrows("'A' as padding", IllegalArgumentException.class, () -> new Base32(32, new byte[] {'\n'}, false, (byte) 'A'));
- assertThrows("' ' as padding", IllegalArgumentException.class, () -> new Base32(32, new byte[] {'\n'}, false, (byte) ' '));
+ assertThrows(IllegalArgumentException.class, () -> new Base32(32, null), "null line separator");
+ assertThrows(IllegalArgumentException.class, () -> new Base32(32, new byte[] {'A'}), "'A' as a line separator");
+ assertThrows(IllegalArgumentException.class, () -> new Base32(32, new byte[] {'='}), "'=' as a line separator");
+ assertThrows(IllegalArgumentException.class, () -> new Base32(32, new byte[] {'A', '$'}), "'A$' as a line separator");
+ assertThrows(IllegalArgumentException.class, () -> new Base32(32, new byte[] {'\n'}, false, (byte) 'A'), "'A' as padding");
+ assertThrows(IllegalArgumentException.class, () -> new Base32(32, new byte[] {'\n'}, false, (byte) ' '), "' ' as padding");
+
base32 = new Base32(32, new byte[] {' ', '$', '\n', '\r', '\t'}); // OK
assertNotNull(base32);
}
@@ -269,16 +262,16 @@
public void testEmptyBase32() {
byte[] empty = {};
byte[] result = new Base32().encode(empty);
- assertEquals("empty Base32 encode", 0, result.length);
- assertNull("empty Base32 encode", new Base32().encode(null));
+ assertEquals(0, result.length, "empty Base32 encode");
+ assertNull(new Base32().encode(null), "empty Base32 encode");
result = new Base32().encode(empty, 0, 1);
- assertEquals("empty Base32 encode with offset", 0, result.length);
- assertNull("empty Base32 encode with offset", new Base32().encode(null));
+ assertEquals(0, result.length, "empty Base32 encode with offset");
+ assertNull(new Base32().encode(null), "empty Base32 encode with offset");
empty = new byte[0];
result = new Base32().decode(empty);
- assertEquals("empty Base32 decode", 0, result.length);
- assertNull("empty Base32 encode", new Base32().decode((byte[]) null));
+ assertEquals(0, result.length, "empty Base32 decode");
+ assertNull(new Base32().decode((byte[]) null), "empty Base32 encode");
}
@Test
@@ -334,7 +327,7 @@
for (int i = 0; i < 20; i++) {
final Base32 codec = new Base32();
final byte[][] b = BaseNTestData.randomData(codec, i);
- assertEquals(""+i+" "+codec.lineLength,b[1].length,codec.getEncodedLength(b[0]));
+ assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength);
//assertEquals(b[0],codec.decode(b[1]));
}
}
@@ -344,7 +337,7 @@
for (int i = 0; i < 20; i++) {
final Base32 codec = new Base32(10);
final byte[][] b = BaseNTestData.randomData(codec, i);
- assertEquals(""+i+" "+codec.lineLength,b[1].length,codec.getEncodedLength(b[0]));
+ assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength);
//assertEquals(b[0],codec.decode(b[1]));
}
}
@@ -354,7 +347,7 @@
for (int i = 0; i < 20; i++) {
final Base32 codec = new Base32(true);
final byte[][] b = BaseNTestData.randomData(codec, i);
- assertEquals(""+i+" "+codec.lineLength,b[1].length,codec.getEncodedLength(b[0]));
+ assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength);
//assertEquals(b[0],codec.decode(b[1]));
}
}
@@ -475,7 +468,7 @@
// If the lower bits are set we expect an exception. This is not a valid
// final character.
if (invalid || (i & emptyBitsMask) != 0) {
- assertThrows("Final base-32 digit should not be allowed", IllegalArgumentException.class, () -> codec.decode(encoded));
+ assertThrows(IllegalArgumentException.class, () -> codec.decode(encoded), "Final base-32 digit should not be allowed");
// The default lenient mode should decode this
final byte[] decoded = defaultCodec.decode(encoded);
// Re-encoding should not match the original array as it was invalid
@@ -485,7 +478,7 @@
final byte[] decoded = codec.decode(encoded);
// Compute the bits that were encoded. This should match the final decoded byte.
final int bitsEncoded = i >> discard;
- assertEquals("Invalid decoding of last character", bitsEncoded, decoded[decoded.length - 1]);
+ assertEquals(bitsEncoded, decoded[decoded.length - 1], "Invalid decoding of last character");
// Re-encoding should match the original array (requires the same padding character)
assertArrayEquals(encoded, codec.encode(decoded));
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Codec13Test.java b/src/test/java/org/apache/commons/codec/binary/Base64Codec13Test.java
index 4a044b1..e84bb82 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Codec13Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Codec13Test.java
@@ -17,10 +17,7 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertTrue;
-
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
@@ -28,7 +25,9 @@
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.Encoder;
import org.apache.commons.codec.EncoderException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
/**
* Tests to make sure future versions of commons-codec.jar have identical Base64
@@ -368,8 +367,7 @@
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(base64, (byte[]) enc.encode(binary));
- assertTrue("Encoder test-" + i, b);
+ assertArrayEquals(base64, (byte[]) enc.encode(binary), "Encoder test-" + i);
}
}
}
@@ -387,8 +385,7 @@
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(binary, (byte[]) dec.decode(base64));
- assertTrue("Decoder test-" + i, b);
+ assertArrayEquals(binary, (byte[]) dec.decode(base64), "Decoder test-" + i);
}
}
}
@@ -406,8 +403,7 @@
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(base64, enc.encode(binary));
- assertTrue("BinaryEncoder test-" + i, b);
+ assertArrayEquals(base64, enc.encode(binary), "BinaryEncoder test-" + i);
}
}
}
@@ -425,8 +421,7 @@
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(binary, dec.decode(base64));
- assertTrue("BinaryDecoder test-" + i, b);
+ assertArrayEquals(binary, dec.decode(base64), "BinaryDecoder test-" + i);
}
}
}
@@ -443,8 +438,8 @@
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(base64, Base64.encodeBase64(binary));
- assertTrue("static Base64.encodeBase64() test-" + i, b);
+ assertArrayEquals(base64, Base64.encodeBase64(binary),
+ "static Base64.encodeBase64() test-" + i);
}
}
}
@@ -461,8 +456,8 @@
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(binary, Base64.decodeBase64(base64));
- assertTrue("static Base64.decodeBase64() test-" + i, b);
+ assertArrayEquals(binary, Base64.decodeBase64(base64),
+ "static Base64.decodeBase64() test-" + i);
}
}
}
@@ -479,8 +474,8 @@
if (STRINGS[i] != null) {
final byte[] base64Chunked = utf8(CHUNKED_STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(base64Chunked, Base64.encodeBase64Chunked(binary));
- assertTrue("static Base64.encodeBase64Chunked() test-" + i, b);
+ assertArrayEquals(base64Chunked, Base64.encodeBase64Chunked(binary),
+ "static Base64.encodeBase64Chunked() test-" + i);
}
}
}
@@ -498,8 +493,8 @@
if (STRINGS[i] != null) {
final byte[] base64Chunked = utf8(CHUNKED_STRINGS[i]);
final byte[] binary = BYTES[i];
- final boolean b = Arrays.equals(binary, Base64.decodeBase64(base64Chunked));
- assertTrue("static Base64.decodeBase64Chunked() test-" + i, b);
+ assertArrayEquals(binary, Base64.decodeBase64(base64Chunked),
+ "static Base64.decodeBase64Chunked() test-" + i);
}
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
index 0472b99..5c91542 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
@@ -25,14 +25,9 @@
import java.io.InputStreamReader;
import org.apache.commons.codec.CodecPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @since 1.4
@@ -96,10 +91,10 @@
try (final Base64InputStream in = new Base64InputStream(bais)) {
final byte[] result = new byte[8192];
int c = in.read(result);
- assertTrue("Codec101: First read successful [c=" + c + "]", c > 0);
+ assertTrue(c > 0, "Codec101: First read successful [c=" + c + "]");
c = in.read(result);
- assertTrue("Codec101: Second read should report end-of-stream [c=" + c + "]", c < 0);
+ assertTrue(c < 0, "Codec101: Second read should report end-of-stream [c=" + c + "]");
}
}
@@ -126,7 +121,7 @@
final InputStreamReader isr = new InputStreamReader(in);
try (final BufferedReader br = new BufferedReader(isr)) {
final String line = br.readLine();
- assertNotNull("Codec101: InputStreamReader works!", line);
+ assertNotNull(line, "Codec101: InputStreamReader works!");
}
}
@@ -146,7 +141,7 @@
final byte[] decodedBytes = BaseNTestData.streamToBytes(stream, new byte[1024]);
final String decoded = StringUtils.newStringUtf8(decodedBytes);
- assertEquals("codec-98 NPE Base64InputStream", Base64TestData.CODEC_98_NPE_DECODED, decoded);
+ assertEquals(Base64TestData.CODEC_98_NPE_DECODED, decoded, "codec-98 NPE Base64InputStream");
}
/**
@@ -301,9 +296,9 @@
in = new Base64InputStream(new ByteArrayInputStream(decoded), true, chunkSize, separator);
byte[] output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base64 encode", encoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(encoded, output, "Streaming base64 encode");
in.close();
@@ -311,9 +306,9 @@
in = new Base64InputStream(new ByteArrayInputStream(encoded));
output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base64 decode", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base64 decode");
// I always wanted to do this! (wrap encoder with decoder etc etc).
in = new ByteArrayInputStream(decoded);
@@ -323,9 +318,9 @@
}
output = BaseNTestData.streamToBytes(in);
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base64 wrap-wrap-wrap!", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base64 wrap-wrap-wrap!");
in.close();
}
@@ -357,9 +352,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base64 encode", encoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(encoded, output, "Streaming base64 encode");
in.close();
// Now let's try decode.
@@ -369,9 +364,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base64 decode", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base64 decode");
in.close();
@@ -386,9 +381,9 @@
output[i] = (byte) in.read();
}
- assertEquals("EOF", -1, in.read());
- assertEquals("Still EOF", -1, in.read());
- assertArrayEquals("Streaming base64 wrap-wrap-wrap!", decoded, output);
+ assertEquals(-1, in.read(), "EOF");
+ assertEquals(-1, in.read(), "Still EOF");
+ assertArrayEquals(decoded, output, "Streaming base64 wrap-wrap-wrap!");
in.close();
}
@@ -404,7 +399,7 @@
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base64InputStream in = new Base64InputStream(bin, true, 4, new byte[] { 0, 0, 0 })) {
// Always returns false for now.
- assertFalse("Base64InputStream.markSupported() is false", in.markSupported());
+ assertFalse(in.markSupported(), "Base64InputStream.markSupported() is false");
}
}
@@ -446,7 +441,7 @@
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base64InputStream in = new Base64InputStream(bin, true, 4, new byte[] { 0, 0, 0 })) {
bytesRead = in.read(buf, 0, 0);
- assertEquals("Base64InputStream.read(buf, 0, 0) returns 0", 0, bytesRead);
+ assertEquals(0, bytesRead, "Base64InputStream.read(buf, 0, 0) returns 0");
}
}
@@ -477,10 +472,10 @@
final byte[] buf = new byte[1024];
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base64InputStream in = new Base64InputStream(bin, true, 4, new byte[] {0, 0, 0})) {
- assertThrows("Base64InputStream.read(buf, -1, 0)", IndexOutOfBoundsException.class, () -> in.read(buf, -1, 0));
- assertThrows("Base64InputStream.read(buf, 0, -1)", IndexOutOfBoundsException.class, () -> in.read(buf, 0, -1));
- assertThrows("Base64InputStream.read(buf, buf.length + 1, 0)", IndexOutOfBoundsException.class, () -> in.read(buf, buf.length + 1, 0));
- assertThrows("Base64InputStream.read(buf, buf.length - 1, 2)", IndexOutOfBoundsException.class, () -> in.read(buf, buf.length - 1, 2));
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, -1, 0), "Base64InputStream.read(buf, -1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, 0, -1), "Base64InputStream.read(buf, 0, -1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, buf.length + 1, 0), "Base64InputStream.read(buf, buf.length + 1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, buf.length - 1, 2), "Base64InputStream.read(buf, buf.length - 1, 2)");
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java
index 3648834..39fa2ad 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java
@@ -21,14 +21,9 @@
import java.io.OutputStream;
import org.apache.commons.codec.CodecPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @since 1.4
@@ -59,7 +54,7 @@
final byte[] decodedBytes = data.toByteArray();
final String decoded = StringUtils.newStringUtf8(decodedBytes);
- assertEquals("codec-98 NPE Base64OutputStream", Base64TestData.CODEC_98_NPE_DECODED, decoded);
+ assertEquals(Base64TestData.CODEC_98_NPE_DECODED, decoded, "codec-98 NPE Base64OutputStream");
}
@@ -196,7 +191,7 @@
out.write(decoded);
out.close();
byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked base64 encode", encoded, output);
+ assertArrayEquals(encoded, output, "Streaming chunked base64 encode");
// Now let's try decode.
byteOut = new ByteArrayOutputStream();
@@ -204,7 +199,7 @@
out.write(encoded);
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked base64 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming chunked base64 decode");
// I always wanted to do this! (wrap encoder with decoder etc etc).
byteOut = new ByteArrayOutputStream();
@@ -217,7 +212,7 @@
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming chunked base64 wrap-wrap-wrap!", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming chunked base64 wrap-wrap-wrap!");
}
/**
@@ -248,7 +243,7 @@
}
out.close();
byte[] output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte base64 encode", encoded, output);
+ assertArrayEquals(encoded, output, "Streaming byte-by-byte base64 encode");
// Now let's try decode.
byteOut = new ByteArrayOutputStream();
@@ -258,7 +253,7 @@
}
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte base64 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte base64 decode");
// Now let's try decode with tonnes of flushes.
byteOut = new ByteArrayOutputStream();
@@ -269,7 +264,7 @@
}
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte flush() base64 decode", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte flush() base64 decode");
// I always wanted to do this! (wrap encoder with decoder etc etc).
byteOut = new ByteArrayOutputStream();
@@ -284,7 +279,7 @@
out.close();
output = byteOut.toByteArray();
- assertArrayEquals("Streaming byte-by-byte base64 wrap-wrap-wrap!", decoded, output);
+ assertArrayEquals(decoded, output, "Streaming byte-by-byte base64 wrap-wrap-wrap!");
}
/**
@@ -298,10 +293,10 @@
final byte[] buf = new byte[1024];
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
try (final Base64OutputStream out = new Base64OutputStream(bout)) {
- assertThrows("Base64OutputStream.write(buf, -1, 1)", IndexOutOfBoundsException.class, () -> out.write(buf, -1, 1));
- assertThrows("Base64OutputStream.write(buf, 1, -1)", IndexOutOfBoundsException.class, () -> out.write(buf, 1, -1));
- assertThrows("Base64OutputStream.write(buf, buf.length + 1, 0)", IndexOutOfBoundsException.class, () -> out.write(buf, buf.length + 1, 0));
- assertThrows("Base64OutputStream.write(buf, buf.length - 1, 2)", IndexOutOfBoundsException.class, () -> out.write(buf, buf.length - 1, 2));
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, -1, 1), "Base64OutputStream.write(buf, -1, 1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, 1, -1), "Base64OutputStream.write(buf, 1, -1)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, buf.length + 1, 0), "Base64OutputStream.write(buf, buf.length + 1, 0)");
+ assertThrows(IndexOutOfBoundsException.class, () -> out.write(buf, buf.length - 1, 2), "Base64OutputStream.write(buf, buf.length - 1, 2)");
}
}
@@ -340,16 +335,12 @@
// Strict decoding should throw
bout = new ByteArrayOutputStream();
Base64OutputStream out = new Base64OutputStream(bout, false, 0, null, CodecPolicy.STRICT);
- assertTrue(out.isStrictDecoding());
- try {
- // May throw on write or on close depending on the position of the
- // impossible last character in the output block size
+ // May throw on write or on close depending on the position of the
+ // impossible last character in the output block size
+ assertThrows(IllegalArgumentException.class, () -> {
out.write(impossibleEncoded);
out.close();
- fail();
- } catch (final IllegalArgumentException ex) {
- // expected
- }
+ });
}
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
index c7730e9..f6c9197 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
@@ -17,15 +17,6 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -36,8 +27,10 @@
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.lang3.ArrayUtils;
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Test cases for Base64 class.
@@ -91,11 +84,12 @@
final String validString = "abc===defg\n\r123456\r789\r\rABC\n\nDEF==GHI\r\nJKL==============";
final String invalidString = validString + (char) 0; // append null character
- assertThrows(NullPointerException.class, () -> Base64.isBase64(nullString));
+ assertThrows(NullPointerException.class, () -> Base64.isBase64(nullString),
+ "Base64.isStringBase64() should not be null-safe.");
- assertTrue("Base64.isStringBase64(empty-string) is true", Base64.isBase64(emptyString));
- assertTrue("Base64.isStringBase64(valid-string) is true", Base64.isBase64(validString));
- assertFalse("Base64.isStringBase64(invalid-string) is false", Base64.isBase64(invalidString));
+ assertTrue(Base64.isBase64(emptyString), "Base64.isStringBase64(empty-string) is true");
+ assertTrue(Base64.isBase64(validString), "Base64.isStringBase64(valid-string) is true");
+ assertFalse(Base64.isBase64(invalidString), "Base64.isStringBase64(invalid-string) is false");
}
/**
@@ -107,7 +101,7 @@
String encodedContent;
byte[] encodedBytes = Base64.encodeBase64(StringUtils.getBytesUtf8(content));
encodedContent = StringUtils.newStringUtf8(encodedBytes);
- assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent);
+ assertEquals("SGVsbG8gV29ybGQ=", encodedContent, "encoding hello world");
Base64 b64 = new Base64(BaseNCodec.MIME_CHUNK_SIZE, null); // null
// lineSeparator
@@ -116,18 +110,18 @@
// no-chunking
encodedBytes = b64.encode(StringUtils.getBytesUtf8(content));
encodedContent = StringUtils.newStringUtf8(encodedBytes);
- assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent);
+ assertEquals("SGVsbG8gV29ybGQ=", encodedContent, "encoding hello world");
b64 = new Base64(0, null); // null lineSeparator same as saying
// no-chunking
encodedBytes = b64.encode(StringUtils.getBytesUtf8(content));
encodedContent = StringUtils.newStringUtf8(encodedBytes);
- assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent);
+ assertEquals("SGVsbG8gV29ybGQ=", encodedContent, "encoding hello world");
// bogus characters to decode (to skip actually) {e-acute*6}
final byte[] decode = b64.decode("SGVsbG{\u00e9\u00e9\u00e9\u00e9\u00e9\u00e9}8gV29ybGQ=");
final String decodeString = StringUtils.newStringUtf8(decode);
- assertEquals("decode hello world", "Hello World", decodeString);
+ assertEquals("Hello World", decodeString, "decode hello world");
}
@Test
@@ -153,7 +147,7 @@
buffer = ArrayUtils.addAll(new byte[startPasSize], buffer);
final byte[] encodedBytes = new Base64().encode(buffer, startPasSize, bytesUtf8.length);
encodedContent = StringUtils.newStringUtf8(encodedBytes);
- assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent);
+ assertEquals("SGVsbG8gV29ybGQ=", encodedContent, "encoding hello world");
}
/**
@@ -174,7 +168,7 @@
final String content = "SGVsbG8gV29ybGQ=SGVsbG8gV29ybGQ=";
final byte[] result = Base64.decodeBase64(content);
final byte[] shouldBe = StringUtils.getBytesUtf8("Hello World");
- assertArrayEquals("decode should halt at pad (=)", result, shouldBe);
+ assertArrayEquals(result, shouldBe, "decode should halt at pad (=)");
}
/**
@@ -188,7 +182,7 @@
// in Base64TestData.ENCODED_76_CHARS_PER_LINE:
final String actualResult = Base64TestData.ENCODED_76_CHARS_PER_LINE.replace("\n", "\r\n");
final byte[] actualEncode = StringUtils.getBytesUtf8(actualResult);
- assertArrayEquals("chunkedEncodeMultipleOf76", expectedEncode, actualEncode);
+ assertArrayEquals(expectedEncode, actualEncode, "chunkedEncodeMultipleOf76");
}
/**
@@ -256,7 +250,8 @@
@Test
public void testCodeIntegerNull() {
- assertThrows(NullPointerException.class, () -> Base64.encodeInteger(null));
+ assertThrows(NullPointerException.class, () -> Base64.encodeInteger(null),
+ "Exception not thrown when passing in null to encodeInteger(BigInteger)");
}
@Test
@@ -268,12 +263,23 @@
base64 = new Base64(64, new byte[] {});
base64 = new Base64(64, new byte[] {'$'}); // OK
- assertThrows("'A' as a line separator", IllegalArgumentException.class, () -> new Base64(-1, new byte[] {'A'}));
- assertThrows("'A' as a line separator", IllegalArgumentException.class, () -> new Base64(64, new byte[] {'A'}));
- assertThrows("'=' as a line separator", IllegalArgumentException.class, () -> new Base64(64, new byte[] {'='}));
- assertThrows("'A$' as a line separator", IllegalArgumentException.class, () -> new Base64(64, new byte[] {'A', '$'}));
+ assertThrows(IllegalArgumentException.class, () -> new Base64(-1, new byte[] { 'A' }),
+ "Should have rejected attempt to use 'A' as a line separator");
+ // TODO do we need to check sep if len = -1?
- base64 = new Base64(64, new byte[] {' ', '$', '\n', '\r', '\t'}); // OK
+ assertThrows(IllegalArgumentException.class, () -> new Base64(64, new byte[] { 'A' }),
+ "Should have rejected attempt to use 'A' as a line separator");
+
+ assertThrows(IllegalArgumentException.class, () -> new Base64(64, new byte[] { '=' }),
+ "Should have rejected attempt to use '=' as a line separator");
+
+ base64 = new Base64(64, new byte[] { '$' }); // OK
+
+ assertThrows(IllegalArgumentException.class, () -> new Base64(64, new byte[] { 'A', '$' }),
+ "Should have rejected attempt to use 'A$' as a line separator");
+
+ base64 = new Base64(64, new byte[] { ' ', '$', '\n', '\r', '\t' }); // OK
+
assertNotNull(base64);
}
@@ -284,7 +290,7 @@
String expectedResult = Base64TestData.ENCODED_64_CHARS_PER_LINE;
expectedResult = expectedResult.replace('\n', '\t');
final String result = StringUtils.newStringUtf8(encoded);
- assertEquals("new Base64(65, \\t, false)", expectedResult, result);
+ assertEquals(expectedResult, result, "new Base64(65, \\t, false)");
}
@Test
@@ -299,7 +305,7 @@
expectedResult = expectedResult.replace('+', '-');
expectedResult = expectedResult.replace('/', '_');
final String result = StringUtils.newStringUtf8(encoded);
- assertEquals("new Base64(64, \\t, true)", result, expectedResult);
+ assertEquals(result, expectedResult, "new Base64(64, \\t, true)");
}
/**
@@ -359,7 +365,7 @@
final String dest = new String(decodedWithWS);
- assertEquals("Dest string doesn't equal the original", orig, dest);
+ assertEquals(orig, dest, "Dest string doesn't equal the original");
}
/**
@@ -369,16 +375,16 @@
public void testEmptyBase64() {
byte[] empty = {};
byte[] result = Base64.encodeBase64(empty);
- assertEquals("empty base64 encode", 0, result.length);
- assertNull("empty base64 encode", Base64.encodeBase64(null));
+ assertEquals(0, result.length, "empty base64 encode");
+ assertNull(Base64.encodeBase64(null), "empty base64 encode");
result = new Base64().encode(empty, 0, 1);
- assertEquals("empty base64 encode", 0, result.length);
- assertNull("empty base64 encode", new Base64().encode(null, 0, 1));
+ assertEquals(0, result.length, "empty base64 encode");
+ assertNull(new Base64().encode(null, 0, 1), "empty base64 encode");
empty = new byte[0];
result = Base64.decodeBase64(empty);
- assertEquals("empty base64 decode", 0, result.length);
- assertNull("empty base64 encode", Base64.decodeBase64((byte[]) null));
+ assertEquals(0, result.length, "empty base64 decode");
+ assertNull(Base64.decodeBase64((byte[]) null), "empty base64 encode");
}
// encode/decode a large random array
@@ -401,9 +407,9 @@
final byte[] data = new byte[i];
this.getRandom().nextBytes(data);
final byte[] enc = Base64.encodeBase64(data);
- assertTrue("\"" + new String(enc) + "\" is Base64 data.", Base64.isBase64(enc));
+ assertTrue(Base64.isBase64(enc), "\"" + new String(enc) + "\" is Base64 data.");
final byte[] data2 = Base64.decodeBase64(enc);
- assertArrayEquals(toString(data) + " equals " + toString(data2), data, data2);
+ assertArrayEquals(data, data2, toString(data) + " equals " + toString(data2));
}
}
@@ -420,6 +426,7 @@
final byte[] in = { 0 };
final byte[] out = Base64.encodeBase64(in);
Base64.encodeBase64(in, false, false, out.length);
+ // TODO Assert??
}
private void testEncodeOverMaxSize(final int maxSize) {
@@ -442,10 +449,14 @@
assertFalse(Base64.isBase64(new byte[] { 0 }));
assertFalse(Base64.isBase64(new byte[] { 64, Byte.MAX_VALUE }));
assertFalse(Base64.isBase64(new byte[] { Byte.MAX_VALUE }));
+
assertTrue(Base64.isBase64(new byte[] { 'A' }));
+
assertFalse(Base64.isBase64(new byte[] { 'A', Byte.MIN_VALUE }));
+
assertTrue(Base64.isBase64(new byte[] { 'A', 'Z', 'a' }));
assertTrue(Base64.isBase64(new byte[] { '/', '=', '+' }));
+
assertFalse(Base64.isBase64(new byte[] { '$' }));
}
@@ -457,11 +468,11 @@
final Base64 base64Standard = new Base64(false);
final Base64 base64URLSafe = new Base64(true);
- assertFalse("Base64.isUrlSafe=false", base64Standard.isUrlSafe());
- assertTrue("Base64.isUrlSafe=true", base64URLSafe.isUrlSafe());
+ assertFalse(base64Standard.isUrlSafe(), "Base64.isUrlSafe=false");
+ assertTrue(base64URLSafe.isUrlSafe(), "Base64.isUrlSafe=true");
final byte[] whiteSpace = { ' ', '\n', '\r', '\t' };
- assertTrue("Base64.isBase64(whiteSpace)=true", Base64.isBase64(whiteSpace));
+ assertTrue(Base64.isBase64(whiteSpace), "Base64.isBase64(whiteSpace)=true");
}
@Test
@@ -504,25 +515,26 @@
final byte[] bArray = { '%' };
- assertFalse("Invalid Base64 array was incorrectly validated as " + "an array of Base64 encoded data",
- Base64.isBase64(bArray));
+ assertFalse(Base64.isBase64(bArray),
+ "Invalid Base64 array was incorrectly validated as an array of Base64 encoded data");
try {
final Base64 b64 = new Base64();
- final byte[] result = b64.decode(bArray);
+ byte[] result = b64.decode(bArray);
- assertEquals("The result should be empty as the test encoded content did " +
- "not contain any valid base 64 characters", 0, result.length);
+ assertEquals(0, result.length, "The result should be empty as the test encoded content did " +
+ "not contain any valid base 64 characters");
} catch (final Exception e) {
- fail("Exception was thrown when trying to decode " +
+ fail("Exception '" + e.getClass().getName() + "' was thrown when trying to decode " +
"invalid base64 encoded data - RFC 2045 requires that all " +
- "non base64 character be discarded, an exception should not" + " have been thrown");
+ "non base64 character be discarded, an exception should not have been thrown");
}
}
@Test
public void testObjectDecodeWithInvalidParameter() {
- assertThrows(DecoderException.class, () -> new Base64().decode(Integer.valueOf(5)));
+ assertThrows(DecoderException.class, () -> new Base64().decode(Integer.valueOf(5)),
+ "decode(Object) didn't throw an exception when passed an Integer object");
}
@Test
@@ -536,12 +548,13 @@
final byte[] baDecoded = (byte[]) oDecoded;
final String dest = new String(baDecoded);
- assertEquals("dest string does not equal original", original, dest);
+ assertEquals(original, dest, "dest string does not equal original");
}
@Test
public void testObjectEncodeWithInvalidParameter() {
- assertThrows(EncoderException.class, () -> new Base64().encode("Yadayadayada"));
+ assertThrows(EncoderException.class, () -> new Base64().encode("Yadayadayada"),
+ "encode(Object) didn't throw an exception when passed a String object");
}
@Test
@@ -555,7 +568,7 @@
final byte[] bArray = Base64.decodeBase64((byte[]) oEncoded);
final String dest = new String(bArray);
- assertEquals("dest string does not equal original", original, dest);
+ assertEquals(original, dest, "dest string does not equal original");
}
@Test
@@ -1110,10 +1123,10 @@
final byte[] encoded = randomData[1];
final byte[] decoded = randomData[0];
final byte[] result = Base64.decodeBase64(encoded);
- assertArrayEquals("url-safe i=" + i, decoded, result);
- assertFalse("url-safe i=" + i + " no '='", BaseNTestData.bytesContain(encoded, (byte) '='));
- assertFalse("url-safe i=" + i + " no '\\'", BaseNTestData.bytesContain(encoded, (byte) '\\'));
- assertFalse("url-safe i=" + i + " no '+'", BaseNTestData.bytesContain(encoded, (byte) '+'));
+ assertArrayEquals(decoded, result, "url-safe i=" + i);
+ assertFalse(BaseNTestData.bytesContain(encoded, (byte) '='), "url-safe i=" + i + " no '='");
+ assertFalse(BaseNTestData.bytesContain(encoded, (byte) '\\'), "url-safe i=" + i + " no '\\'");
+ assertFalse(BaseNTestData.bytesContain(encoded, (byte) '+'), "url-safe i=" + i + " no '+'");
}
}
@@ -1194,12 +1207,12 @@
// + StringUtils.newStringUtf8(urlSafe3[i]) + "]");
// }
- assertArrayEquals("standard encode uuid", encodedStandard, standard[i]);
- assertArrayEquals("url-safe encode uuid", encodedUrlSafe, urlSafe3[i]);
- assertArrayEquals("standard decode uuid", decodedStandard, ids[i]);
- assertArrayEquals("url-safe1 decode uuid", decodedUrlSafe1, ids[i]);
- assertArrayEquals("url-safe2 decode uuid", decodedUrlSafe2, ids[i]);
- assertArrayEquals("url-safe3 decode uuid", decodedUrlSafe3, ids[i]);
+ assertArrayEquals(encodedStandard, standard[i], "standard encode uuid");
+ assertArrayEquals(encodedUrlSafe, urlSafe3[i], "url-safe encode uuid");
+ assertArrayEquals(decodedStandard, ids[i], "standard decode uuid");
+ assertArrayEquals(decodedUrlSafe1, ids[i], "url-safe1 decode uuid");
+ assertArrayEquals(decodedUrlSafe2, ids[i], "url-safe2 decode uuid");
+ assertArrayEquals(decodedUrlSafe3, ids[i], "url-safe3 decode uuid");
}
}
@@ -1213,16 +1226,24 @@
// url-safe
// tests
- assertEquals("byteToString Hello World", "SGVsbG8gV29ybGQ=", base64.encodeToString(b1));
- assertEquals("byteToString static Hello World", "SGVsbG8gV29ybGQ=", Base64.encodeBase64String(b1));
- assertEquals("byteToString \"\"", "", base64.encodeToString(b2));
- assertEquals("byteToString static \"\"", "", Base64.encodeBase64String(b2));
- assertNull("byteToString null", base64.encodeToString(b3));
- assertNull("byteToString static null", Base64.encodeBase64String(b3));
- assertEquals("byteToString UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", base64.encodeToString(b4));
- assertEquals("byteToString static UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", Base64.encodeBase64String(b4));
- assertEquals("byteToString static-url-safe UUID", "K_fMJwH-Q5e0nr7tWsxwkA",
- Base64.encodeBase64URLSafeString(b4));
+ assertEquals("SGVsbG8gV29ybGQ=", base64.encodeToString(b1),
+ "byteToString Hello World");
+ assertEquals( "SGVsbG8gV29ybGQ=", Base64.encodeBase64String(b1),
+ "byteToString static Hello World");
+ assertEquals("", base64.encodeToString(b2),
+ "byteToString \"\"");
+ assertEquals("", Base64.encodeBase64String(b2),
+ "byteToString static \"\"");
+ assertNull(base64.encodeToString(b3),
+ "byteToString null");
+ assertNull(Base64.encodeBase64String(b3),
+ "byteToString static null");
+ assertEquals("K/fMJwH+Q5e0nr7tWsxwkA==", base64.encodeToString(b4),
+ "byteToString UUID");
+ assertEquals("K/fMJwH+Q5e0nr7tWsxwkA==", Base64.encodeBase64String(b4),
+ "byteToString static UUID");
+ assertEquals("K_fMJwH-Q5e0nr7tWsxwkA", Base64.encodeBase64URLSafeString(b4),
+ "byteToString static-url-safe UUID");
}
@Test
@@ -1237,18 +1258,16 @@
// url-safe
// tests
- assertEquals("StringToByte Hello World", "Hello World", StringUtils.newStringUtf8(base64.decode(s1)));
- assertEquals("StringToByte Hello World", "Hello World",
- StringUtils.newStringUtf8((byte[]) base64.decode((Object) s1)));
- assertEquals("StringToByte static Hello World", "Hello World",
- StringUtils.newStringUtf8(Base64.decodeBase64(s1)));
- assertEquals("StringToByte \"\"", "", StringUtils.newStringUtf8(base64.decode(s2)));
- assertEquals("StringToByte static \"\"", "", StringUtils.newStringUtf8(Base64.decodeBase64(s2)));
- assertNull("StringToByte null", StringUtils.newStringUtf8(base64.decode(s3)));
- assertNull("StringToByte static null", StringUtils.newStringUtf8(Base64.decodeBase64(s3)));
- assertArrayEquals("StringToByte UUID", b4, base64.decode(s4b));
- assertArrayEquals("StringToByte static UUID", b4, Base64.decodeBase64(s4a));
- assertArrayEquals("StringToByte static-url-safe UUID", b4, Base64.decodeBase64(s4b));
+ assertEquals("Hello World", StringUtils.newStringUtf8(base64.decode(s1)), "StringToByte Hello World");
+ assertEquals("Hello World", StringUtils.newStringUtf8((byte[]) base64.decode((Object) s1)), "StringToByte Hello World");
+ assertEquals("Hello World", StringUtils.newStringUtf8(Base64.decodeBase64(s1)), "StringToByte static Hello World");
+ assertEquals("", StringUtils.newStringUtf8(base64.decode(s2)), "StringToByte \"\"");
+ assertEquals("", StringUtils.newStringUtf8(Base64.decodeBase64(s2)), "StringToByte static \"\"");
+ assertNull(StringUtils.newStringUtf8(base64.decode(s3)), "StringToByte null");
+ assertNull(StringUtils.newStringUtf8(Base64.decodeBase64(s3)), "StringToByte static null");
+ assertArrayEquals(b4, base64.decode(s4b), "StringToByte UUID");
+ assertArrayEquals(b4, Base64.decodeBase64(s4a), "StringToByte static UUID");
+ assertArrayEquals(b4, Base64.decodeBase64(s4b), "StringToByte static-url-safe UUID");
}
private String toString(final byte[] data) {
@@ -1275,7 +1294,7 @@
final Base64 b64 = new Base64(Base64_BYTES_PER_ENCODED_BLOCK, baLineSeparator);
final String strOriginal = "Hello World";
final String strDecoded = new String(b64.decode(b64.encode(StringUtils.getBytesUtf8(strOriginal))));
- assertEquals("testDEFAULT_BUFFER_SIZE", strOriginal, strDecoded);
+ assertEquals(strOriginal, strDecoded, "testDEFAULT_BUFFER_SIZE");
}
@Test
@@ -1337,7 +1356,8 @@
// If the lower bits are set we expect an exception. This is not a valid
// final character.
if (invalid || (i & emptyBitsMask) != 0) {
- assertThrows(IllegalArgumentException.class, () -> codec.decode(encoded));
+ assertThrows(IllegalArgumentException.class, () -> codec.decode(encoded),
+ "Final base-64 digit should not be allowed");
// The default lenient mode should decode this
final byte[] decoded = defaultCodec.decode(encoded);
// Re-encoding should not match the original array as it was invalid
@@ -1347,7 +1367,7 @@
final byte[] decoded = codec.decode(encoded);
// Compute the bits that were encoded. This should match the final decoded byte.
final int bitsEncoded = i >> discard;
- assertEquals("Invalid decoding of last character", bitsEncoded, decoded[decoded.length - 1]);
+ assertEquals(bitsEncoded, decoded[decoded.length - 1], "Invalid decoding of last character");
// Re-encoding should match the original array (requires the same padding character)
assertArrayEquals(encoded, codec.encode(decoded));
}
@@ -1381,7 +1401,8 @@
// ~1.33GiB: Expected output size (since the working buffer is copied at the end)
// 32KiB: Some head room
final long estimatedMemory = (long) size1GiB * 4 + expectedLength + 32 * 1024;
- Assume.assumeTrue("Not enough free memory for the test", presumableFreeMemory > estimatedMemory);
+ Assumptions.assumeTrue(presumableFreeMemory > estimatedMemory,
+ "Not enough free memory for the test");
final byte[] bytes = new byte[size1GiB];
final byte[] encoded = Base64.encodeBase64(bytes);
diff --git a/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java b/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java
index f17feed..9b29b7b 100644
--- a/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java
@@ -17,23 +17,18 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
import org.apache.commons.codec.binary.BaseNCodec.Context;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class BaseNCodecTest {
BaseNCodec codec;
- @Before
+ @BeforeEach
public void setUp() {
codec = new BaseNCodec(0, 0, 0, 0) {
@Override
@@ -68,14 +63,14 @@
context.pos = 42;
context.readPos = 981;
final String text = context.toString();
- Assert.assertTrue(text.contains("[0, 0, 0]"));
- Assert.assertTrue(text.contains("13"));
- Assert.assertTrue(text.contains("true"));
- Assert.assertTrue(text.contains("777"));
- Assert.assertTrue(text.contains("999"));
- Assert.assertTrue(text.contains("5"));
- Assert.assertTrue(text.contains("42"));
- Assert.assertTrue(text.contains("981"));
+ assertTrue(text.contains("[0, 0, 0]"));
+ assertTrue(text.contains("13"));
+ assertTrue(text.contains("true"));
+ assertTrue(text.contains("777"));
+ assertTrue(text.contains("999"));
+ assertTrue(text.contains("5"));
+ assertTrue(text.contains("42"));
+ assertTrue(text.contains("981"));
}
@Test
@@ -226,27 +221,27 @@
public void testEnsureBufferSize() {
final BaseNCodec ncodec = new NoOpBaseNCodec();
final Context context = new Context();
- Assert.assertNull("Initial buffer should be null", context.buffer);
+ assertNull(context.buffer, "Initial buffer should be null");
// Test initialization
context.pos = 76979;
context.readPos = 273;
ncodec.ensureBufferSize(0, context);
- Assert.assertNotNull("buffer should be initialized", context.buffer);
- Assert.assertEquals("buffer should be initialized to default size", ncodec.getDefaultBufferSize(), context.buffer.length);
- Assert.assertEquals("context position", 0, context.pos);
- Assert.assertEquals("context read position", 0, context.readPos);
+ assertNotNull(context.buffer, "buffer should be initialized");
+ assertEquals(ncodec.getDefaultBufferSize(), context.buffer.length, "buffer should be initialized to default size");
+ assertEquals(0, context.pos, "context position");
+ assertEquals(0, context.readPos, "context read position");
// Test when no expansion is required
ncodec.ensureBufferSize(1, context);
- Assert.assertEquals("buffer should not expand unless required", ncodec.getDefaultBufferSize(), context.buffer.length);
+ assertEquals(ncodec.getDefaultBufferSize(), context.buffer.length, "buffer should not expand unless required");
// Test expansion
int length = context.buffer.length;
context.pos = length;
int extra = 1;
ncodec.ensureBufferSize(extra, context);
- Assert.assertTrue("buffer should expand", context.buffer.length >= length + extra);
+ assertTrue(context.buffer.length >= length + extra, "buffer should expand");
// Test expansion beyond double the buffer size.
// Hits the edge case where the required capacity is more than the default expansion.
@@ -254,7 +249,7 @@
context.pos = length;
extra = length * 10;
ncodec.ensureBufferSize(extra, context);
- Assert.assertTrue("buffer should expand beyond double capacity", context.buffer.length >= length + extra);
+ assertTrue(context.buffer.length >= length + extra, "buffer should expand beyond double capacity");
}
/**
@@ -294,7 +289,7 @@
// 32KiB: Some head room
// length: Existing buffer
final long estimatedMemory = (1L << 31) + 32 * 1024 + length;
- Assume.assumeTrue("Not enough free memory for the test", presumableFreeMemory > estimatedMemory);
+ assumeTrue(presumableFreeMemory > estimatedMemory, "Not enough free memory for the test");
final int max = Integer.MAX_VALUE - 8;
@@ -319,7 +314,7 @@
extra++;
}
ncodec.ensureBufferSize(extra, context);
- Assert.assertTrue(context.buffer.length >= length + extra);
+ assertTrue(context.buffer.length >= length + extra);
}
/**
@@ -332,7 +327,7 @@
} catch (final OutOfMemoryError ignore) {
// ignore
}
- Assume.assumeTrue("Cannot allocate array of size: " + size, bytes != null);
+ assumeTrue(bytes != null, "Cannot allocate array of size: " + size);
}
/**
diff --git a/src/test/java/org/apache/commons/codec/binary/BinaryCodecTest.java b/src/test/java/org/apache/commons/codec/binary/BinaryCodecTest.java
index 2e3e638..dea5efb 100644
--- a/src/test/java/org/apache/commons/codec/binary/BinaryCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/BinaryCodecTest.java
@@ -17,17 +17,17 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* TestCase for BinaryCodec class.
@@ -64,12 +64,12 @@
/** An instance of the binary codec. */
BinaryCodec instance = null;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
this.instance = new BinaryCodec();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
this.instance = null;
}
diff --git a/src/test/java/org/apache/commons/codec/binary/CharSequenceUtilsTest.java b/src/test/java/org/apache/commons/codec/binary/CharSequenceUtilsTest.java
index 0b7518a..a53f987 100644
--- a/src/test/java/org/apache/commons/codec/binary/CharSequenceUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/CharSequenceUtilsTest.java
@@ -17,11 +17,9 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link org.apache.commons.codec.binary.CharSequenceUtils}.
@@ -109,14 +107,14 @@
final String msg = id + " Expected " + data.throwable;
try {
invoke();
- Assert.fail(msg + " but nothing was thrown.");
+ fail(msg + " but nothing was thrown.");
} catch (final Exception ex) {
- assertTrue(msg + " but was " + ex.getClass().getSimpleName(),
- data.throwable.isAssignableFrom(ex.getClass()));
+ assertTrue(data.throwable.isAssignableFrom(ex.getClass()),
+ msg + " but was " + ex.getClass().getSimpleName());
}
} else {
final boolean stringCheck = invoke();
- assertEquals(id + " Failed test " + data, data.expected, stringCheck);
+ assertEquals(data.expected, stringCheck, id + " Failed test " + data);
}
}
diff --git a/src/test/java/org/apache/commons/codec/binary/HexTest.java b/src/test/java/org/apache/commons/codec/binary/HexTest.java
index 0aa78d2..19104cf 100644
--- a/src/test/java/org/apache/commons/codec/binary/HexTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/HexTest.java
@@ -17,12 +17,6 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -32,8 +26,9 @@
import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link org.apache.commons.codec.binary.Hex}.
@@ -177,19 +172,18 @@
assertArrayEquals(expectedHexStringBytes, actualEncodedBytes);
// test 2
String actualStringFromBytes = new String(actualEncodedBytes, name);
- assertEquals(name + ", expectedHexString=" + expectedHexString + ", actualStringFromBytes=" +
- actualStringFromBytes, expectedHexString, actualStringFromBytes);
+ assertEquals(expectedHexString, actualStringFromBytes, name);
// second test:
final Hex utf8Codec = new Hex();
expectedHexString = "48656c6c6f20576f726c64";
final byte[] decodedUtf8Bytes = (byte[]) utf8Codec.decode(expectedHexString);
actualStringFromBytes = new String(decodedUtf8Bytes, utf8Codec.getCharset());
// sanity check:
- assertEquals(name, sourceString, actualStringFromBytes);
+ assertEquals(sourceString, actualStringFromBytes, name);
// actual check:
final byte[] decodedCustomBytes = customCodec.decode(actualEncodedBytes);
actualStringFromBytes = new String(decodedCustomBytes, name);
- assertEquals(name, sourceString, actualStringFromBytes);
+ assertEquals(sourceString, actualStringFromBytes, name);
}
@Test
@@ -224,7 +218,7 @@
@Test
public void testDecodeByteArrayOddCharacters() {
- assertThrows("odd number of characters", DecoderException.class, () -> new Hex().decode(new byte[] { 65 }));
+ assertThrows(DecoderException.class, () -> new Hex().decode(new byte[] { 65 }), "odd number of characters");
}
@Test
@@ -275,7 +269,7 @@
@Test
public void testDecodeClassCastException() {
- assertThrows("odd number of characters", DecoderException.class, () -> new Hex().decode(new int[] { 65 }));
+ assertThrows(DecoderException.class, () -> new Hex().decode(new int[] { 65 }), "odd number of characters");
}
@Test
@@ -308,11 +302,12 @@
public void testDecodeHexCharArrayOutBufferUnderSizedByOffset() {
final byte[] out = new byte[6];
assertThrows(DecoderException.class, () -> Hex.decodeHex("aabbccddeeff".toCharArray(), out, 1));
+
}
@Test
public void testDecodeHexStringOddCharacters() {
- assertThrows("odd number of characters", DecoderException.class, () -> new Hex().decode("6"));
+ assertThrows(DecoderException.class, () -> new Hex().decode("6"), "odd number of characters");
}
@@ -656,12 +651,12 @@
@Test
public void testGetCharset() {
- Assert.assertEquals(StandardCharsets.UTF_8, new Hex(StandardCharsets.UTF_8).getCharset());
+ assertEquals(StandardCharsets.UTF_8, new Hex(StandardCharsets.UTF_8).getCharset());
}
@Test
public void testGetCharsetName() {
- Assert.assertEquals(StandardCharsets.UTF_8.name(), new Hex(StandardCharsets.UTF_8).getCharsetName());
+ assertEquals(StandardCharsets.UTF_8.name(), new Hex(StandardCharsets.UTF_8).getCharsetName());
}
@Test
diff --git a/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java b/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
index 9286398..84f9365 100644
--- a/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
@@ -17,14 +17,13 @@
package org.apache.commons.codec.binary;
-import static org.junit.Assert.assertThrows;
+import org.junit.jupiter.api.Test;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link StringUtils}
@@ -57,13 +56,13 @@
testGetBytesUnchecked(charsetName);
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesIso8859_1(STRING_FIXTURE);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
private void testGetBytesUnchecked(final String charsetName) throws UnsupportedEncodingException {
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesUnchecked(STRING_FIXTURE, charsetName);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
@Test
@@ -72,7 +71,7 @@
testGetBytesUnchecked(charsetName);
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesUsAscii(STRING_FIXTURE);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
@Test
@@ -81,7 +80,7 @@
testGetBytesUnchecked(charsetName);
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesUtf16(STRING_FIXTURE);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
@Test
@@ -90,7 +89,7 @@
testGetBytesUnchecked(charsetName);
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesUtf16Be(STRING_FIXTURE);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
@Test
@@ -99,7 +98,7 @@
testGetBytesUnchecked(charsetName);
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesUtf16Le(STRING_FIXTURE);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
@Test
@@ -108,7 +107,7 @@
testGetBytesUnchecked(charsetName);
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
final byte[] actual = StringUtils.getBytesUtf8(STRING_FIXTURE);
- Assert.assertArrayEquals(expected, actual);
+ assertArrayEquals(expected, actual);
}
@Test
@@ -118,13 +117,13 @@
@Test
public void testGetBytesUncheckedNullInput() {
- Assert.assertNull(StringUtils.getBytesUnchecked(null, "UNKNOWN"));
+ assertNull(StringUtils.getBytesUnchecked(null, "UNKNOWN"));
}
private void testNewString(final String charsetName) throws UnsupportedEncodingException {
final String expected = new String(BYTES_FIXTURE, charsetName);
final String actual = StringUtils.newString(BYTES_FIXTURE, charsetName);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -134,17 +133,17 @@
@Test
public void testNewStringNullInput() {
- Assert.assertNull(StringUtils.newString(null, "UNKNOWN"));
+ assertNull(StringUtils.newString(null, "UNKNOWN"));
}
@Test
public void testNewStringNullInput_CODEC229() {
- Assert.assertNull(StringUtils.newStringUtf8(null));
- Assert.assertNull(StringUtils.newStringIso8859_1(null));
- Assert.assertNull(StringUtils.newStringUsAscii(null));
- Assert.assertNull(StringUtils.newStringUtf16(null));
- Assert.assertNull(StringUtils.newStringUtf16Be(null));
- Assert.assertNull(StringUtils.newStringUtf16Le(null));
+ assertNull(StringUtils.newStringUtf8(null));
+ assertNull(StringUtils.newStringIso8859_1(null));
+ assertNull(StringUtils.newStringUsAscii(null));
+ assertNull(StringUtils.newStringUtf16(null));
+ assertNull(StringUtils.newStringUtf16Be(null));
+ assertNull(StringUtils.newStringUtf16Le(null));
}
@Test
@@ -153,7 +152,7 @@
testNewString(charsetName);
final String expected = new String(BYTES_FIXTURE, charsetName);
final String actual = StringUtils.newStringIso8859_1(BYTES_FIXTURE);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -162,7 +161,7 @@
testNewString(charsetName);
final String expected = new String(BYTES_FIXTURE, charsetName);
final String actual = StringUtils.newStringUsAscii(BYTES_FIXTURE);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -171,7 +170,7 @@
testNewString(charsetName);
final String expected = new String(BYTES_FIXTURE, charsetName);
final String actual = StringUtils.newStringUtf16(BYTES_FIXTURE);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -180,7 +179,7 @@
testNewString(charsetName);
final String expected = new String(BYTES_FIXTURE_16BE, charsetName);
final String actual = StringUtils.newStringUtf16Be(BYTES_FIXTURE_16BE);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -189,7 +188,7 @@
testNewString(charsetName);
final String expected = new String(BYTES_FIXTURE_16LE, charsetName);
final String actual = StringUtils.newStringUtf16Le(BYTES_FIXTURE_16LE);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -198,43 +197,43 @@
testNewString(charsetName);
final String expected = new String(BYTES_FIXTURE, charsetName);
final String actual = StringUtils.newStringUtf8(BYTES_FIXTURE);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
public void testEqualsString() {
- Assert.assertTrue(StringUtils.equals(null, null));
- Assert.assertFalse(StringUtils.equals("abc", null));
- Assert.assertFalse(StringUtils.equals(null, "abc"));
- Assert.assertTrue(StringUtils.equals("abc", "abc"));
- Assert.assertFalse(StringUtils.equals("abc", "abcd"));
- Assert.assertFalse(StringUtils.equals("abcd", "abc"));
- Assert.assertFalse(StringUtils.equals("abc", "ABC"));
+ assertTrue(StringUtils.equals(null, null));
+ assertFalse(StringUtils.equals("abc", null));
+ assertFalse(StringUtils.equals(null, "abc"));
+ assertTrue(StringUtils.equals("abc", "abc"));
+ assertFalse(StringUtils.equals("abc", "abcd"));
+ assertFalse(StringUtils.equals("abcd", "abc"));
+ assertFalse(StringUtils.equals("abc", "ABC"));
}
@Test
public void testEqualsCS1() {
- Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), null));
- Assert.assertFalse(StringUtils.equals(null, new StringBuilder("abc")));
- Assert.assertTrue(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("abc")));
- Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("abcd")));
- Assert.assertFalse(StringUtils.equals(new StringBuilder("abcd"), new StringBuilder("abc")));
- Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("ABC")));
+ assertFalse(StringUtils.equals(new StringBuilder("abc"), null));
+ assertFalse(StringUtils.equals(null, new StringBuilder("abc")));
+ assertTrue(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("abc")));
+ assertFalse(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("abcd")));
+ assertFalse(StringUtils.equals(new StringBuilder("abcd"), new StringBuilder("abc")));
+ assertFalse(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("ABC")));
}
@Test
public void testEqualsCS2() {
- Assert.assertTrue(StringUtils.equals("abc", new StringBuilder("abc")));
- Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), "abcd"));
- Assert.assertFalse(StringUtils.equals("abcd", new StringBuilder("abc")));
- Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), "ABC"));
+ assertTrue(StringUtils.equals("abc", new StringBuilder("abc")));
+ assertFalse(StringUtils.equals(new StringBuilder("abc"), "abcd"));
+ assertFalse(StringUtils.equals("abcd", new StringBuilder("abc")));
+ assertFalse(StringUtils.equals(new StringBuilder("abc"), "ABC"));
}
@Test
public void testByteBufferUtf8() {
- Assert.assertNull("Should be null safe", StringUtils.getByteBufferUtf8(null));
+ assertNull(StringUtils.getByteBufferUtf8(null), "Should be null safe");
final String text = "asdhjfhsadiogasdjhagsdygfjasfgsdaksjdhfk";
final ByteBuffer bb = StringUtils.getByteBufferUtf8(text);
- Assert.assertArrayEquals(text.getBytes(StandardCharsets.UTF_8), bb.array());
+ assertArrayEquals(text.getBytes(StandardCharsets.UTF_8), bb.array());
}
}
diff --git a/src/test/java/org/apache/commons/codec/cli/DigestTest.java b/src/test/java/org/apache/commons/codec/cli/DigestTest.java
index 6b7ccc2..2d4d8ab 100644
--- a/src/test/java/org/apache/commons/codec/cli/DigestTest.java
+++ b/src/test/java/org/apache/commons/codec/cli/DigestTest.java
@@ -17,7 +17,7 @@
package org.apache.commons.codec.cli;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
diff --git a/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java
index 55ae16a..9af12d6 100644
--- a/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java
@@ -16,16 +16,13 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ThreadLocalRandom;
+import static org.junit.jupiter.api.Assertions.*;
+
public class Apr1CryptTest {
@Test
diff --git a/src/test/java/org/apache/commons/codec/digest/B64Test.java b/src/test/java/org/apache/commons/codec/digest/B64Test.java
index 0d01a04..0ac694e 100644
--- a/src/test/java/org/apache/commons/codec/digest/B64Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/B64Test.java
@@ -16,10 +16,10 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class B64Test {
diff --git a/src/test/java/org/apache/commons/codec/digest/Blake3Test.java b/src/test/java/org/apache/commons/codec/digest/Blake3Test.java
index ce3ec92..40832c8 100644
--- a/src/test/java/org/apache/commons/codec/digest/Blake3Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/Blake3Test.java
@@ -16,9 +16,9 @@
*/
package org.apache.commons.codec.digest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.*;
public class Blake3Test {
@Test
@@ -30,6 +30,6 @@
}
private static void assertThrowsProperExceptionWithKeySize(final int keySize) {
- assertThrows("Blake3 keys must be 32 bytes", IllegalArgumentException.class, () -> Blake3.initKeyedHash(new byte[keySize]));
+ assertThrows(IllegalArgumentException.class, () -> Blake3.initKeyedHash(new byte[keySize]), "Blake3 keys must be 32 bytes");
}
}
diff --git a/src/test/java/org/apache/commons/codec/digest/Blake3TestVectorsTest.java b/src/test/java/org/apache/commons/codec/digest/Blake3TestVectorsTest.java
index 609547c..289a576 100644
--- a/src/test/java/org/apache/commons/codec/digest/Blake3TestVectorsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Blake3TestVectorsTest.java
@@ -18,14 +18,15 @@
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import java.util.stream.Stream;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
/**
* Tests the standard test vectors provided by the reference Blake3 implementation. Each test uses as input data the
@@ -36,282 +37,290 @@
* For each of these hashes, both the extended hash output and the truncated 32-byte hash outputs are validated against
* these known answer tests (KATs).
*/
-@RunWith(Parameterized.class)
public class Blake3TestVectorsTest {
private static final byte[] KEY = "whats the Elvish word for friend".getBytes(StandardCharsets.UTF_8);
private static final byte[] CTX =
"BLAKE3 2019-12-27 16:29:52 test vectors context".getBytes(StandardCharsets.UTF_8);
- @Parameterized.Parameters
- public static Object[][] testCases() {
- return new Object[][] {
- {
+ public static Stream<Arguments> data() {
+ return Stream.of(
+ Arguments.of(
0,
"af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262e00f03e7b69af26b7faaf09fcd333050338ddfe085b8cc869ca98b206c08243a26f5487789e8f660afe6c99ef9e0c52b92e7393024a80459cf91f476f9ffdbda7001c22e159b402631f277ca96f2defdf1078282314e763699a31c5363165421cce14d",
"92b2b75604ed3c761f9d6f62392c8a9227ad0ea3f09573e783f1498a4ed60d26b18171a2f22a4b94822c701f107153dba24918c4bae4d2945c20ece13387627d3b73cbf97b797d5e59948c7ef788f54372df45e45e4293c7dc18c1d41144a9758be58960856be1eabbe22c2653190de560ca3b2ac4aa692a9210694254c371e851bc8f",
"2cc39783c223154fea8dfb7c1b1660f2ac2dcbd1c1de8277b0b0dd39b7e50d7d905630c8be290dfcf3e6842f13bddd573c098c3f17361f1f206b8cad9d088aa4a3f746752c6b0ce6a83b0da81d59649257cdf8eb3e9f7d4998e41021fac119deefb896224ac99f860011f73609e6e0e4540f93b273e56547dfd3aa1a035ba6689d89a0"
- },
- {
+ ),
+ Arguments.of(
1,
"2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213c3a6cb8bf623e20cdb535f8d1a5ffb86342d9c0b64aca3bce1d31f60adfa137b358ad4d79f97b47c3d5e79f179df87a3b9776ef8325f8329886ba42f07fb138bb502f4081cbcec3195c5871e6c23e2cc97d3c69a613eba131e5f1351f3f1da786545e5",
"6d7878dfff2f485635d39013278ae14f1454b8c0a3a2d34bc1ab38228a80c95b6568c0490609413006fbd428eb3fd14e7756d90f73a4725fad147f7bf70fd61c4e0cf7074885e92b0e3f125978b4154986d4fb202a3f331a3fb6cf349a3a70e49990f98fe4289761c8602c4e6ab1138d31d3b62218078b2f3ba9a88e1d08d0dd4cea11",
"b3e2e340a117a499c6cf2398a19ee0d29cca2bb7404c73063382693bf66cb06c5827b91bf889b6b97c5477f535361caefca0b5d8c4746441c57617111933158950670f9aa8a05d791daae10ac683cbef8faf897c84e6114a59d2173c3f417023a35d6983f2c7dfa57e7fc559ad751dbfb9ffab39c2ef8c4aafebc9ae973a64f0c76551"
- },
- {
+ ),
+ Arguments.of(
2,
"7b7015bb92cf0b318037702a6cdd81dee41224f734684c2c122cd6359cb1ee63d8386b22e2ddc05836b7c1bb693d92af006deb5ffbc4c70fb44d0195d0c6f252faac61659ef86523aa16517f87cb5f1340e723756ab65efb2f91964e14391de2a432263a6faf1d146937b35a33621c12d00be8223a7f1919cec0acd12097ff3ab00ab1",
"5392ddae0e0a69d5f40160462cbd9bd889375082ff224ac9c758802b7a6fd20a9ffbf7efd13e989a6c246f96d3a96b9d279f2c4e63fb0bdff633957acf50ee1a5f658be144bab0f6f16500dee4aa5967fc2c586d85a04caddec90fffb7633f46a60786024353b9e5cebe277fcd9514217fee2267dcda8f7b31697b7c54fab6a939bf8f",
"1f166565a7df0098ee65922d7fea425fb18b9943f19d6161e2d17939356168e6daa59cae19892b2d54f6fc9f475d26031fd1c22ae0a3e8ef7bdb23f452a15e0027629d2e867b1bb1e6ab21c71297377750826c404dfccc2406bd57a83775f89e0b075e59a7732326715ef912078e213944f490ad68037557518b79c0086de6d6f6cdd2"
- },
- {
+ ),
+ Arguments.of(
3,
"e1be4d7a8ab5560aa4199eea339849ba8e293d55ca0a81006726d184519e647f5b49b82f805a538c68915c1ae8035c900fd1d4b13902920fd05e1450822f36de9454b7e9996de4900c8e723512883f93f4345f8a58bfe64ee38d3ad71ab027765d25cdd0e448328a8e7a683b9a6af8b0af94fa09010d9186890b096a08471e4230a134",
"39e67b76b5a007d4921969779fe666da67b5213b096084ab674742f0d5ec62b9b9142d0fab08e1b161efdbb28d18afc64d8f72160c958e53a950cdecf91c1a1bbab1a9c0f01def762a77e2e8545d4dec241e98a89b6db2e9a5b070fc110caae2622690bd7b76c02ab60750a3ea75426a6bb8803c370ffe465f07fb57def95df772c39f",
"440aba35cb006b61fc17c0529255de438efc06a8c9ebf3f2ddac3b5a86705797f27e2e914574f4d87ec04c379e12789eccbfbc15892626042707802dbe4e97c3ff59dca80c1e54246b6d055154f7348a39b7d098b2b4824ebe90e104e763b2a447512132cede16243484a55a4e40a85790038bb0dcf762e8c053cabae41bbe22a5bff7"
- },
- {
+ ),
+ Arguments.of(
4,
"f30f5ab28fe047904037f77b6da4fea1e27241c5d132638d8bedce9d40494f328f603ba4564453e06cdcee6cbe728a4519bbe6f0d41e8a14b5b225174a566dbfa61b56afb1e452dc08c804f8c3143c9e2cc4a31bb738bf8c1917b55830c6e65797211701dc0b98daa1faeaa6ee9e56ab606ce03a1a881e8f14e87a4acf4646272cfd12",
"7671dde590c95d5ac9616651ff5aa0a27bee5913a348e053b8aa9108917fe070116c0acff3f0d1fa97ab38d813fd46506089118147d83393019b068a55d646251ecf81105f798d76a10ae413f3d925787d6216a7eb444e510fd56916f1d753a5544ecf0072134a146b2615b42f50c179f56b8fae0788008e3e27c67482349e249cb86a",
"f46085c8190d69022369ce1a18880e9b369c135eb93f3c63550d3e7630e91060fbd7d8f4258bec9da4e05044f88b91944f7cab317a2f0c18279629a3867fad0662c9ad4d42c6f27e5b124da17c8c4f3a94a025ba5d1b623686c6099d202a7317a82e3d95dae46a87de0555d727a5df55de44dab799a20dffe239594d6e99ed17950910"
- },
- {
+ ),
+ Arguments.of(
5,
"b40b44dfd97e7a84a996a91af8b85188c66c126940ba7aad2e7ae6b385402aa2ebcfdac6c5d32c31209e1f81a454751280db64942ce395104e1e4eaca62607de1c2ca748251754ea5bbe8c20150e7f47efd57012c63b3c6a6632dc1c7cd15f3e1c999904037d60fac2eb9397f2adbe458d7f264e64f1e73aa927b30988e2aed2f03620",
"73ac69eecf286894d8102018a6fc729f4b1f4247d3703f69bdc6a5fe3e0c84616ab199d1f2f3e53bffb17f0a2209fe8b4f7d4c7bae59c2bc7d01f1ff94c67588cc6b38fa6024886f2c078bfe09b5d9e6584cd6c521c3bb52f4de7687b37117a2dbbec0d59e92fa9a8cc3240d4432f91757aabcae03e87431dac003e7d73574bfdd8218",
"1f24eda69dbcb752847ec3ebb5dd42836d86e58500c7c98d906ecd82ed9ae47f6f48a3f67e4e43329c9a89b1ca526b9b35cbf7d25c1e353baffb590fd79be58ddb6c711f1a6b60e98620b851c688670412fcb0435657ba6b638d21f0f2a04f2f6b0bd8834837b10e438d5f4c7c2c71299cf7586ea9144ed09253d51f8f54dd6bff719d"
- },
- {
+ ),
+ Arguments.of(
6,
"06c4e8ffb6872fad96f9aaca5eee1553eb62aed0ad7198cef42e87f6a616c844611a30c4e4f37fe2fe23c0883cde5cf7059d88b657c7ed2087e3d210925ede716435d6d5d82597a1e52b9553919e804f5656278bd739880692c94bff2824d8e0b48cac1d24682699e4883389dc4f2faa2eb3b4db6e39debd5061ff3609916f3e07529a",
"82d3199d0013035682cc7f2a399d4c212544376a839aa863a0f4c91220ca7a6dc2ffb3aa05f2631f0fa9ac19b6e97eb7e6669e5ec254799350c8b8d189e8807800842a5383c4d907c932f34490aaf00064de8cdb157357bde37c1504d2960034930887603abc5ccb9f5247f79224baff6120a3c622a46d7b1bcaee02c5025460941256",
"be96b30b37919fe4379dfbe752ae77b4f7e2ab92f7ff27435f76f2f065f6a5f435ae01a1d14bd5a6b3b69d8cbd35f0b01ef2173ff6f9b640ca0bd4748efa398bf9a9c0acd6a66d9332fdc9b47ffe28ba7ab6090c26747b85f4fab22f936b71eb3f64613d8bd9dfabe9bb68da19de78321b481e5297df9e40ec8a3d662f3e1479c65de0"
- },
- {
+ ),
+ Arguments.of(
7,
"3f8770f387faad08faa9d8414e9f449ac68e6ff0417f673f602a646a891419fe66036ef6e6d1a8f54baa9fed1fc11c77cfb9cff65bae915045027046ebe0c01bf5a941f3bb0f73791d3fc0b84370f9f30af0cd5b0fc334dd61f70feb60dad785f070fef1f343ed933b49a5ca0d16a503f599a365a4296739248b28d1a20b0e2cc8975c",
"af0a7ec382aedc0cfd626e49e7628bc7a353a4cb108855541a5651bf64fbb28a7c5035ba0f48a9c73dabb2be0533d02e8fd5d0d5639a18b2803ba6bf527e1d145d5fd6406c437b79bcaad6c7bdf1cf4bd56a893c3eb9510335a7a798548c6753f74617bede88bef924ba4b334f8852476d90b26c5dc4c3668a2519266a562c6c8034a6",
"dc3b6485f9d94935329442916b0d059685ba815a1fa2a14107217453a7fc9f0e66266db2ea7c96843f9d8208e600a73f7f45b2f55b9e6d6a7ccf05daae63a3fdd10b25ac0bd2e224ce8291f88c05976d575df998477db86fb2cfbbf91725d62cb57acfeb3c2d973b89b503c2b60dde85a7802b69dc1ac2007d5623cbea8cbfb6b181f5"
- },
- {
+ ),
+ Arguments.of(
8,
"2351207d04fc16ade43ccab08600939c7c1fa70a5c0aaca76063d04c3228eaeb725d6d46ceed8f785ab9f2f9b06acfe398c6699c6129da084cb531177445a682894f9685eaf836999221d17c9a64a3a057000524cd2823986db378b074290a1a9b93a22e135ed2c14c7e20c6d045cd00b903400374126676ea78874d79f2dd7883cf5c",
"be2f5495c61cba1bb348a34948c004045e3bd4dae8f0fe82bf44d0da245a060048eb5e68ce6dea1eb0229e144f578b3aa7e9f4f85febd135df8525e6fe40c6f0340d13dd09b255ccd5112a94238f2be3c0b5b7ecde06580426a93e0708555a265305abf86d874e34b4995b788e37a823491f25127a502fe0704baa6bfdf04e76c13276",
"2b166978cef14d9d438046c720519d8b1cad707e199746f1562d0c87fbd32940f0e2545a96693a66654225ebbaac76d093bfa9cd8f525a53acb92a861a98c42e7d1c4ae82e68ab691d510012edd2a728f98cd4794ef757e94d6546961b4f280a51aac339cc95b64a92b83cc3f26d8af8dfb4c091c240acdb4d47728d23e7148720ef04"
- },
- {
+ ),
+ Arguments.of(
63,
"e9bc37a594daad83be9470df7f7b3798297c3d834ce80ba85d6e207627b7db7b1197012b1e7d9af4d7cb7bdd1f3bb49a90a9b5dec3ea2bbc6eaebce77f4e470cbf4687093b5352f04e4a4570fba233164e6acc36900e35d185886a827f7ea9bdc1e5c3ce88b095a200e62c10c043b3e9bc6cb9b6ac4dfa51794b02ace9f98779040755",
"bb1eb5d4afa793c1ebdd9fb08def6c36d10096986ae0cfe148cd101170ce37aea05a63d74a840aecd514f654f080e51ac50fd617d22610d91780fe6b07a26b0847abb38291058c97474ef6ddd190d30fc318185c09ca1589d2024f0a6f16d45f11678377483fa5c005b2a107cb9943e5da634e7046855eaa888663de55d6471371d55d",
"b6451e30b953c206e34644c6803724e9d2725e0893039cfc49584f991f451af3b89e8ff572d3da4f4022199b9563b9d70ebb616efff0763e9abec71b550f1371e233319c4c4e74da936ba8e5bbb29a598e007a0bbfa929c99738ca2cc098d59134d11ff300c39f82e2fce9f7f0fa266459503f64ab9913befc65fddc474f6dc1c67669"
- },
- {
+ ),
+ Arguments.of(
64,
"4eed7141ea4a5cd4b788606bd23f46e212af9cacebacdc7d1f4c6dc7f2511b98fc9cc56cb831ffe33ea8e7e1d1df09b26efd2767670066aa82d023b1dfe8ab1b2b7fbb5b97592d46ffe3e05a6a9b592e2949c74160e4674301bc3f97e04903f8c6cf95b863174c33228924cdef7ae47559b10b294acd660666c4538833582b43f82d74",
"ba8ced36f327700d213f120b1a207a3b8c04330528586f414d09f2f7d9ccb7e68244c26010afc3f762615bbac552a1ca909e67c83e2fd5478cf46b9e811efccc93f77a21b17a152ebaca1695733fdb086e23cd0eb48c41c034d52523fc21236e5d8c9255306e48d52ba40b4dac24256460d56573d1312319afcf3ed39d72d0bfc69acb",
"a5c4a7053fa86b64746d4bb688d06ad1f02a18fce9afd3e818fefaa7126bf73e9b9493a9befebe0bf0c9509fb3105cfa0e262cde141aa8e3f2c2f77890bb64a4cca96922a21ead111f6338ad5244f2c15c44cb595443ac2ac294231e31be4a4307d0a91e874d36fc9852aeb1265c09b6e0cda7c37ef686fbbcab97e8ff66718be048bb"
- },
- {
+ ),
+ Arguments.of(
65,
"de1e5fa0be70df6d2be8fffd0e99ceaa8eb6e8c93a63f2d8d1c30ecb6b263dee0e16e0a4749d6811dd1d6d1265c29729b1b75a9ac346cf93f0e1d7296dfcfd4313b3a227faaaaf7757cc95b4e87a49be3b8a270a12020233509b1c3632b3485eef309d0abc4a4a696c9decc6e90454b53b000f456a3f10079072baaf7a981653221f2c",
"c0a4edefa2d2accb9277c371ac12fcdbb52988a86edc54f0716e1591b4326e72d5e795f46a596b02d3d4bfb43abad1e5d19211152722ec1f20fef2cd413e3c22f2fc5da3d73041275be6ede3517b3b9f0fc67ade5956a672b8b75d96cb43294b9041497de92637ed3f2439225e683910cb3ae923374449ca788fb0f9bea92731bc26ad",
"51fd05c3c1cfbc8ed67d139ad76f5cf8236cd2acd26627a30c104dfd9d3ff8a82b02e8bd36d8498a75ad8c8e9b15eb386970283d6dd42c8ae7911cc592887fdbe26a0a5f0bf821cd92986c60b2502c9be3f98a9c133a7e8045ea867e0828c7252e739321f7c2d65daee4468eb4429efae469a42763f1f94977435d10dccae3e3dce88d"
- },
- {
+ ),
+ Arguments.of(
127,
"d81293fda863f008c09e92fc382a81f5a0b4a1251cba1634016a0f86a6bd640de3137d477156d1fde56b0cf36f8ef18b44b2d79897bece12227539ac9ae0a5119da47644d934d26e74dc316145dcb8bb69ac3f2e05c242dd6ee06484fcb0e956dc44355b452c5e2bbb5e2b66e99f5dd443d0cbcaaafd4beebaed24ae2f8bb672bcef78",
"c64200ae7dfaf35577ac5a9521c47863fb71514a3bcad18819218b818de85818ee7a317aaccc1458f78d6f65f3427ec97d9c0adb0d6dacd4471374b621b7b5f35cd54663c64dbe0b9e2d95632f84c611313ea5bd90b71ce97b3cf645776f3adc11e27d135cbadb9875c2bf8d3ae6b02f8a0206aba0c35bfe42574011931c9a255ce6dc",
"c91c090ceee3a3ac81902da31838012625bbcd73fcb92e7d7e56f78deba4f0c3feeb3974306966ccb3e3c69c337ef8a45660ad02526306fd685c88542ad00f759af6dd1adc2e50c2b8aac9f0c5221ff481565cf6455b772515a69463223202e5c371743e35210bbbbabd89651684107fd9fe493c937be16e39cfa7084a36207c99bea3"
- },
- {
+ ),
+ Arguments.of(
128,
"f17e570564b26578c33bb7f44643f539624b05df1a76c81f30acd548c44b45efa69faba091427f9c5c4caa873aa07828651f19c55bad85c47d1368b11c6fd99e47ecba5820a0325984d74fe3e4058494ca12e3f1d3293d0010a9722f7dee64f71246f75e9361f44cc8e214a100650db1313ff76a9f93ec6e84edb7add1cb4a95019b0c",
"b04fe15577457267ff3b6f3c947d93be581e7e3a4b018679125eaf86f6a628ecd86bbe0001f10bda47e6077b735016fca8119da11348d93ca302bbd125bde0db2b50edbe728a620bb9d3e6f706286aedea973425c0b9eedf8a38873544cf91badf49ad92a635a93f71ddfcee1eae536c25d1b270956be16588ef1cfef2f1d15f650bd5",
"81720f34452f58a0120a58b6b4608384b5c51d11f39ce97161a0c0e442ca022550e7cd651e312f0b4c6afb3c348ae5dd17d2b29fab3b894d9a0034c7b04fd9190cbd90043ff65d1657bbc05bfdecf2897dd894c7a1b54656d59a50b51190a9da44db426266ad6ce7c173a8c0bbe091b75e734b4dadb59b2861cd2518b4e7591e4b83c9"
- },
- {
+ ),
+ Arguments.of(
129,
"683aaae9f3c5ba37eaaf072aed0f9e30bac0865137bae68b1fde4ca2aebdcb12f96ffa7b36dd78ba321be7e842d364a62a42e3746681c8bace18a4a8a79649285c7127bf8febf125be9de39586d251f0d41da20980b70d35e3dac0eee59e468a894fa7e6a07129aaad09855f6ad4801512a116ba2b7841e6cfc99ad77594a8f2d181a7",
"d4a64dae6cdccbac1e5287f54f17c5f985105457c1a2ec1878ebd4b57e20d38f1c9db018541eec241b748f87725665b7b1ace3e0065b29c3bcb232c90e37897fa5aaee7e1e8a2ecfcd9b51463e42238cfdd7fee1aecb3267fa7f2128079176132a412cd8aaf0791276f6b98ff67359bd8652ef3a203976d5ff1cd41885573487bcd683",
"938d2d4435be30eafdbb2b7031f7857c98b04881227391dc40db3c7b21f41fc18d72d0f9c1de5760e1941aebf3100b51d64644cb459eb5d20258e233892805eb98b07570ef2a1787cd48e117c8d6a63a68fd8fc8e59e79dbe63129e88352865721c8d5f0cf183f85e0609860472b0d6087cefdd186d984b21542c1c780684ed6832d8d"
- },
- {
+ ),
+ Arguments.of(
1023,
"10108970eeda3eb932baac1428c7a2163b0e924c9a9e25b35bba72b28f70bd11a182d27a591b05592b15607500e1e8dd56bc6c7fc063715b7a1d737df5bad3339c56778957d870eb9717b57ea3d9fb68d1b55127bba6a906a4a24bbd5acb2d123a37b28f9e9a81bbaae360d58f85e5fc9d75f7c370a0cc09b6522d9c8d822f2f28f485",
"c951ecdf03288d0fcc96ee3413563d8a6d3589547f2c2fb36d9786470f1b9d6e890316d2e6d8b8c25b0a5b2180f94fb1a158ef508c3cde45e2966bd796a696d3e13efd86259d756387d9becf5c8bf1ce2192b87025152907b6d8cc33d17826d8b7b9bc97e38c3c85108ef09f013e01c229c20a83d9e8efac5b37470da28575fd755a10",
"74a16c1c3d44368a86e1ca6df64be6a2f64cce8f09220787450722d85725dea59c413264404661e9e4d955409dfe4ad3aa487871bcd454ed12abfe2c2b1eb7757588cf6cb18d2eccad49e018c0d0fec323bec82bf1644c6325717d13ea712e6840d3e6e730d35553f59eff5377a9c350bcc1556694b924b858f329c44ee64b884ef00d"
- },
- {
+ ),
+ Arguments.of(
1024,
"42214739f095a406f3fc83deb889744ac00df831c10daa55189b5d121c855af71cf8107265ecdaf8505b95d8fcec83a98a6a96ea5109d2c179c47a387ffbb404756f6eeae7883b446b70ebb144527c2075ab8ab204c0086bb22b7c93d465efc57f8d917f0b385c6df265e77003b85102967486ed57db5c5ca170ba441427ed9afa684e",
"75c46f6f3d9eb4f55ecaaee480db732e6c2105546f1e675003687c31719c7ba4a78bc838c72852d4f49c864acb7adafe2478e824afe51c8919d06168414c265f298a8094b1ad813a9b8614acabac321f24ce61c5a5346eb519520d38ecc43e89b5000236df0597243e4d2493fd626730e2ba17ac4d8824d09d1a4a8f57b8227778e2de",
"7356cd7720d5b66b6d0697eb3177d9f8d73a4a5c5e968896eb6a6896843027066c23b601d3ddfb391e90d5c8eccdef4ae2a264bce9e612ba15e2bc9d654af1481b2e75dbabe615974f1070bba84d56853265a34330b4766f8e75edd1f4a1650476c10802f22b64bd3919d246ba20a17558bc51c199efdec67e80a227251808d8ce5bad"
- },
- {
+ ),
+ Arguments.of(
1025,
"d00278ae47eb27b34faecf67b4fe263f82d5412916c1ffd97c8cb7fb814b8444f4c4a22b4b399155358a994e52bf255de60035742ec71bd08ac275a1b51cc6bfe332b0ef84b409108cda080e6269ed4b3e2c3f7d722aa4cdc98d16deb554e5627be8f955c98e1d5f9565a9194cad0c4285f93700062d9595adb992ae68ff12800ab67a",
"357dc55de0c7e382c900fd6e320acc04146be01db6a8ce7210b7189bd664ea69362396b77fdc0d2634a552970843722066c3c15902ae5097e00ff53f1e116f1cd5352720113a837ab2452cafbde4d54085d9cf5d21ca613071551b25d52e69d6c81123872b6f19cd3bc1333edf0c52b94de23ba772cf82636cff4542540a7738d5b930",
"effaa245f065fbf82ac186839a249707c3bddf6d3fdda22d1b95a3c970379bcb5d31013a167509e9066273ab6e2123bc835b408b067d88f96addb550d96b6852dad38e320b9d940f86db74d398c770f462118b35d2724efa13da97194491d96dd37c3c09cbef665953f2ee85ec83d88b88d11547a6f911c8217cca46defa2751e7f3ad"
- },
- {
+ ),
+ Arguments.of(
2048,
"e776b6028c7cd22a4d0ba182a8bf62205d2ef576467e838ed6f2529b85fba24a9a60bf80001410ec9eea6698cd537939fad4749edd484cb541aced55cd9bf54764d063f23f6f1e32e12958ba5cfeb1bf618ad094266d4fc3c968c2088f677454c288c67ba0dba337b9d91c7e1ba586dc9a5bc2d5e90c14f53a8863ac75655461cea8f9",
"879cf1fa2ea0e79126cb1063617a05b6ad9d0b696d0d757cf053439f60a99dd10173b961cd574288194b23ece278c330fbb8585485e74967f31352a8183aa782b2b22f26cdcadb61eed1a5bc144b8198fbb0c13abbf8e3192c145d0a5c21633b0ef86054f42809df823389ee40811a5910dcbd1018af31c3b43aa55201ed4edaac74fe",
"7b2945cb4fef70885cc5d78a87bf6f6207dd901ff239201351ffac04e1088a23e2c11a1ebffcea4d80447867b61badb1383d842d4e79645d48dd82ccba290769caa7af8eaa1bd78a2a5e6e94fbdab78d9c7b74e894879f6a515257ccf6f95056f4e25390f24f6b35ffbb74b766202569b1d797f2d4bd9d17524c720107f985f4ddc583"
- },
- {
+ ),
+ Arguments.of(
2049,
"5f4d72f40d7a5f82b15ca2b2e44b1de3c2ef86c426c95c1af0b687952256303096de31d71d74103403822a2e0bc1eb193e7aecc9643a76b7bbc0c9f9c52e8783aae98764ca468962b5c2ec92f0c74eb5448d519713e09413719431c802f948dd5d90425a4ecdadece9eb178d80f26efccae630734dff63340285adec2aed3b51073ad3",
"9f29700902f7c86e514ddc4df1e3049f258b2472b6dd5267f61bf13983b78dd5f9a88abfefdfa1e00b418971f2b39c64ca621e8eb37fceac57fd0c8fc8e117d43b81447be22d5d8186f8f5919ba6bcc6846bd7d50726c06d245672c2ad4f61702c646499ee1173daa061ffe15bf45a631e2946d616a4c345822f1151284712f76b2b0e",
"2ea477c5515cc3dd606512ee72bb3e0e758cfae7232826f35fb98ca1bcbdf27316d8e9e79081a80b046b60f6a263616f33ca464bd78d79fa18200d06c7fc9bffd808cc4755277a7d5e09da0f29ed150f6537ea9bed946227ff184cc66a72a5f8c1e4bd8b04e81cf40fe6dc4427ad5678311a61f4ffc39d195589bdbc670f63ae70f4b6"
- },
- {
+ ),
+ Arguments.of(
3072,
"b98cb0ff3623be03326b373de6b9095218513e64f1ee2edd2525c7ad1e5cffd29a3f6b0b978d6608335c09dc94ccf682f9951cdfc501bfe47b9c9189a6fc7b404d120258506341a6d802857322fbd20d3e5dae05b95c88793fa83db1cb08e7d8008d1599b6209d78336e24839724c191b2a52a80448306e0daa84a3fdb566661a37e11",
"044a0e7b172a312dc02a4c9a818c036ffa2776368d7f528268d2e6b5df19177022f302d0529e4174cc507c463671217975e81dab02b8fdeb0d7ccc7568dd22574c783a76be215441b32e91b9a904be8ea81f7a0afd14bad8ee7c8efc305ace5d3dd61b996febe8da4f56ca0919359a7533216e2999fc87ff7d8f176fbecb3d6f34278b",
"050df97f8c2ead654d9bb3ab8c9178edcd902a32f8495949feadcc1e0480c46b3604131bbd6e3ba573b6dd682fa0a63e5b165d39fc43a625d00207607a2bfeb65ff1d29292152e26b298868e3b87be95d6458f6f2ce6118437b632415abe6ad522874bcd79e4030a5e7bad2efa90a7a7c67e93f0a18fb28369d0a9329ab5c24134ccb0"
- },
- {
+ ),
+ Arguments.of(
3073,
"7124b49501012f81cc7f11ca069ec9226cecb8a2c850cfe644e327d22d3e1cd39a27ae3b79d68d89da9bf25bc27139ae65a324918a5f9b7828181e52cf373c84f35b639b7fccbb985b6f2fa56aea0c18f531203497b8bbd3a07ceb5926f1cab74d14bd66486d9a91eba99059a98bd1cd25876b2af5a76c3e9eed554ed72ea952b603bf",
"68dede9bef00ba89e43f31a6825f4cf433389fedae75c04ee9f0cf16a427c95a96d6da3fe985054d3478865be9a092250839a697bbda74e279e8a9e69f0025e4cfddd6cfb434b1cd9543aaf97c635d1b451a4386041e4bb100f5e45407cbbc24fa53ea2de3536ccb329e4eb9466ec37093a42cf62b82903c696a93a50b702c80f3c3c5",
"72613c9ec9ff7e40f8f5c173784c532ad852e827dba2bf85b2ab4b76f7079081576288e552647a9d86481c2cae75c2dd4e7c5195fb9ada1ef50e9c5098c249d743929191441301c69e1f48505a4305ec1778450ee48b8e69dc23a25960fe33070ea549119599760a8a2d28aeca06b8c5e9ba58bc19e11fe57b6ee98aa44b2a8e6b14a5"
- },
- {
+ ),
+ Arguments.of(
4096,
"015094013f57a5277b59d8475c0501042c0b642e531b0a1c8f58d2163229e9690289e9409ddb1b99768eafe1623da896faf7e1114bebeadc1be30829b6f8af707d85c298f4f0ff4d9438aef948335612ae921e76d411c3a9111df62d27eaf871959ae0062b5492a0feb98ef3ed4af277f5395172dbe5c311918ea0074ce0036454f620",
"befc660aea2f1718884cd8deb9902811d332f4fc4a38cf7c7300d597a081bfc0bbb64a36edb564e01e4b4aaf3b060092a6b838bea44afebd2deb8298fa562b7b597c757b9df4c911c3ca462e2ac89e9a787357aaf74c3b56d5c07bc93ce899568a3eb17d9250c20f6c5f6c1e792ec9a2dcb715398d5a6ec6d5c54f586a00403a1af1de",
"1e0d7f3db8c414c97c6307cbda6cd27ac3b030949da8e23be1a1a924ad2f25b9d78038f7b198596c6cc4a9ccf93223c08722d684f240ff6569075ed81591fd93f9fff1110b3a75bc67e426012e5588959cc5a4c192173a03c00731cf84544f65a2fb9378989f72e9694a6a394a8a30997c2e67f95a504e631cd2c5f55246024761b245"
- },
- {
+ ),
+ Arguments.of(
4097,
"9b4052b38f1c5fc8b1f9ff7ac7b27cd242487b3d890d15c96a1c25b8aa0fb99505f91b0b5600a11251652eacfa9497b31cd3c409ce2e45cfe6c0a016967316c426bd26f619eab5d70af9a418b845c608840390f361630bd497b1ab44019316357c61dbe091ce72fc16dc340ac3d6e009e050b3adac4b5b2c92e722cffdc46501531956",
"00df940cd36bb9fa7cbbc3556744e0dbc8191401afe70520ba292ee3ca80abbc606db4976cfdd266ae0abf667d9481831ff12e0caa268e7d3e57260c0824115a54ce595ccc897786d9dcbf495599cfd90157186a46ec800a6763f1c59e36197e9939e900809f7077c102f888caaf864b253bc41eea812656d46742e4ea42769f89b83f",
"aca51029626b55fda7117b42a7c211f8c6e9ba4fe5b7a8ca922f34299500ead8a897f66a400fed9198fd61dd2d58d382458e64e100128075fc54b860934e8de2e84170734b06e1d212a117100820dbc48292d148afa50567b8b84b1ec336ae10d40c8c975a624996e12de31abbe135d9d159375739c333798a80c64ae895e51e22f3ad"
- },
- {
+ ),
+ Arguments.of(
5120,
"9cadc15fed8b5d854562b26a9536d9707cadeda9b143978f319ab34230535833acc61c8fdc114a2010ce8038c853e121e1544985133fccdd0a2d507e8e615e611e9a0ba4f47915f49e53d721816a9198e8b30f12d20ec3689989175f1bf7a300eee0d9321fad8da232ece6efb8e9fd81b42ad161f6b9550a069e66b11b40487a5f5059",
"2c493e48e9b9bf31e0553a22b23503c0a3388f035cece68eb438d22fa1943e209b4dc9209cd80ce7c1f7c9a744658e7e288465717ae6e56d5463d4f80cdb2ef56495f6a4f5487f69749af0c34c2cdfa857f3056bf8d807336a14d7b89bf62bef2fb54f9af6a546f818dc1e98b9e07f8a5834da50fa28fb5874af91bf06020d1bf0120e",
"7a7acac8a02adcf3038d74cdd1d34527de8a0fcc0ee3399d1262397ce5817f6055d0cefd84d9d57fe792d65a278fd20384ac6c30fdb340092f1a74a92ace99c482b28f0fc0ef3b923e56ade20c6dba47e49227166251337d80a037e987ad3a7f728b5ab6dfafd6e2ab1bd583a95d9c895ba9c2422c24ea0f62961f0dca45cad47bfa0d"
- },
- {
+ ),
+ Arguments.of(
5121,
"628bd2cb2004694adaab7bbd778a25df25c47b9d4155a55f8fbd79f2fe154cff96adaab0613a6146cdaabe498c3a94e529d3fc1da2bd08edf54ed64d40dcd6777647eac51d8277d70219a9694334a68bc8f0f23e20b0ff70ada6f844542dfa32cd4204ca1846ef76d811cdb296f65e260227f477aa7aa008bac878f72257484f2b6c95",
"6ccf1c34753e7a044db80798ecd0782a8f76f33563accaddbfbb2e0ea4b2d0240d07e63f13667a8d1490e5e04f13eb617aea16a8c8a5aaed1ef6fbde1b0515e3c81050b361af6ead126032998290b563e3caddeaebfab592e155f2e161fb7cba939092133f23f9e65245e58ec23457b78a2e8a125588aad6e07d7f11a85b88d375b72d",
"b07f01e518e702f7ccb44a267e9e112d403a7b3f4883a47ffbed4b48339b3c341a0add0ac032ab5aaea1e4e5b004707ec5681ae0fcbe3796974c0b1cf31a194740c14519273eedaabec832e8a784b6e7cfc2c5952677e6c3f2c3914454082d7eb1ce1766ac7d75a4d3001fc89544dd46b5147382240d689bbbaefc359fb6ae30263165"
- },
- {
+ ),
+ Arguments.of(
6144,
"3e2e5b74e048f3add6d21faab3f83aa44d3b2278afb83b80b3c35164ebeca2054d742022da6fdda444ebc384b04a54c3ac5839b49da7d39f6d8a9db03deab32aade156c1c0311e9b3435cde0ddba0dce7b26a376cad121294b689193508dd63151603c6ddb866ad16c2ee41585d1633a2cea093bea714f4c5d6b903522045b20395c83",
"3d6b6d21281d0ade5b2b016ae4034c5dec10ca7e475f90f76eac7138e9bc8f1dc35754060091dc5caf3efabe0603c60f45e415bb3407db67e6beb3d11cf8e4f7907561f05dace0c15807f4b5f389c841eb114d81a82c02a00b57206b1d11fa6e803486b048a5ce87105a686dee041207e095323dfe172df73deb8c9532066d88f9da7e",
"2a95beae63ddce523762355cf4b9c1d8f131465780a391286a5d01abb5683a1597099e3c6488aab6c48f3c15dbe1942d21dbcdc12115d19a8b8465fb54e9053323a9178e4275647f1a9927f6439e52b7031a0b465c861a3fc531527f7758b2b888cf2f20582e9e2c593709c0a44f9c6e0f8b963994882ea4168827823eef1f64169fef"
- },
- {
+ ),
+ Arguments.of(
6145,
"f1323a8631446cc50536a9f705ee5cb619424d46887f3c376c695b70e0f0507f18a2cfdd73c6e39dd75ce7c1c6e3ef238fd54465f053b25d21044ccb2093beb015015532b108313b5829c3621ce324b8e14229091b7c93f32db2e4e63126a377d2a63a3597997d4f1cba59309cb4af240ba70cebff9a23d5e3ff0cdae2cfd54e070022",
"9ac301e9e39e45e3250a7e3b3df701aa0fb6889fbd80eeecf28dbc6300fbc539f3c184ca2f59780e27a576c1d1fb9772e99fd17881d02ac7dfd39675aca918453283ed8c3169085ef4a466b91c1649cc341dfdee60e32231fc34c9c4e0b9a2ba87ca8f372589c744c15fd6f985eec15e98136f25beeb4b13c4e43dc84abcc79cd4646c",
"379bcc61d0051dd489f686c13de00d5b14c505245103dc040d9e4dd1facab8e5114493d029bdbd295aaa744a59e31f35c7f52dba9c3642f773dd0b4262a9980a2aef811697e1305d37ba9d8b6d850ef07fe41108993180cf779aeece363704c76483458603bbeeb693cffbbe5588d1f3535dcad888893e53d977424bb707201569a8d2"
- },
- {
+ ),
+ Arguments.of(
7168,
"61da957ec2499a95d6b8023e2b0e604ec7f6b50e80a9678b89d2628e99ada77a5707c321c83361793b9af62a40f43b523df1c8633cecb4cd14d00bdc79c78fca5165b863893f6d38b02ff7236c5a9a8ad2dba87d24c547cab046c29fc5bc1ed142e1de4763613bb162a5a538e6ef05ed05199d751f9eb58d332791b8d73fb74e4fce95",
"b42835e40e9d4a7f42ad8cc04f85a963a76e18198377ed84adddeaecacc6f3fca2f01d5277d69bb681c70fa8d36094f73ec06e452c80d2ff2257ed82e7ba348400989a65ee8daa7094ae0933e3d2210ac6395c4af24f91c2b590ef87d7788d7066ea3eaebca4c08a4f14b9a27644f99084c3543711b64a070b94f2c9d1d8a90d035d52",
"11c37a112765370c94a51415d0d651190c288566e295d505defdad895dae223730d5a5175a38841693020669c7638f40b9bc1f9f39cf98bda7a5b54ae24218a800a2116b34665aa95d846d97ea988bfcb53dd9c055d588fa21ba78996776ea6c40bc428b53c62b5f3ccf200f647a5aae8067f0ea1976391fcc72af1945100e2a6dcb88"
- },
- {
+ ),
+ Arguments.of(
7169,
"a003fc7a51754a9b3c7fae0367ab3d782dccf28855a03d435f8cfe74605e781798a8b20534be1ca9eb2ae2df3fae2ea60e48c6fb0b850b1385b5de0fe460dbe9d9f9b0d8db4435da75c601156df9d047f4ede008732eb17adc05d96180f8a73548522840779e6062d643b79478a6e8dbce68927f36ebf676ffa7d72d5f68f050b119c8",
"ed9b1a922c046fdb3d423ae34e143b05ca1bf28b710432857bf738bcedbfa5113c9e28d72fcbfc020814ce3f5d4fc867f01c8f5b6caf305b3ea8a8ba2da3ab69fabcb438f19ff11f5378ad4484d75c478de425fb8e6ee809b54eec9bdb184315dc856617c09f5340451bf42fd3270a7b0b6566169f242e533777604c118a6358250f54",
"554b0a5efea9ef183f2f9b931b7497995d9eb26f5c5c6dad2b97d62fc5ac31d99b20652c016d88ba2a611bbd761668d5eda3e568e940faae24b0d9991c3bd25a65f770b89fdcadabcb3d1a9c1cb63e69721cacf1ae69fefdcef1e3ef41bc5312ccc17222199e47a26552c6adc460cf47a72319cb5039369d0060eaea59d6c65130f1dd"
- },
- {
+ ),
+ Arguments.of(
8192,
"aae792484c8efe4f19e2ca7d371d8c467ffb10748d8a5a1ae579948f718a2a635fe51a27db045a567c1ad51be5aa34c01c6651c4d9b5b5ac5d0fd58cf18dd61a47778566b797a8c67df7b1d60b97b19288d2d877bb2df417ace009dcb0241ca1257d62712b6a4043b4ff33f690d849da91ea3bf711ed583cb7b7a7da2839ba71309bbf",
"dc9637c8845a770b4cbf76b8daec0eebf7dc2eac11498517f08d44c8fc00d58a4834464159dcbc12a0ba0c6d6eb41bac0ed6585cabfe0aca36a375e6c5480c22afdc40785c170f5a6b8a1107dbee282318d00d915ac9ed1143ad40765ec120042ee121cd2baa36250c618adaf9e27260fda2f94dea8fb6f08c04f8f10c78292aa46102",
"ad01d7ae4ad059b0d33baa3c01319dcf8088094d0359e5fd45d6aeaa8b2d0c3d4c9e58958553513b67f84f8eac653aeeb02ae1d5672dcecf91cd9985a0e67f4501910ecba25555395427ccc7241d70dc21c190e2aadee875e5aae6bf1912837e53411dabf7a56cbf8e4fb780432b0d7fe6cec45024a0788cf5874616407757e9e6bef7"
- },
- {
+ ),
+ Arguments.of(
8193,
"bab6c09cb8ce8cf459261398d2e7aef35700bf488116ceb94a36d0f5f1b7bc3bb2282aa69be089359ea1154b9a9286c4a56af4de975a9aa4a5c497654914d279bea60bb6d2cf7225a2fa0ff5ef56bbe4b149f3ed15860f78b4e2ad04e158e375c1e0c0b551cd7dfc82f1b155c11b6b3ed51ec9edb30d133653bb5709d1dbd55f4e1ff6",
"954a2a75420c8d6547e3ba5b98d963e6fa6491addc8c023189cc519821b4a1f5f03228648fd983aef045c2fa8290934b0866b615f585149587dda2299039965328835a2b18f1d63b7e300fc76ff260b571839fe44876a4eae66cbac8c67694411ed7e09df51068a22c6e67d6d3dd2cca8ff12e3275384006c80f4db68023f24eebba57",
"af1e0346e389b17c23200270a64aa4e1ead98c61695d917de7d5b00491c9b0f12f20a01d6d622edf3de026a4db4e4526225debb93c1237934d71c7340bb5916158cbdafe9ac3225476b6ab57a12357db3abbad7a26c6e66290e44034fb08a20a8d0ec264f309994d2810c49cfba6989d7abb095897459f5425adb48aba07c5fb3c83c0"
- },
- {
+ ),
+ Arguments.of(
16384,
"f875d6646de28985646f34ee13be9a576fd515f76b5b0a26bb324735041ddde49d764c270176e53e97bdffa58d549073f2c660be0e81293767ed4e4929f9ad34bbb39a529334c57c4a381ffd2a6d4bfdbf1482651b172aa883cc13408fa67758a3e47503f93f87720a3177325f7823251b85275f64636a8f1d599c2e49722f42e93893",
"9e9fc4eb7cf081ea7c47d1807790ed211bfec56aa25bb7037784c13c4b707b0df9e601b101e4cf63a404dfe50f2e1865bb12edc8fca166579ce0c70dba5a5c0fc960ad6f3772183416a00bd29d4c6e651ea7620bb100c9449858bf14e1ddc9ecd35725581ca5b9160de04060045993d972571c3e8f71e9d0496bfa744656861b169d65",
"160e18b5878cd0df1c3af85eb25a0db5344d43a6fbd7a8ef4ed98d0714c3f7e160dc0b1f09caa35f2f417b9ef309dfe5ebd67f4c9507995a531374d099cf8ae317542e885ec6f589378864d3ea98716b3bbb65ef4ab5e0ab5bb298a501f19a41ec19af84a5e6b428ecd813b1a47ed91c9657c3fba11c406bc316768b58f6802c9e9b57"
- },
- {
+ ),
+ Arguments.of(
31744,
"62b6960e1a44bcc1eb1a611a8d6235b6b4b78f32e7abc4fb4c6cdcce94895c47860cc51f2b0c28a7b77304bd55fe73af663c02d3f52ea053ba43431ca5bab7bfea2f5e9d7121770d88f70ae9649ea713087d1914f7f312147e247f87eb2d4ffef0ac978bf7b6579d57d533355aa20b8b77b13fd09748728a5cc327a8ec470f4013226f",
"efa53b389ab67c593dba624d898d0f7353ab99e4ac9d42302ee64cbf9939a4193a7258db2d9cd32a7a3ecfce46144114b15c2fcb68a618a976bd74515d47be08b628be420b5e830fade7c080e351a076fbc38641ad80c736c8a18fe3c66ce12f95c61c2462a9770d60d0f77115bbcd3782b593016a4e728d4c06cee4505cb0c08a42ec",
"39772aef80e0ebe60596361e45b061e8f417429d529171b6764468c22928e28e9759adeb797a3fbf771b1bcea30150a020e317982bf0d6e7d14dd9f064bc11025c25f31e81bd78a921db0174f03dd481d30e93fd8e90f8b2fee209f849f2d2a52f31719a490fb0ba7aea1e09814ee912eba111a9fde9d5c274185f7bae8ba85d300a2b"
- },
- {
+ ),
+ Arguments.of(
102400,
"bc3e3d41a1146b069abffad3c0d44860cf664390afce4d9661f7902e7943e085e01c59dab908c04c3342b816941a26d69c2605ebee5ec5291cc55e15b76146e6745f0601156c3596cb75065a9c57f35585a52e1ac70f69131c23d611ce11ee4ab1ec2c009012d236648e77be9295dd0426f29b764d65de58eb7d01dd42248204f45f8e",
"1c35d1a5811083fd7119f5d5d1ba027b4d01c0c6c49fb6ff2cf75393ea5db4a7f9dbdd3e1d81dcbca3ba241bb18760f207710b751846faaeb9dff8262710999a59b2aa1aca298a032d94eacfadf1aa192418eb54808db23b56e34213266aa08499a16b354f018fc4967d05f8b9d2ad87a7278337be9693fc638a3bfdbe314574ee6fc4",
"4652cff7a3f385a6103b5c260fc1593e13c778dbe608efb092fe7ee69df6e9c6d83a3e041bc3a48df2879f4a0a3ed40e7c961c73eff740f3117a0504c2dff4786d44fb17f1549eb0ba585e40ec29bf7732f0b7e286ff8acddc4cb1e23b87ff5d824a986458dcc6a04ac83969b80637562953df51ed1a7e90a7926924d2763778be8560"
- }
- };
+ )
+ );
}
private final Blake3 hasher = Blake3.initHash();
private final Blake3 keyedHasher = Blake3.initKeyedHash(KEY);
private final Blake3 kdfHasher = Blake3.initKeyDerivationFunction(CTX);
- private final byte[] input;
- private final byte[] hash;
- private final byte[] keyedHash;
- private final byte[] deriveKey;
+ private byte[] inputByteArray;
+ private byte[] hashByteArray;
+ private byte[] keyedHashByteArray;
+ private byte[] deriveKeyByteArray;
- public Blake3TestVectorsTest(final int inputLength, final String hash, final String keyedHash, final String deriveKey)
+ private void initData(final int inputLength, final String hash, final String keyedHash, final String deriveKey)
throws DecoderException {
- input = new byte[inputLength];
- for (int i = 0; i < input.length; i++) {
- input[i] = (byte) (i % 251);
+ this.inputByteArray = new byte[inputLength];
+ for (int i = 0; i < inputByteArray.length; i++) {
+ inputByteArray[i] = (byte) (i % 251);
}
- this.hash = Hex.decodeHex(hash);
- this.keyedHash = Hex.decodeHex(keyedHash);
- this.deriveKey = Hex.decodeHex(deriveKey);
+ this.hashByteArray = Hex.decodeHex(hash);
+ this.keyedHashByteArray = Hex.decodeHex(keyedHash);
+ this.deriveKeyByteArray = Hex.decodeHex(deriveKey);
}
- @Test
- public void hashArbitraryOutputLength() {
- hasher.update(input);
- final byte[] actual = hasher.doFinalize(hash.length);
- assertArrayEquals(hash, actual);
+ @ParameterizedTest
+ @MethodSource("data")
+ public void hashArbitraryOutputLength(int inputLength, String hash, String keyedHash, String deriveKey) throws DecoderException {
+ initData(inputLength, hash, keyedHash, deriveKey);
+ hasher.update(inputByteArray);
+ final byte[] actual = hasher.doFinalize(hashByteArray.length);
+ assertArrayEquals(hashByteArray, actual);
}
- @Test
- public void hashTruncatedOutput() {
- final byte[] actual = Blake3.hash(input);
- assertArrayEquals(Arrays.copyOf(this.hash, 32), actual);
+ @ParameterizedTest
+ @MethodSource("data")
+ public void hashTruncatedOutput(int inputLength, String hash, String keyedHash, String deriveKey) throws DecoderException {
+ initData(inputLength, hash, keyedHash, deriveKey);
+ final byte[] actual = Blake3.hash(inputByteArray);
+ assertArrayEquals(Arrays.copyOf(this.hashByteArray, 32), actual);
}
- @Test
- public void keyedHashArbitraryOutputLength() {
- keyedHasher.update(input);
- final byte[] actual = keyedHasher.doFinalize(keyedHash.length);
- assertArrayEquals(keyedHash, actual);
+ @ParameterizedTest
+ @MethodSource("data")
+ public void keyedHashArbitraryOutputLength(int inputLength, String hash, String keyedHash, String deriveKey) throws DecoderException {
+ initData(inputLength, hash, keyedHash, deriveKey);
+ keyedHasher.update(inputByteArray);
+ final byte[] actual = keyedHasher.doFinalize(keyedHashByteArray.length);
+ assertArrayEquals(keyedHashByteArray, actual);
}
- @Test
- public void keyedHashTruncatedOutput() {
- final byte[] actual = Blake3.keyedHash(KEY, input);
- assertArrayEquals(Arrays.copyOf(keyedHash, 32), actual);
+ @ParameterizedTest
+ @MethodSource("data")
+ public void keyedHashTruncatedOutput(int inputLength, String hash, String keyedHash, String deriveKey) throws DecoderException {
+ initData(inputLength, hash, keyedHash, deriveKey);
+ final byte[] actual = Blake3.keyedHash(KEY, inputByteArray);
+ assertArrayEquals(Arrays.copyOf(keyedHashByteArray, 32), actual);
}
- @Test
- public void keyDerivation() {
- kdfHasher.update(input);
- final byte[] actual = kdfHasher.doFinalize(deriveKey.length);
- assertArrayEquals(deriveKey, actual);
+ @ParameterizedTest
+ @MethodSource("data")
+ public void keyDerivation(int inputLength, String hash, String keyedHash, String deriveKey) throws DecoderException {
+ initData(inputLength, hash, keyedHash, deriveKey);
+ kdfHasher.update(inputByteArray);
+ final byte[] actual = kdfHasher.doFinalize(deriveKeyByteArray.length);
+ assertArrayEquals(deriveKeyByteArray, actual);
kdfHasher.reset();
- kdfHasher.update(input);
+ kdfHasher.update(inputByteArray);
final byte[] truncated = kdfHasher.doFinalize(32);
- assertArrayEquals(Arrays.copyOf(deriveKey, 32), truncated);
+ assertArrayEquals(Arrays.copyOf(deriveKeyByteArray, 32), truncated);
}
}
diff --git a/src/test/java/org/apache/commons/codec/digest/CryptTest.java b/src/test/java/org/apache/commons/codec/digest/CryptTest.java
index 8633200..0085352 100644
--- a/src/test/java/org/apache/commons/codec/digest/CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/CryptTest.java
@@ -16,12 +16,9 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
public class CryptTest {
diff --git a/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java b/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
index a27ac67..e480e68 100644
--- a/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
@@ -18,12 +18,8 @@
package org.apache.commons.codec.digest;
import static org.apache.commons.codec.binary.StringUtils.getBytesUtf8;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -43,10 +39,10 @@
import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.SystemUtils;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
/**
* Tests DigestUtils methods.
@@ -65,11 +61,11 @@
private RandomAccessFile testRandomAccessFileWrapper;
private void assumeJava8() {
- Assume.assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8));
+ assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8));
}
private void assumeJava9() {
- Assume.assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9));
+ assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9));
}
byte[] getTestData() {
@@ -88,7 +84,7 @@
return testRandomAccessFileWrapper;
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
new Random().nextBytes(testData);
testFile = File.createTempFile(DigestUtilsTest.class.getName(), ".dat");
@@ -103,7 +99,7 @@
testRandomAccessFileWrapper = new RandomAccessFile(testRandomAccessFile, "rw");
}
- @After
+ @AfterEach
public void tearDown() {
if (!testFile.delete()) {
testFile.deleteOnExit();
diff --git a/src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java b/src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java
index 0538670..4a8bbb6 100644
--- a/src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java
@@ -21,21 +21,21 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
+import java.util.stream.Stream;
import javax.crypto.Mac;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.SystemUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -44,7 +44,6 @@
*
* @since 1.11
*/
-@RunWith(Parameterized.class)
public class HmacAlgorithmsTest {
static final String STANDARD_KEY_STRING = "key";
@@ -93,136 +92,155 @@
private static final byte[] EMPTY_BYTE_ARRAY = {};
// TODO HMAC_SHA_224
- @Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- List<Object[]> list = Arrays.asList(
+ public static Stream<Arguments> data() {
+ List<Arguments> list = Arrays.asList(
// @formatter:off
- new Object[][] { { HmacAlgorithms.HMAC_MD5, STANDARD_MD5_RESULT_BYTES, STANDARD_MD5_RESULT_STRING },
- { HmacAlgorithms.HMAC_SHA_1, STANDARD_SHA1_RESULT_BYTES, STANDARD_SHA1_RESULT_STRING },
- { HmacAlgorithms.HMAC_SHA_256, STANDARD_SHA256_RESULT_BYTES, STANDARD_SHA256_RESULT_STRING },
- { HmacAlgorithms.HMAC_SHA_384, STANDARD_SHA384_RESULT_BYTES, STANDARD_SHA384_RESULT_STRING },
- { HmacAlgorithms.HMAC_SHA_512, STANDARD_SHA512_RESULT_BYTES, STANDARD_SHA512_RESULT_STRING } });
+ Arguments.of( HmacAlgorithms.HMAC_MD5, STANDARD_MD5_RESULT_BYTES, STANDARD_MD5_RESULT_STRING ),
+ Arguments.of( HmacAlgorithms.HMAC_SHA_1, STANDARD_SHA1_RESULT_BYTES, STANDARD_SHA1_RESULT_STRING ),
+ Arguments.of( HmacAlgorithms.HMAC_SHA_256, STANDARD_SHA256_RESULT_BYTES, STANDARD_SHA256_RESULT_STRING ),
+ Arguments.of( HmacAlgorithms.HMAC_SHA_384, STANDARD_SHA384_RESULT_BYTES, STANDARD_SHA384_RESULT_STRING ),
+ Arguments.of( HmacAlgorithms.HMAC_SHA_512, STANDARD_SHA512_RESULT_BYTES, STANDARD_SHA512_RESULT_STRING ));
// @formatter:on
if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) {
list = new ArrayList<>(list);
- list.add(new Object[] {HmacAlgorithms.HMAC_SHA_224, STANDARD_SHA224_RESULT_BYTES, STANDARD_SHA224_RESULT_STRING});
+ list.add(Arguments.of(HmacAlgorithms.HMAC_SHA_224, STANDARD_SHA224_RESULT_BYTES, STANDARD_SHA224_RESULT_STRING));
}
- return list;
+ return list.stream();
}
private DigestUtilsTest digestUtilsTest;
- private final HmacAlgorithms hmacAlgorithm;
-
- private final byte[] standardResultBytes;
- private final String standardResultString;
-
- public HmacAlgorithmsTest(final HmacAlgorithms hmacAlgorithm, final byte[] standardResultBytes, final String standardResultString) {
- Assume.assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
- this.hmacAlgorithm = hmacAlgorithm;
- this.standardResultBytes = standardResultBytes;
- this.standardResultString = standardResultString;
- }
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
digestUtilsTest = new DigestUtilsTest();
digestUtilsTest.setUp();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
digestUtilsTest.tearDown();
digestUtilsTest = null;
}
- @Test
- public void testAlgorithm() throws NoSuchAlgorithmException {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testAlgorithm(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) throws NoSuchAlgorithmException {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
final String algorithm = hmacAlgorithm.getName();
- Assert.assertNotNull(algorithm);
- Assert.assertFalse(algorithm.isEmpty());
- Assume.assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertNotNull(algorithm);
+ assertFalse(algorithm.isEmpty());
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
Mac.getInstance(algorithm);
}
- @Test
- public void testGetHmacEmptyKey() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testGetHmacEmptyKey(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> HmacUtils.getInitializedMac(hmacAlgorithm, EMPTY_BYTE_ARRAY));
}
- @Test
- public void testGetHmacNullKey() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testGetHmacNullKey(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> HmacUtils.getInitializedMac(hmacAlgorithm, null));
}
- @Test
- public void testHmacFailByteArray() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testHmacFailByteArray(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(STANDARD_PHRASE_BYTES));
}
- @Test
- public void testHmacFailInputStream() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testHmacFailInputStream(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) throws IOException {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new ByteArrayInputStream(STANDARD_PHRASE_BYTES)));
}
- @Test
- public void testHmacFailString() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testHmacFailString(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> new HmacUtils(hmacAlgorithm, (String) null).hmac(STANDARD_PHRASE_STRING));
}
- @Test
- public void testHmacHexFailByteArray() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testHmacHexFailByteArray(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(STANDARD_PHRASE_BYTES));
}
- @Test
- public void testHmacHexFailInputStream() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testHmacHexFailInputStream(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) throws IOException {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new ByteArrayInputStream(STANDARD_PHRASE_BYTES)));
}
- @Test
- public void testHmacHexFailString() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testHmacHexFailString(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
assertThrows(IllegalArgumentException.class, () -> new HmacUtils(hmacAlgorithm, (String) null).hmac(STANDARD_PHRASE_STRING));
}
- @Test
- public void testInitializedMac() {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testInitializedMac(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
final Mac mac = HmacUtils.getInitializedMac(hmacAlgorithm, STANDARD_KEY_BYTES);
final Mac mac2 = HmacUtils.getInitializedMac(hmacAlgorithm.getName(), STANDARD_KEY_BYTES);
- Assert.assertArrayEquals(standardResultBytes, HmacUtils.updateHmac(mac, STANDARD_PHRASE_STRING).doFinal());
- Assert.assertArrayEquals(standardResultBytes, HmacUtils.updateHmac(mac2, STANDARD_PHRASE_STRING).doFinal());
+ assertArrayEquals(standardResultBytes, HmacUtils.updateHmac(mac, STANDARD_PHRASE_STRING).doFinal());
+ assertArrayEquals(standardResultBytes, HmacUtils.updateHmac(mac2, STANDARD_PHRASE_STRING).doFinal());
}
- @Test
- public void testMacByteArary() {
- Assert.assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(STANDARD_PHRASE_BYTES));
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testMacByteArary(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(STANDARD_PHRASE_BYTES));
}
- @Test
- public void testMacHexByteArray() {
- Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_BYTES));
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testMacHexByteArray(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_BYTES));
}
- @Test
- public void testMacHexInputStream() throws IOException {
- Assert.assertEquals(standardResultString,
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testMacHexInputStream(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) throws IOException {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertEquals(standardResultString,
new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(new ByteArrayInputStream(STANDARD_PHRASE_BYTES)));
}
- @Test
- public void testMacHexString() {
- Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_STRING));
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testMacHexString(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_STRING));
}
- @Test
- public void testMacInputStream() throws IOException {
- Assert.assertArrayEquals(standardResultBytes,
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testMacInputStream(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) throws IOException {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertArrayEquals(standardResultBytes,
new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(new ByteArrayInputStream(STANDARD_PHRASE_BYTES)));
}
- @Test
- public void testMacString() {
- Assert.assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(STANDARD_PHRASE_STRING));
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testMacString(HmacAlgorithms hmacAlgorithm, byte[] standardResultBytes, String standardResultString) {
+ assumeTrue(HmacUtils.isAvailable(hmacAlgorithm));
+ assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(STANDARD_PHRASE_STRING));
}
}
diff --git a/src/test/java/org/apache/commons/codec/digest/HmacUtilsTest.java b/src/test/java/org/apache/commons/codec/digest/HmacUtilsTest.java
index 4808e12..d802a97 100644
--- a/src/test/java/org/apache/commons/codec/digest/HmacUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/HmacUtilsTest.java
@@ -16,9 +16,6 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -27,8 +24,9 @@
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.binary.StringUtils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests HmacUtils methods.
@@ -45,15 +43,15 @@
@SuppressWarnings("deprecation") // most of the static methods are deprecated
@Test
public void testGetHMac() {
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
- HmacUtils.getHmacMd5(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
- HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
- HmacUtils.getHmacSha256(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
- HmacUtils.getHmacSha384(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
+ HmacUtils.getHmacMd5(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
+ HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
+ HmacUtils.getHmacSha256(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
+ HmacUtils.getHmacSha384(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
HmacUtils.getHmacSha512(HmacAlgorithmsTest.STANDARD_KEY_BYTES).doFinal(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
}
@@ -116,9 +114,9 @@
public void testInitializedMac() {
final Mac md5Mac = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, HmacAlgorithmsTest.STANDARD_KEY_BYTES);
final Mac md5Mac2 = HmacUtils.getInitializedMac("HmacMD5", HmacAlgorithmsTest.STANDARD_KEY_BYTES);
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac, HmacAlgorithmsTest.STANDARD_PHRASE_STRING)
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac, HmacAlgorithmsTest.STANDARD_PHRASE_STRING)
.doFinal());
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac2, HmacAlgorithmsTest.STANDARD_PHRASE_STRING)
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac2, HmacAlgorithmsTest.STANDARD_PHRASE_STRING)
.doFinal());
}
@@ -140,16 +138,16 @@
@SuppressWarnings("deprecation") // most of the static methods are deprecated
@Test
public void testMd5HMac() throws IOException {
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
HmacUtils.hmacMd5(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
HmacUtils.hmacMd5(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES,
HmacUtils.hmacMd5(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING, HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING, HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
+ assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING,
HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING,
HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
}
@@ -173,17 +171,17 @@
@SuppressWarnings("deprecation") // most of the static methods are deprecated
@Test
public void testSha1HMac() throws IOException {
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
HmacUtils.hmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
HmacUtils.hmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_BYTES,
HmacUtils.hmacSha1(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING,
HmacUtils.hmacSha1Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING,
HmacUtils.hmacSha1Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING,
HmacUtils.hmacSha1Hex(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
}
@@ -196,17 +194,17 @@
@SuppressWarnings("deprecation") // most of the static methods are deprecated
@Test
public void testSha256HMac() throws IOException {
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
HmacUtils.hmacSha256(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
HmacUtils.hmacSha256(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_BYTES,
HmacUtils.hmacSha256(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_STRING,
HmacUtils.hmacSha256Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_STRING,
HmacUtils.hmacSha256Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA256_RESULT_STRING,
HmacUtils.hmacSha256Hex(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
}
@@ -219,17 +217,17 @@
@SuppressWarnings("deprecation") // most of the static methods are deprecated
@Test
public void testSha384HMac() throws IOException {
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
HmacUtils.hmacSha384(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
HmacUtils.hmacSha384(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_BYTES,
HmacUtils.hmacSha384(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_STRING,
HmacUtils.hmacSha384Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_STRING,
HmacUtils.hmacSha384Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA384_RESULT_STRING,
HmacUtils.hmacSha384Hex(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
}
@@ -242,17 +240,17 @@
@SuppressWarnings("deprecation") // most of the static methods are deprecated
@Test
public void testSha512HMac() throws IOException {
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
HmacUtils.hmacSha512(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
HmacUtils.hmacSha512(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
+ assertArrayEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_BYTES,
HmacUtils.hmacSha512(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_STRING,
HmacUtils.hmacSha512Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_STRING,
HmacUtils.hmacSha512Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)));
- Assert.assertEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_STRING,
+ assertEquals(HmacAlgorithmsTest.STANDARD_SHA512_RESULT_STRING,
HmacUtils.hmacSha512Hex(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING));
}
diff --git a/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java
index 8fa4c18..63ac164 100644
--- a/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java
@@ -16,16 +16,13 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ThreadLocalRandom;
+import static org.junit.jupiter.api.Assertions.*;
+
public class Md5CryptTest {
@Test
diff --git a/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java b/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java
index 4d1f576..ca1aab2 100644
--- a/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java
@@ -16,6 +16,12 @@
*/
package org.apache.commons.codec.digest;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@@ -29,25 +35,17 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Tests {@link MessageDigestAlgorithms}.
*
* @since 1.11
*/
-@RunWith(Parameterized.class)
public class MessageDigestAlgorithmsTest {
- @BeforeClass
+ @BeforeAll
public static void checkValues() throws Exception {
final Field [] fields = MessageDigestAlgorithms.class.getDeclaredFields();
boolean ok = true;
@@ -69,10 +67,10 @@
}
}
if (!ok) {
- Assert.fail("One or more entries are missing from the MessageDigestAlgorithms.values() array");
+ fail("One or more entries are missing from the MessageDigestAlgorithms.values() array");
}
if (psf != MessageDigestAlgorithms.values().length) {
- Assert.fail("One or more unexpected entries found in the MessageDigestAlgorithms.values() array");
+ fail("One or more unexpected entries found in the MessageDigestAlgorithms.values() array");
}
}
@@ -85,20 +83,13 @@
return false;
}
- @Parameters(name = "{0}")
- public static Object[] data() {
+ public static String[] data() {
return MessageDigestAlgorithms.values();
}
private DigestUtilsTest digestUtilsTest;
- private final String messageDigestAlgorithm;
-
- public MessageDigestAlgorithmsTest(final String messageDigestAlgorithm) {
- this.messageDigestAlgorithm = messageDigestAlgorithm;
- }
-
- private byte[] digestTestData() {
+ private byte[] digestTestData(String messageDigestAlgorithm) {
return DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData());
}
@@ -118,98 +109,109 @@
return digestUtilsTest.getTestRandomAccessFile();
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
digestUtilsTest = new DigestUtilsTest();
digestUtilsTest.setUp();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
digestUtilsTest.tearDown();
digestUtilsTest = null;
}
- @Test
- public void testAlgorithm() throws NoSuchAlgorithmException {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testAlgorithm(String messageDigestAlgorithm) throws NoSuchAlgorithmException {
final String algorithm = messageDigestAlgorithm;
- Assert.assertNotNull(algorithm);
- Assert.assertFalse(algorithm.isEmpty());
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ assertNotNull(algorithm);
+ assertFalse(algorithm.isEmpty());
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
MessageDigest.getInstance(algorithm);
}
- @Test
- public void testDigestByteArray() {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
- Assert.assertArrayEquals(digestTestData(),
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testDigestByteArray(String messageDigestAlgorithm) {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestData()));
- Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData()));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData()));
}
- @Test
- public void testDigestByteBuffer() {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
- Assert.assertArrayEquals(digestTestData(),
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testDigestByteBuffer(String messageDigestAlgorithm) {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), ByteBuffer.wrap(getTestData())));
- Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),ByteBuffer.wrap(getTestData())));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),ByteBuffer.wrap(getTestData())));
}
- @Test
- public void testDigestFile() throws IOException {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
- Assert.assertArrayEquals(digestTestData(),
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testDigestFile(String messageDigestAlgorithm) throws IOException {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestFile()));
- Assert.assertArrayEquals(digestTestData(),
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestFile()));
}
- @Test
- public void testDigestInputStream() throws IOException {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
- Assert.assertArrayEquals(digestTestData(),
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testDigestInputStream(String messageDigestAlgorithm) throws IOException {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), new ByteArrayInputStream(getTestData())));
- Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),new ByteArrayInputStream(getTestData())));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),new ByteArrayInputStream(getTestData())));
}
- private void testDigestPath(final OpenOption... options) throws IOException {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
- Assert.assertArrayEquals(digestTestData(),
+ @ParameterizedTest
+ @MethodSource("data")
+ private void testDigestPath(String messageDigestAlgorithm, final OpenOption... options) throws IOException {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestPath(), options));
- Assert.assertArrayEquals(digestTestData(),
+ assertArrayEquals(digestTestData(messageDigestAlgorithm),
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestPath(), options));
}
- @Test
- public void testDigestPathOpenOptionsEmpty() throws IOException {
- testDigestPath();
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testDigestPathOpenOptionsEmpty(String messageDigestAlgorithm) throws IOException {
+ testDigestPath(messageDigestAlgorithm);
}
- @Test
- public void testDigestPathStandardOpenOptionRead() throws IOException {
- testDigestPath(StandardOpenOption.READ);
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testDigestPathStandardOpenOptionRead(String messageDigestAlgorithm) throws IOException {
+ testDigestPath(messageDigestAlgorithm, StandardOpenOption.READ);
}
- @Test
- public void testGetMessageDigest() {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testGetMessageDigest(String messageDigestAlgorithm) {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
final MessageDigest messageDigest = DigestUtils.getDigest(messageDigestAlgorithm);
- Assert.assertEquals(messageDigestAlgorithm, messageDigest.getAlgorithm());
+ assertEquals(messageDigestAlgorithm, messageDigest.getAlgorithm());
}
- @Test
- public void testNonBlockingDigestRandomAccessFile() throws IOException {
- Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testNonBlockingDigestRandomAccessFile(String messageDigestAlgorithm) throws IOException {
+ assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
- final byte[] expected = digestTestData();
+ final byte[] expected = digestTestData(messageDigestAlgorithm);
- Assert.assertArrayEquals(expected,
+ assertArrayEquals(expected,
DigestUtils.digest(
DigestUtils.getDigest(messageDigestAlgorithm), getTestRandomAccessFile()
)
);
getTestRandomAccessFile().seek(0);
- Assert.assertArrayEquals(expected,
+ assertArrayEquals(expected,
DigestUtils.digest(
DigestUtils.getDigest(messageDigestAlgorithm), getTestRandomAccessFile()
)
diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java b/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java
index 3dc7dfa..ff6079a 100644
--- a/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java
@@ -17,8 +17,11 @@
package org.apache.commons.codec.digest;
-import org.junit.Assert;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
public class MurmurHash2Test {
@@ -83,7 +86,7 @@
for (int i = 0; i < input.length; i++) {
final int hash = MurmurHash2.hash32(input[i], input[i].length, 0x71b4954d);
if (hash != results32_seed[i]) {
- Assert.fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
+ fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
results32_seed[i]));
}
}
@@ -94,7 +97,7 @@
for (int i = 0; i < input.length; i++) {
final int hash = MurmurHash2.hash32(input[i], input[i].length);
if (hash != results32_standard[i]) {
- Assert.fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
+ fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
results32_standard[i]));
}
}
@@ -103,13 +106,13 @@
@Test
public void testHash32String() {
final int hash = MurmurHash2.hash32(text);
- Assert.assertEquals(0xb3bf597e, hash);
+ assertEquals(0xb3bf597e, hash);
}
@Test
public void testHash32StringIntInt() {
final int hash = MurmurHash2.hash32(text, 2, text.length() - 4);
- Assert.assertEquals(0x4d666d90, hash);
+ assertEquals(0x4d666d90, hash);
}
@Test
@@ -117,7 +120,7 @@
for (int i = 0; i < input.length; i++) {
final long hash = MurmurHash2.hash64(input[i], input[i].length, 0x344d1f5c);
if (hash != results64_seed[i]) {
- Assert.fail(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
+ fail(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
results64_seed[i]));
}
}
@@ -128,7 +131,7 @@
for (int i = 0; i < input.length; i++) {
final long hash = MurmurHash2.hash64(input[i], input[i].length);
if (hash != results64_standard[i]) {
- Assert.fail(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
+ fail(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
results64_standard[i]));
}
}
@@ -137,12 +140,12 @@
@Test
public void testHash64String() {
final long hash = MurmurHash2.hash64(text);
- Assert.assertEquals(0x0920e0c1b7eeb261L, hash);
+ assertEquals(0x0920e0c1b7eeb261L, hash);
}
@Test
public void testHash64StringIntInt() {
final long hash = MurmurHash2.hash64(text, 2, text.length() - 4);
- Assert.assertEquals(0xa8b33145194985a2L, hash);
+ assertEquals(0xa8b33145194985a2L, hash);
}
}
diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
index fb55505..3865f1f 100644
--- a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
@@ -17,9 +17,6 @@
package org.apache.commons.codec.digest;
-import org.junit.Assert;
-import org.junit.Assume;
-
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
@@ -27,7 +24,10 @@
import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.codec.digest.MurmurHash3.IncrementalHash32;
import org.apache.commons.codec.digest.MurmurHash3.IncrementalHash32x86;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Test for {@link MurmurHash3}.
@@ -107,7 +107,7 @@
for (final long j : data) {
buffer.putLong(0, i);
buffer.putLong(MurmurHash3.LONG_BYTES, j);
- Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j));
+ assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j));
}
}
}
@@ -129,7 +129,7 @@
for (final long j : data) {
buffer.putLong(0, i);
buffer.putLong(MurmurHash3.LONG_BYTES, j);
- Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j, seed));
+ assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j, seed));
}
}
}
@@ -149,7 +149,7 @@
final long[] data = createLongTestData();
for (final long i : data) {
buffer.putLong(0, i);
- Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i));
+ assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i));
}
}
@@ -168,7 +168,7 @@
final long[] data = createLongTestData();
for (final long i : data) {
buffer.putLong(0, i);
- Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, seed));
+ assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, seed));
}
}
@@ -200,7 +200,7 @@
@Test
public void testHash32() {
// mmh3.hash(bytes, 104729)
- Assert.assertEquals(1905657630, MurmurHash3.hash32(RANDOM_BYTES));
+ assertEquals(1905657630, MurmurHash3.hash32(RANDOM_BYTES));
// Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to
// 15 bytes remaining.
@@ -215,9 +215,9 @@
// Known bug: Incorrect result for non modulus of 4 byte arrays if there are
// negative bytes
if (i % 4 == 0 || !negativeBytes(bytes, (i / 4) * 4, i % 4)) {
- Assert.assertEquals(answers[i], MurmurHash3.hash32(bytes));
+ assertEquals(answers[i], MurmurHash3.hash32(bytes));
} else {
- Assert.assertNotEquals(answers[i], MurmurHash3.hash32(bytes));
+ assertNotEquals(answers[i], MurmurHash3.hash32(bytes));
}
}
}
@@ -232,7 +232,7 @@
@Test
public void testHash32WithLength() {
// mmh3.hash(bytes, 104729)
- Assert.assertEquals(1905657630, MurmurHash3.hash32(RANDOM_BYTES, RANDOM_BYTES.length));
+ assertEquals(1905657630, MurmurHash3.hash32(RANDOM_BYTES, RANDOM_BYTES.length));
// Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to
// 15 bytes remaining.
@@ -246,9 +246,9 @@
// Known bug: Incorrect result for non modulus of 4 byte arrays if there are
// negative bytes
if (i % 4 == 0 || !negativeBytes(RANDOM_BYTES, (i / 4) * 4, i % 4)) {
- Assert.assertEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i));
+ assertEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i));
} else {
- Assert.assertNotEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i));
+ assertNotEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i));
}
}
}
@@ -264,7 +264,7 @@
public void testHash32WithLengthAndSeed() {
final int seed = -42;
// mmh3.hash(bytes, -42)
- Assert.assertEquals(1693958011, MurmurHash3.hash32(RANDOM_BYTES, RANDOM_BYTES.length, seed));
+ assertEquals(1693958011, MurmurHash3.hash32(RANDOM_BYTES, RANDOM_BYTES.length, seed));
// Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to
// 15 bytes remaining.
@@ -278,9 +278,9 @@
// Known bug: Incorrect result for non modulus of 4 byte arrays if there are
// negative bytes
if (i % 4 == 0 || !negativeBytes(RANDOM_BYTES, (i / 4) * 4, i % 4)) {
- Assert.assertEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i, seed));
+ assertEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i, seed));
} else {
- Assert.assertNotEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i, seed));
+ assertNotEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, i, seed));
}
}
}
@@ -309,9 +309,9 @@
// Known bug: Incorrect result for non modulus of 4 byte arrays if there are
// negative bytes
if (i % 4 == 0 || !negativeBytes(RANDOM_BYTES, offset + (i / 4) * 4, i % 4)) {
- Assert.assertEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, offset, i, seed));
+ assertEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, offset, i, seed));
} else {
- Assert.assertNotEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, offset, i, seed));
+ assertNotEquals(answers[i], MurmurHash3.hash32(RANDOM_BYTES, offset, i, seed));
}
}
}
@@ -360,7 +360,7 @@
final byte[] bytes = StringUtils.getBytesUtf8(text);
final int h1 = MurmurHash3.hash32(bytes, 0, bytes.length, seed);
final int h2 = MurmurHash3.hash32(text);
- Assert.assertEquals(h1, h2);
+ assertEquals(h1, h2);
}
}
@@ -378,12 +378,12 @@
// mmh3.hash(np.uint8([-1, 0]))
// mmh3.hash(np.uint8([-1, 0, 0]))
// mmh3.hash(np.uint8([0, -1, 0]))
- Assert.assertNotEquals(-43192051, MurmurHash3.hash32(new byte[] {-1}, 0, 1, 0));
- Assert.assertNotEquals(-582037868, MurmurHash3.hash32(new byte[] {0, -1}, 0, 2, 0));
- Assert.assertNotEquals(922088087, MurmurHash3.hash32(new byte[] {0, 0, -1}, 0, 3, 0));
- Assert.assertNotEquals(-1309567588, MurmurHash3.hash32(new byte[] {-1, 0}, 0, 2, 0));
- Assert.assertNotEquals(-363779670, MurmurHash3.hash32(new byte[] {-1, 0, 0}, 0, 3, 0));
- Assert.assertNotEquals(-225068062, MurmurHash3.hash32(new byte[] {0, -1, 0}, 0, 3, 0));
+ assertNotEquals(-43192051, MurmurHash3.hash32(new byte[] {-1}, 0, 1, 0));
+ assertNotEquals(-582037868, MurmurHash3.hash32(new byte[] {0, -1}, 0, 2, 0));
+ assertNotEquals(922088087, MurmurHash3.hash32(new byte[] {0, 0, -1}, 0, 3, 0));
+ assertNotEquals(-1309567588, MurmurHash3.hash32(new byte[] {-1, 0}, 0, 2, 0));
+ assertNotEquals(-363779670, MurmurHash3.hash32(new byte[] {-1, 0, 0}, 0, 3, 0));
+ assertNotEquals(-225068062, MurmurHash3.hash32(new byte[] {0, -1, 0}, 0, 3, 0));
}
/**
@@ -394,11 +394,11 @@
* @see <a href="https://pypi.org/project/mmh3/">mmh3</a>
*/
@Test
- public void testhash32x86() {
+ public void testHash32x86() {
// Note: Default seed is zero.
// mmh3.hash(bytes, 0)
- Assert.assertEquals(1546271276, MurmurHash3.hash32x86(RANDOM_BYTES));
+ assertEquals(1546271276, MurmurHash3.hash32x86(RANDOM_BYTES));
// Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to
// 15 bytes remaining.
@@ -410,7 +410,7 @@
905810751, 1044578220, -1758486689, -491393913, 839836946, -435014415, 2044851178,};
for (int i = 0; i < answers.length; i++) {
final byte[] bytes = Arrays.copyOf(RANDOM_BYTES, i);
- Assert.assertEquals(answers[i], MurmurHash3.hash32x86(bytes));
+ assertEquals(answers[i], MurmurHash3.hash32x86(bytes));
}
}
@@ -431,7 +431,7 @@
-1985866226, -678669121, -2123325690, -253319081, 46181235, 656058278, 1401175653, 1750113912, -1567219725,
2032742772, -2024269989, -305340794, 1161737942, -661265418, 172838872, -650122718, -1934812417,};
for (int i = 0; i < answers.length; i++) {
- Assert.assertEquals(answers[i], MurmurHash3.hash32x86(RANDOM_BYTES, offset, i, seed));
+ assertEquals(answers[i], MurmurHash3.hash32x86(RANDOM_BYTES, offset, i, seed));
}
}
@@ -443,12 +443,12 @@
public void testHash32x86WithTrailingNegativeSignedBytes() {
// Data as above for testing MurmurHash3.hash32(byte[], int, int, int).
// This test uses assertEquals().
- Assert.assertEquals(-43192051, MurmurHash3.hash32x86(new byte[] {-1}, 0, 1, 0));
- Assert.assertEquals(-582037868, MurmurHash3.hash32x86(new byte[] {0, -1}, 0, 2, 0));
- Assert.assertEquals(922088087, MurmurHash3.hash32x86(new byte[] {0, 0, -1}, 0, 3, 0));
- Assert.assertEquals(-1309567588, MurmurHash3.hash32x86(new byte[] {-1, 0}, 0, 2, 0));
- Assert.assertEquals(-363779670, MurmurHash3.hash32x86(new byte[] {-1, 0, 0}, 0, 3, 0));
- Assert.assertEquals(-225068062, MurmurHash3.hash32x86(new byte[] {0, -1, 0}, 0, 3, 0));
+ assertEquals(-43192051, MurmurHash3.hash32x86(new byte[] {-1}, 0, 1, 0));
+ assertEquals(-582037868, MurmurHash3.hash32x86(new byte[] {0, -1}, 0, 2, 0));
+ assertEquals(922088087, MurmurHash3.hash32x86(new byte[] {0, 0, -1}, 0, 3, 0));
+ assertEquals(-1309567588, MurmurHash3.hash32x86(new byte[] {-1, 0}, 0, 2, 0));
+ assertEquals(-363779670, MurmurHash3.hash32x86(new byte[] {-1, 0, 0}, 0, 3, 0));
+ assertEquals(-225068062, MurmurHash3.hash32x86(new byte[] {0, -1, 0}, 0, 3, 0));
}
/**
@@ -459,7 +459,7 @@
public void testHash64() {
final byte[] origin = StringUtils.getBytesUtf8(TEST_HASH64);
final long hash = MurmurHash3.hash64(origin);
- Assert.assertEquals(5785358552565094607L, hash);
+ assertEquals(5785358552565094607L, hash);
}
/**
@@ -473,7 +473,7 @@
Arrays.fill(originOffset, (byte) 123);
System.arraycopy(origin, 0, originOffset, 150, origin.length);
final long hash = MurmurHash3.hash64(originOffset, 150, origin.length);
- Assert.assertEquals(5785358552565094607L, hash);
+ assertEquals(5785358552565094607L, hash);
}
/**
@@ -500,11 +500,11 @@
final int in = (int) (ln >>> 3);
final short sn = (short) (ln >>> 5);
shortBuffer.putShort(0, sn);
- Assert.assertEquals(MurmurHash3.hash64(shortBytes, offset, shortBytes.length, seed), MurmurHash3.hash64(sn));
+ assertEquals(MurmurHash3.hash64(shortBytes, offset, shortBytes.length, seed), MurmurHash3.hash64(sn));
intBuffer.putInt(0, in);
- Assert.assertEquals(MurmurHash3.hash64(intBytes, offset, intBytes.length, seed), MurmurHash3.hash64(in));
+ assertEquals(MurmurHash3.hash64(intBytes, offset, intBytes.length, seed), MurmurHash3.hash64(in));
longBuffer.putLong(0, ln);
- Assert.assertEquals(MurmurHash3.hash64(longBytes, offset, longBytes.length, seed), MurmurHash3.hash64(ln));
+ assertEquals(MurmurHash3.hash64(longBytes, offset, longBytes.length, seed), MurmurHash3.hash64(ln));
}
}
@@ -521,8 +521,8 @@
final byte[] bytes = Arrays.copyOf(RANDOM_BYTES, i);
final long h1 = MurmurHash3.hash64(bytes);
final long[] hash = MurmurHash3.hash128(bytes);
- Assert.assertNotEquals("Did not expect hash64 to match upper bits of hash128", hash[0], h1);
- Assert.assertNotEquals("Did not expect hash64 to match lower bits of hash128", hash[1], h1);
+ assertNotEquals(hash[0], h1, "Did not expect hash64 to match upper bits of hash128");
+ assertNotEquals(hash[1], h1, "Did not expect hash64 to match lower bits of hash128");
}
}
@@ -536,7 +536,7 @@
@Test
public void testHash128() {
// mmh3.hash64(bytes, 104729)
- Assert.assertArrayEquals(new long[] {-5614308156300707300L, -4165733009867452172L},
+ assertArrayEquals(new long[] {-5614308156300707300L, -4165733009867452172L},
MurmurHash3.hash128(RANDOM_BYTES));
// Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to
@@ -562,7 +562,7 @@
{-4534351735605790331L, -4530801663887858236L}, {-7886946241830957955L, -6261339648449285315L},};
for (int i = 0; i < answers.length; i++) {
final byte[] bytes = Arrays.copyOf(RANDOM_BYTES, i);
- Assert.assertArrayEquals(answers[i], MurmurHash3.hash128(bytes));
+ assertArrayEquals(answers[i], MurmurHash3.hash128(bytes));
}
}
@@ -601,7 +601,7 @@
{-4610341636137642517L, -6694266039505142069L}, {-758896383254029789L, 4050360662271552727L},
{-6123628195475753507L, 4283875822581966645L},};
for (int i = 0; i < answers.length; i++) {
- Assert.assertArrayEquals("Length: " + i, answers[i], MurmurHash3.hash128(RANDOM_BYTES, offset, i, seed));
+ assertArrayEquals(answers[i], MurmurHash3.hash128(RANDOM_BYTES, offset, i, seed), "Length: " + i);
}
}
@@ -638,7 +638,7 @@
{4881732293467626532L, 2617335658565007304L}, {-5722863941703478257L, -5424475653939430258L},
{-3703319768293496315L, -2124426428486426443L},};
for (int i = 0; i < answers.length; i++) {
- Assert.assertArrayEquals("Length: " + i, answers[i], MurmurHash3.hash128(RANDOM_BYTES, offset, i, seed));
+ assertArrayEquals(answers[i], MurmurHash3.hash128(RANDOM_BYTES, offset, i, seed), "Length: " + i);
}
}
@@ -669,7 +669,7 @@
final byte[] bytes = StringUtils.getBytesUtf8(text);
final long[] h1 = MurmurHash3.hash128(bytes, 0, bytes.length, seed);
final long[] h2 = MurmurHash3.hash128(text);
- Assert.assertArrayEquals(h1, h2);
+ assertArrayEquals(h1, h2);
}
}
@@ -685,7 +685,7 @@
// Note: Default seed is zero.
// mmh3.hash64(bytes, 0)
- Assert.assertArrayEquals(new long[] {1972113670104592209L, 5171809317673151911L},
+ assertArrayEquals(new long[] {1972113670104592209L, 5171809317673151911L},
MurmurHash3.hash128x64(RANDOM_BYTES));
// Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to
@@ -710,7 +710,7 @@
{-3842593823306330815L, 3805147088291453755L}, {4030161393619149616L, -2813603781312455238L},};
for (int i = 0; i < answers.length; i++) {
final byte[] bytes = Arrays.copyOf(RANDOM_BYTES, i);
- Assert.assertArrayEquals(answers[i], MurmurHash3.hash128x64(bytes));
+ assertArrayEquals(answers[i], MurmurHash3.hash128x64(bytes));
}
}
@@ -749,7 +749,7 @@
{-4610341636137642517L, -6694266039505142069L}, {-758896383254029789L, 4050360662271552727L},
{-6123628195475753507L, 4283875822581966645L},};
for (int i = 0; i < answers.length; i++) {
- Assert.assertArrayEquals("Length: " + i, answers[i], MurmurHash3.hash128x64(RANDOM_BYTES, offset, i, seed));
+ assertArrayEquals(answers[i], MurmurHash3.hash128x64(RANDOM_BYTES, offset, i, seed), "Length: " + i);
}
}
@@ -791,7 +791,7 @@
{-8580307083590783934L, 3634449965473715778L}, {6705664584730187559L, 5192304951463791556L},
{-6426410954037604142L, -1579122709247558101L},};
for (int i = 0; i < answers.length; i++) {
- Assert.assertArrayEquals("Length: " + i, answers[i], MurmurHash3.hash128x64(RANDOM_BYTES, offset, i, seed));
+ assertArrayEquals(answers[i], MurmurHash3.hash128x64(RANDOM_BYTES, offset, i, seed), "Length: " + i);
}
}
@@ -848,8 +848,8 @@
inc.add(bytes, offset, block);
offset += block;
final int h2 = inc.end();
- Assert.assertEquals("Hashes differ", h1, h2);
- Assert.assertEquals("Hashes differ after no additional data", h1, inc.end());
+ assertEquals(h1, h2, "Hashes differ");
+ assertEquals(h1, inc.end(), "Hashes differ after no additional data");
}
}
@@ -906,8 +906,8 @@
inc.add(bytes, offset, block);
offset += block;
final int h2 = inc.end();
- Assert.assertEquals("Hashes differ", h1, h2);
- Assert.assertEquals("Hashes differ after no additional data", h1, inc.end());
+ assertEquals(h1, h2, "Hashes differ");
+ assertEquals(h1, inc.end(), "Hashes differ after no additional data");
}
}
@@ -943,7 +943,7 @@
// as some VMs cannot allocate maximum length arrays.
final int unprocessedSize = 3;
final int hugeLength = Integer.MAX_VALUE - 2;
- Assert.assertTrue("This should overflow to negative", unprocessedSize + hugeLength < 4);
+ assertTrue(unprocessedSize + hugeLength < 4, "This should overflow to negative");
// Check the test can be run
byte[] bytes = null;
@@ -953,7 +953,7 @@
// Some VMs cannot allocate an array this large.
// Some test environments may not have enough available memory for this.
}
- Assume.assumeTrue("Cannot allocate array of length " + hugeLength, bytes != null);
+ assumeTrue(bytes != null, "Cannot allocate array of length " + hugeLength);
final IncrementalHash32x86 inc = new IncrementalHash32x86();
inc.start(0);
diff --git a/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32CTest.java b/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32CTest.java
index 87add04..c088a0e 100644
--- a/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32CTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32CTest.java
@@ -16,10 +16,11 @@
*/
package org.apache.commons.codec.digest;
+import org.junit.jupiter.api.Test;
+
import java.util.Arrays;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test class for PureJavaCrc32C.
@@ -65,7 +66,7 @@
crc.reset();
crc.update(data, 0, data.length);
final int actual = (int) crc.getValue();
- Assert.assertEquals(Integer.toHexString(expected), Integer.toHexString(actual));
+ assertEquals(Integer.toHexString(expected), Integer.toHexString(actual));
}
}
diff --git a/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32Test.java b/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32Test.java
index 58505de..c0ca7f3 100644
--- a/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/PureJavaCrc32Test.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.codec.digest;
+import org.junit.jupiter.api.Test;
+
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
@@ -28,8 +30,8 @@
import java.util.zip.CRC32;
import java.util.zip.Checksum;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* Unit test to verify that the pure-Java CRC32 algorithm gives
@@ -100,7 +102,7 @@
}
private void checkSame() {
- Assert.assertEquals(theirs.getValue(), ours.getValue());
+ assertEquals(theirs.getValue(), ours.getValue());
}
/**
diff --git a/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java
index 0d1d0bb..267ad47 100644
--- a/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java
@@ -16,15 +16,13 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
public class Sha256CryptTest {
diff --git a/src/test/java/org/apache/commons/codec/digest/Sha2CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Sha2CryptTest.java
index 8a258df..6e6ab7a 100644
--- a/src/test/java/org/apache/commons/codec/digest/Sha2CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Sha2CryptTest.java
@@ -17,9 +17,9 @@
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertNotNull;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class Sha2CryptTest {
diff --git a/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java
index b29c4c5..7ecb3ae 100644
--- a/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java
@@ -16,16 +16,14 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
-import org.junit.Ignore;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
public class Sha512CryptTest {
@@ -69,7 +67,7 @@
assertThrows(NullPointerException.class, () -> Sha2Crypt.sha512Crypt((byte[]) null));
}
- @Ignore
+ @Disabled
public void testSha512CryptNullSalt() {
// cannot be tested as sha512Crypt() with all params is private and
// all public methods check for salt==null.
diff --git a/src/test/java/org/apache/commons/codec/digest/UnixCryptTest.java b/src/test/java/org/apache/commons/codec/digest/UnixCryptTest.java
index 77cf939..ea2ccbe 100644
--- a/src/test/java/org/apache/commons/codec/digest/UnixCryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/UnixCryptTest.java
@@ -16,15 +16,11 @@
*/
package org.apache.commons.codec.digest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
public class UnixCryptTest {
diff --git a/src/test/java/org/apache/commons/codec/digest/XXHash32OverflowTest.java b/src/test/java/org/apache/commons/codec/digest/XXHash32OverflowTest.java
index 889785e..bc016c3 100644
--- a/src/test/java/org/apache/commons/codec/digest/XXHash32OverflowTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/XXHash32OverflowTest.java
@@ -16,9 +16,11 @@
*/
package org.apache.commons.codec.digest;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class XXHash32OverflowTest {
@@ -36,7 +38,7 @@
final int bufferSize = 16;
final int unprocessedSize = bufferSize - 1;
final int hugeLength = Integer.MAX_VALUE - (unprocessedSize - 1);
- Assert.assertTrue("This should overflow to negative", unprocessedSize + hugeLength < bufferSize);
+ assertTrue(unprocessedSize + hugeLength < bufferSize, "This should overflow to negative");
// Check the test can be run
byte[] bytes = null;
@@ -46,7 +48,7 @@
// Some VMs cannot allocate an array this large.
// Some test environments may not have enough available memory for this.
}
- Assume.assumeTrue("Cannot allocate array of length " + hugeLength, bytes != null);
+ assumeTrue(bytes != null, "Cannot allocate array of length " + hugeLength);
final XXHash32 inc = new XXHash32();
// Add bytes that should be unprocessed
diff --git a/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java b/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java
index e2f9b95..4b97e02 100644
--- a/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/XXHash32Test.java
@@ -16,6 +16,10 @@
*/
package org.apache.commons.codec.digest;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -25,22 +29,16 @@
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
-import java.util.Arrays;
-import java.util.Collection;
+import java.util.stream.Stream;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-import org.junit.runner.RunWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-@RunWith(Parameterized.class)
public class XXHash32Test {
- private final File file;
- private final String expectedChecksum;
+ private File file;
+ private String expectedChecksum;
- public XXHash32Test(final String path, final String c) throws IOException {
+ public void initData(final String path, final String c) throws IOException {
final URL url = XXHash32Test.class.getClassLoader().getResource(path);
if (url == null) {
throw new FileNotFoundException("couldn't find " + path);
@@ -55,29 +53,32 @@
expectedChecksum = c;
}
- @Parameters
- public static Collection<Object[]> factory() {
- return Arrays.asList(new Object[][] {
+ public static Stream<Arguments> data() {
+ return Stream.of(
// reference checksums created with xxh32sum
// http://cyan4973.github.io/xxHash/
- { "org/apache/commons/codec/bla.tar", "fbb5c8d1" },
- { "org/apache/commons/codec/bla.tar.xz", "4106a208" },
- { "org/apache/commons/codec/small.bin", "f66c26f8" },
- });
+ Arguments.of( "org/apache/commons/codec/bla.tar", "fbb5c8d1" ),
+ Arguments.of( "org/apache/commons/codec/bla.tar.xz", "4106a208" ),
+ Arguments.of( "org/apache/commons/codec/small.bin", "f66c26f8" )
+ );
}
- @Test
- public void verifyChecksum() throws IOException {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void verifyChecksum(String path, String c) throws IOException {
+ initData(path, c);
final XXHash32 h = new XXHash32();
try (final FileInputStream s = new FileInputStream(file)) {
final byte[] b = toByteArray(s);
h.update(b, 0, b.length);
}
- Assert.assertEquals("checksum for " + file.getName(), expectedChecksum, Long.toHexString(h.getValue()));
+ assertEquals(expectedChecksum, Long.toHexString(h.getValue()), "checksum for " + file.getName());
}
- @Test
- public void verifyIncrementalChecksum() throws IOException {
+ @ParameterizedTest
+ @MethodSource("data")
+ public void verifyIncrementalChecksum(String path, String c) throws IOException {
+ initData(path, c);
final XXHash32 h = new XXHash32();
try (final FileInputStream s = new FileInputStream(file)) {
final byte[] b = toByteArray(s);
@@ -91,7 +92,7 @@
// Check the hash ignores negative length
h.update(b, 0, -1);
}
- Assert.assertEquals("checksum for " + file.getName(), expectedChecksum, Long.toHexString(h.getValue()));
+ assertEquals(expectedChecksum, Long.toHexString(h.getValue()), "checksum for " + file.getName());
}
private static byte[] toByteArray(final InputStream input) throws IOException {
diff --git a/src/test/java/org/apache/commons/codec/language/Caverphone1Test.java b/src/test/java/org/apache/commons/codec/language/Caverphone1Test.java
index 96e5586..d4f120a 100644
--- a/src/test/java/org/apache/commons/codec/language/Caverphone1Test.java
+++ b/src/test/java/org/apache/commons/codec/language/Caverphone1Test.java
@@ -19,8 +19,10 @@
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests Caverphone1.
@@ -75,8 +77,8 @@
@Test
public void testIsCaverphoneEquals() throws EncoderException {
final Caverphone1 caverphone = new Caverphone1();
- Assert.assertFalse("Caverphone encodings should not be equal", caverphone.isEncodeEqual("Peter", "Stevenson"));
- Assert.assertTrue("Caverphone encodings should be equal", caverphone.isEncodeEqual("Peter", "Peady"));
+ assertFalse(caverphone.isEncodeEqual("Peter", "Stevenson"), "Caverphone encodings should not be equal");
+ assertTrue(caverphone.isEncodeEqual("Peter", "Peady"), "Caverphone encodings should be equal");
}
/**
diff --git a/src/test/java/org/apache/commons/codec/language/Caverphone2Test.java b/src/test/java/org/apache/commons/codec/language/Caverphone2Test.java
index 2a57c3f..8803061 100644
--- a/src/test/java/org/apache/commons/codec/language/Caverphone2Test.java
+++ b/src/test/java/org/apache/commons/codec/language/Caverphone2Test.java
@@ -19,8 +19,10 @@
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests Caverphone2.
@@ -337,8 +339,8 @@
@Test
public void testIsCaverphoneEquals() throws EncoderException {
final Caverphone2 caverphone = new Caverphone2();
- Assert.assertFalse("Caverphone encodings should not be equal", caverphone.isEncodeEqual("Peter", "Stevenson"));
- Assert.assertTrue("Caverphone encodings should be equal", caverphone.isEncodeEqual("Peter", "Peady"));
+ assertFalse(caverphone.isEncodeEqual("Peter", "Stevenson"), "Caverphone encodings should not be equal");
+ assertTrue(caverphone.isEncodeEqual("Peter", "Peady"), "Caverphone encodings should be equal");
}
@Test
diff --git a/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java b/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java
index fcae367..66293b8 100644
--- a/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java
+++ b/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java
@@ -23,9 +23,11 @@
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+import org.opentest4j.AssertionFailedError;
+
+import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -72,7 +74,7 @@
".*[CKQ]X.*", // X after C,K,Q
};
- @AfterClass
+ @AfterAll
// Check that all possible input sequence conditions are represented
public static void finishTests() {
int errors = 0;
@@ -82,7 +84,7 @@
errors++;
}
}
- Assert.assertEquals("Not expecting any missing test cases", 0, errors);
+ assertEquals(0, errors, "Not expecting any missing test cases");
}
@Override
@@ -101,7 +103,7 @@
@Test
// Ensure that override still allows tests to work
public void testCanFail() {
- assertThrows(org.junit.ComparisonFailure.class, () -> this.checkEncoding("/", "Fehler"));
+ assertThrows(AssertionFailedError.class, () -> this.checkEncoding("/", "Fehler"));
}
@Test
@@ -222,7 +224,7 @@
//@formatter:on
for (final String[] element : data) {
final boolean encodeEqual = this.getStringEncoder().isEncodeEqual(element[1], element[0]);
- Assert.assertTrue(element[1] + " != " + element[0], encodeEqual);
+ assertTrue(encodeEqual, element[1] + " != " + element[0]);
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/DaitchMokotoffSoundexTest.java b/src/test/java/org/apache/commons/codec/language/DaitchMokotoffSoundexTest.java
index ebf6012..7f34818 100644
--- a/src/test/java/org/apache/commons/codec/language/DaitchMokotoffSoundexTest.java
+++ b/src/test/java/org/apache/commons/codec/language/DaitchMokotoffSoundexTest.java
@@ -18,8 +18,9 @@
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests {@link DaitchMokotoffSoundex}.
@@ -46,11 +47,11 @@
@Test
public void testAccentedCharacterFolding() {
- Assert.assertEquals("294795", soundex("Straßburg"));
- Assert.assertEquals("294795", soundex("Strasburg"));
+ assertEquals("294795", soundex("Straßburg"));
+ assertEquals("294795", soundex("Strasburg"));
- Assert.assertEquals("095600", soundex("Éregon"));
- Assert.assertEquals("095600", soundex("Eregon"));
+ assertEquals("095600", soundex("Éregon"));
+ assertEquals("095600", soundex("Eregon"));
}
@Test
@@ -59,25 +60,25 @@
// A-KS-S-O-L
// 0-54-4---8 -> wrong
// 0-54-----8 -> correct
- Assert.assertEquals("054800", soundex("AKSSOL"));
+ assertEquals("054800", soundex("AKSSOL"));
// GERSCHFELD
// G-E-RS-CH-F-E-L-D
// 5--4/94-5/4-7-8-3 -> wrong
// 5--4/94-5/--7-8-3 -> correct
- Assert.assertEquals("547830|545783|594783|594578", soundex("GERSCHFELD"));
+ assertEquals("547830|545783|594783|594578", soundex("GERSCHFELD"));
}
public void testEncodeBasic() {
// same as above, but without branching
- Assert.assertEquals("097400", encode("AUERBACH"));
- Assert.assertEquals("097400", encode("OHRBACH"));
- Assert.assertEquals("874400", encode("LIPSHITZ"));
- Assert.assertEquals("874400", encode("LIPPSZYC"));
- Assert.assertEquals("876450", encode("LEWINSKY"));
- Assert.assertEquals("876450", encode("LEVINSKI"));
- Assert.assertEquals("486740", encode("SZLAMAWICZ"));
- Assert.assertEquals("486740", encode("SHLAMOVITZ"));
+ assertEquals("097400", encode("AUERBACH"));
+ assertEquals("097400", encode("OHRBACH"));
+ assertEquals("874400", encode("LIPSHITZ"));
+ assertEquals("874400", encode("LIPPSZYC"));
+ assertEquals("876450", encode("LEWINSKY"));
+ assertEquals("876450", encode("LEVINSKI"));
+ assertEquals("486740", encode("SZLAMAWICZ"));
+ assertEquals("486740", encode("SHLAMOVITZ"));
}
@Test
@@ -98,8 +99,8 @@
@Test
public void testEncodeIgnoreTrimmable() {
- Assert.assertEquals("746536", encode(" \t\n\r Washington \t\n\r "));
- Assert.assertEquals("746536", encode("Washington"));
+ assertEquals("746536", encode(" \t\n\r Washington \t\n\r "));
+ assertEquals("746536", encode("Washington"));
}
/**
@@ -107,24 +108,24 @@
*/
@Test
public void testSoundexBasic() {
- Assert.assertEquals("583600", soundex("GOLDEN"));
- Assert.assertEquals("087930", soundex("Alpert"));
- Assert.assertEquals("791900", soundex("Breuer"));
- Assert.assertEquals("579000", soundex("Haber"));
- Assert.assertEquals("665600", soundex("Mannheim"));
- Assert.assertEquals("664000", soundex("Mintz"));
- Assert.assertEquals("370000", soundex("Topf"));
- Assert.assertEquals("586660", soundex("Kleinmann"));
- Assert.assertEquals("769600", soundex("Ben Aron"));
+ assertEquals("583600", soundex("GOLDEN"));
+ assertEquals("087930", soundex("Alpert"));
+ assertEquals("791900", soundex("Breuer"));
+ assertEquals("579000", soundex("Haber"));
+ assertEquals("665600", soundex("Mannheim"));
+ assertEquals("664000", soundex("Mintz"));
+ assertEquals("370000", soundex("Topf"));
+ assertEquals("586660", soundex("Kleinmann"));
+ assertEquals("769600", soundex("Ben Aron"));
- Assert.assertEquals("097400|097500", soundex("AUERBACH"));
- Assert.assertEquals("097400|097500", soundex("OHRBACH"));
- Assert.assertEquals("874400", soundex("LIPSHITZ"));
- Assert.assertEquals("874400|874500", soundex("LIPPSZYC"));
- Assert.assertEquals("876450", soundex("LEWINSKY"));
- Assert.assertEquals("876450", soundex("LEVINSKI"));
- Assert.assertEquals("486740", soundex("SZLAMAWICZ"));
- Assert.assertEquals("486740", soundex("SHLAMOVITZ"));
+ assertEquals("097400|097500", soundex("AUERBACH"));
+ assertEquals("097400|097500", soundex("OHRBACH"));
+ assertEquals("874400", soundex("LIPSHITZ"));
+ assertEquals("874400|874500", soundex("LIPPSZYC"));
+ assertEquals("876450", soundex("LEWINSKY"));
+ assertEquals("876450", soundex("LEVINSKI"));
+ assertEquals("486740", soundex("SZLAMAWICZ"));
+ assertEquals("486740", soundex("SHLAMOVITZ"));
}
/**
@@ -132,14 +133,14 @@
*/
@Test
public void testSoundexBasic2() {
- Assert.assertEquals("467000|567000", soundex("Ceniow"));
- Assert.assertEquals("467000", soundex("Tsenyuv"));
- Assert.assertEquals("587400|587500", soundex("Holubica"));
- Assert.assertEquals("587400", soundex("Golubitsa"));
- Assert.assertEquals("746480|794648", soundex("Przemysl"));
- Assert.assertEquals("746480", soundex("Pshemeshil"));
- Assert.assertEquals("944744|944745|944754|944755|945744|945745|945754|945755", soundex("Rosochowaciec"));
- Assert.assertEquals("945744", soundex("Rosokhovatsets"));
+ assertEquals("467000|567000", soundex("Ceniow"));
+ assertEquals("467000", soundex("Tsenyuv"));
+ assertEquals("587400|587500", soundex("Holubica"));
+ assertEquals("587400", soundex("Golubitsa"));
+ assertEquals("746480|794648", soundex("Przemysl"));
+ assertEquals("746480", soundex("Pshemeshil"));
+ assertEquals("944744|944745|944754|944755|945744|945745|945754|945755", soundex("Rosochowaciec"));
+ assertEquals("945744", soundex("Rosokhovatsets"));
}
/**
@@ -147,19 +148,19 @@
*/
@Test
public void testSoundexBasic3() {
- Assert.assertEquals("734000|739400", soundex("Peters"));
- Assert.assertEquals("734600|739460", soundex("Peterson"));
- Assert.assertEquals("645740", soundex("Moskowitz"));
- Assert.assertEquals("645740", soundex("Moskovitz"));
- Assert.assertEquals("154600|145460|454600|445460", soundex("Jackson"));
- Assert.assertEquals("154654|154645|154644|145465|145464|454654|454645|454644|445465|445464",
+ assertEquals("734000|739400", soundex("Peters"));
+ assertEquals("734600|739460", soundex("Peterson"));
+ assertEquals("645740", soundex("Moskowitz"));
+ assertEquals("645740", soundex("Moskovitz"));
+ assertEquals("154600|145460|454600|445460", soundex("Jackson"));
+ assertEquals("154654|154645|154644|145465|145464|454654|454645|454644|445465|445464",
soundex("Jackson-Jackson"));
}
@Test
public void testSpecialRomanianCharacters() {
- Assert.assertEquals("364000|464000", soundex("Å£amas")); // t-cedilla
- Assert.assertEquals("364000|464000", soundex("țamas")); // t-comma
+ assertEquals("364000|464000", soundex("Å£amas")); // t-cedilla
+ assertEquals("364000|464000", soundex("țamas")); // t-comma
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/DoubleMetaphone2Test.java b/src/test/java/org/apache/commons/codec/language/DoubleMetaphone2Test.java
index 5f8435a..af0334c 100644
--- a/src/test/java/org/apache/commons/codec/language/DoubleMetaphone2Test.java
+++ b/src/test/java/org/apache/commons/codec/language/DoubleMetaphone2Test.java
@@ -17,10 +17,10 @@
package org.apache.commons.codec.language;
-import static org.junit.Assert.assertEquals;
-
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests {@link DoubleMetaphone}.
@@ -1263,7 +1263,7 @@
private void checkDoubleMetaphone(final int typeIndex, final boolean alternate) {
for (int i = 0; i < TEST_DATA.length; i++) {
final String value = TEST_DATA[i][0];
- assertEquals("Test [" + i + "]=" + value, TEST_DATA[i][typeIndex], this.getStringEncoder().doubleMetaphone(value, alternate));
+ assertEquals(TEST_DATA[i][typeIndex], this.getStringEncoder().doubleMetaphone(value, alternate), "Test [" + i + "]=" + value);
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/DoubleMetaphoneTest.java b/src/test/java/org/apache/commons/codec/language/DoubleMetaphoneTest.java
index 60ecf01..ae1e940 100644
--- a/src/test/java/org/apache/commons/codec/language/DoubleMetaphoneTest.java
+++ b/src/test/java/org/apache/commons/codec/language/DoubleMetaphoneTest.java
@@ -17,15 +17,11 @@
package org.apache.commons.codec.language;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link DoubleMetaphone}.
@@ -1012,7 +1008,7 @@
try {
assertEquals(expected, this.getStringEncoder().encode((Object) source));
} catch (final EncoderException e) {
- fail("Unexpected expection: " + e);
+ fail("Unexpected exception: " + e);
}
assertEquals(expected, this.getStringEncoder().doubleMetaphone(source));
assertEquals(expected, this.getStringEncoder().doubleMetaphone(source, false));
@@ -1036,11 +1032,11 @@
final String name0 = pair[0];
final String name1 = pair[1];
final String failMsg = "Expected match between " + name0 + " and " + name1 + " (use alternate: " + useAlternate + ")";
- assertTrue(failMsg, this.getStringEncoder().isDoubleMetaphoneEqual(name0, name1, useAlternate));
- assertTrue(failMsg, this.getStringEncoder().isDoubleMetaphoneEqual(name1, name0, useAlternate));
+ assertTrue(this.getStringEncoder().isDoubleMetaphoneEqual(name0, name1, useAlternate), failMsg);
+ assertTrue(this.getStringEncoder().isDoubleMetaphoneEqual(name1, name0, useAlternate), failMsg);
if (!useAlternate) {
- assertTrue(failMsg, this.getStringEncoder().isDoubleMetaphoneEqual(name0, name1));
- assertTrue(failMsg, this.getStringEncoder().isDoubleMetaphoneEqual(name1, name0));
+ assertTrue(this.getStringEncoder().isDoubleMetaphoneEqual(name0, name1), failMsg);
+ assertTrue(this.getStringEncoder().isDoubleMetaphoneEqual(name1, name0), failMsg);
}
}
}
@@ -1227,15 +1223,15 @@
final DoubleMetaphone doubleMetaphone = new DoubleMetaphone();
// Sanity check of default settings
- assertEquals("Default Max Code Length", 4, doubleMetaphone.getMaxCodeLen());
- assertEquals("Default Primary", "JMPT", doubleMetaphone.doubleMetaphone(value, false));
- assertEquals("Default Alternate", "AMPT", doubleMetaphone.doubleMetaphone(value, true));
+ assertEquals(4, doubleMetaphone.getMaxCodeLen(), "Default Max Code Length");
+ assertEquals( "JMPT", doubleMetaphone.doubleMetaphone(value, false), "Default Primary");
+ assertEquals("AMPT", doubleMetaphone.doubleMetaphone(value, true), "Default Alternate");
// Check setting Max Code Length
doubleMetaphone.setMaxCodeLen(3);
- assertEquals("Set Max Code Length", 3, doubleMetaphone.getMaxCodeLen());
- assertEquals("Max=3 Primary", "JMP", doubleMetaphone.doubleMetaphone(value, false));
- assertEquals("Max=3 Alternate", "AMP", doubleMetaphone.doubleMetaphone(value, true));
+ assertEquals(3, doubleMetaphone.getMaxCodeLen(), "Set Max Code Length");
+ assertEquals( "JMP", doubleMetaphone.doubleMetaphone(value, false), "Max=3 Primary");
+ assertEquals("AMP", doubleMetaphone.doubleMetaphone(value, true), "Max=3 Alternate");
}
public void validateFixture(final String[][] pairs) {
diff --git a/src/test/java/org/apache/commons/codec/language/MatchRatingApproachEncoderTest.java b/src/test/java/org/apache/commons/codec/language/MatchRatingApproachEncoderTest.java
index 9e8eff7..f27f1a1 100644
--- a/src/test/java/org/apache/commons/codec/language/MatchRatingApproachEncoderTest.java
+++ b/src/test/java/org/apache/commons/codec/language/MatchRatingApproachEncoderTest.java
@@ -17,13 +17,10 @@
package org.apache.commons.codec.language;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Series of tests for the Match Rating Approach algorithm.
diff --git a/src/test/java/org/apache/commons/codec/language/MetaphoneTest.java b/src/test/java/org/apache/commons/codec/language/MetaphoneTest.java
index 0df2832..813c274 100644
--- a/src/test/java/org/apache/commons/codec/language/MetaphoneTest.java
+++ b/src/test/java/org/apache/commons/codec/language/MetaphoneTest.java
@@ -17,12 +17,10 @@
package org.apache.commons.codec.language;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
*/
@@ -31,8 +29,8 @@
public void assertIsMetaphoneEqual(final String source, final String[] matches) {
// match source to all matches
for (final String matche : matches) {
- assertTrue("Source: " + source + ", should have same Metaphone as: " + matche,
- this.getStringEncoder().isMetaphoneEqual(source, matche));
+ assertTrue(this.getStringEncoder().isMetaphoneEqual(source, matche),
+ "Source: " + source + ", should have same Metaphone as: " + matche);
}
// match to each other
for (final String matche : matches) {
@@ -48,8 +46,8 @@
final String name0 = pair[0];
final String name1 = pair[1];
final String failMsg = "Expected match between " + name0 + " and " + name1;
- assertTrue(failMsg, this.getStringEncoder().isMetaphoneEqual(name0, name1));
- assertTrue(failMsg, this.getStringEncoder().isMetaphoneEqual(name1, name0));
+ assertTrue(this.getStringEncoder().isMetaphoneEqual(name0, name1), failMsg);
+ assertTrue(this.getStringEncoder().isMetaphoneEqual(name1, name0), failMsg);
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/NysiisTest.java b/src/test/java/org/apache/commons/codec/language/NysiisTest.java
index eacaef4..4405cd8 100644
--- a/src/test/java/org/apache/commons/codec/language/NysiisTest.java
+++ b/src/test/java/org/apache/commons/codec/language/NysiisTest.java
@@ -19,8 +19,10 @@
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link Nysiis}
@@ -41,7 +43,7 @@
* @throws EncoderException for some failure scenarios */
private void assertEncodings(final String[]... testValues) throws EncoderException {
for (final String[] arr : testValues) {
- Assert.assertEquals("Problem with " + arr[0], arr[1], this.fullNysiis.encode(arr[0]));
+ assertEquals(arr[1], this.fullNysiis.encode(arr[0]), "Problem with " + arr[0]);
}
}
@@ -52,7 +54,7 @@
private void encodeAll(final String[] strings, final String expectedEncoding) {
for (final String string : strings) {
- Assert.assertEquals("Problem with " + string, expectedEncoding, getStringEncoder().encode(string));
+ assertEquals(expectedEncoding, getStringEncoder().encode(string), "Problem with " + string);
}
}
@@ -285,8 +287,8 @@
final Nysiis encoder = new Nysiis(true);
final String encoded = encoder.encode("WESTERLUND");
- Assert.assertTrue(encoded.length() <= 6);
- Assert.assertEquals("WASTAR", encoded);
+ assertTrue(encoded.length() <= 6);
+ assertEquals("WASTAR", encoded);
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/RefinedSoundexTest.java b/src/test/java/org/apache/commons/codec/language/RefinedSoundexTest.java
index 7bb62e5..da0375c 100644
--- a/src/test/java/org/apache/commons/codec/language/RefinedSoundexTest.java
+++ b/src/test/java/org/apache/commons/codec/language/RefinedSoundexTest.java
@@ -17,11 +17,11 @@
package org.apache.commons.codec.language;
-import static org.junit.Assert.assertEquals;
-
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests RefinedSoundex.
@@ -77,7 +77,7 @@
@Test
public void testGetMappingCodeNonLetter() {
final char code = this.getStringEncoder().getMappingCode('#');
- assertEquals("Code does not equals zero", 0, code);
+ assertEquals(0, code, "Code does not equals zero");
}
@Test
diff --git a/src/test/java/org/apache/commons/codec/language/SoundexTest.java b/src/test/java/org/apache/commons/codec/language/SoundexTest.java
index 849abf4..7dfd02e 100644
--- a/src/test/java/org/apache/commons/codec/language/SoundexTest.java
+++ b/src/test/java/org/apache/commons/codec/language/SoundexTest.java
@@ -19,12 +19,11 @@
package org.apache.commons.codec.language;
-import static org.junit.Assert.assertThrows;
-
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link Soundex}.
@@ -86,42 +85,42 @@
@Test
public void testBadCharacters() {
- Assert.assertEquals("H452", this.getStringEncoder().encode("HOL>MES"));
+ assertEquals("H452", this.getStringEncoder().encode("HOL>MES"));
}
@Test
public void testDifference() throws EncoderException {
// Edge cases
- Assert.assertEquals(0, this.getStringEncoder().difference(null, null));
- Assert.assertEquals(0, this.getStringEncoder().difference("", ""));
- Assert.assertEquals(0, this.getStringEncoder().difference(" ", " "));
+ assertEquals(0, this.getStringEncoder().difference(null, null));
+ assertEquals(0, this.getStringEncoder().difference("", ""));
+ assertEquals(0, this.getStringEncoder().difference(" ", " "));
// Normal cases
- Assert.assertEquals(4, this.getStringEncoder().difference("Smith", "Smythe"));
- Assert.assertEquals(2, this.getStringEncoder().difference("Ann", "Andrew"));
- Assert.assertEquals(1, this.getStringEncoder().difference("Margaret", "Andrew"));
- Assert.assertEquals(0, this.getStringEncoder().difference("Janet", "Margaret"));
+ assertEquals(4, this.getStringEncoder().difference("Smith", "Smythe"));
+ assertEquals(2, this.getStringEncoder().difference("Ann", "Andrew"));
+ assertEquals(1, this.getStringEncoder().difference("Margaret", "Andrew"));
+ assertEquals(0, this.getStringEncoder().difference("Janet", "Margaret"));
// Examples from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp
- Assert.assertEquals(4, this.getStringEncoder().difference("Green", "Greene"));
- Assert.assertEquals(0, this.getStringEncoder().difference("Blotchet-Halls", "Greene"));
+ assertEquals(4, this.getStringEncoder().difference("Green", "Greene"));
+ assertEquals(0, this.getStringEncoder().difference("Blotchet-Halls", "Greene"));
// Examples from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_3o6w.asp
- Assert.assertEquals(4, this.getStringEncoder().difference("Smith", "Smythe"));
- Assert.assertEquals(4, this.getStringEncoder().difference("Smithers", "Smythers"));
- Assert.assertEquals(2, this.getStringEncoder().difference("Anothers", "Brothers"));
+ assertEquals(4, this.getStringEncoder().difference("Smith", "Smythe"));
+ assertEquals(4, this.getStringEncoder().difference("Smithers", "Smythers"));
+ assertEquals(2, this.getStringEncoder().difference("Anothers", "Brothers"));
}
@Test
public void testEncodeBasic() {
- Assert.assertEquals("T235", this.getStringEncoder().encode("testing"));
- Assert.assertEquals("T000", this.getStringEncoder().encode("The"));
- Assert.assertEquals("Q200", this.getStringEncoder().encode("quick"));
- Assert.assertEquals("B650", this.getStringEncoder().encode("brown"));
- Assert.assertEquals("F200", this.getStringEncoder().encode("fox"));
- Assert.assertEquals("J513", this.getStringEncoder().encode("jumped"));
- Assert.assertEquals("O160", this.getStringEncoder().encode("over"));
- Assert.assertEquals("T000", this.getStringEncoder().encode("the"));
- Assert.assertEquals("L200", this.getStringEncoder().encode("lazy"));
- Assert.assertEquals("D200", this.getStringEncoder().encode("dogs"));
+ assertEquals("T235", this.getStringEncoder().encode("testing"));
+ assertEquals("T000", this.getStringEncoder().encode("The"));
+ assertEquals("Q200", this.getStringEncoder().encode("quick"));
+ assertEquals("B650", this.getStringEncoder().encode("brown"));
+ assertEquals("F200", this.getStringEncoder().encode("fox"));
+ assertEquals("J513", this.getStringEncoder().encode("jumped"));
+ assertEquals("O160", this.getStringEncoder().encode("over"));
+ assertEquals("T000", this.getStringEncoder().encode("the"));
+ assertEquals("L200", this.getStringEncoder().encode("lazy"));
+ assertEquals("D200", this.getStringEncoder().encode("dogs"));
}
/**
@@ -129,22 +128,22 @@
*/
@Test
public void testEncodeBatch2() {
- Assert.assertEquals("A462", this.getStringEncoder().encode("Allricht"));
- Assert.assertEquals("E166", this.getStringEncoder().encode("Eberhard"));
- Assert.assertEquals("E521", this.getStringEncoder().encode("Engebrethson"));
- Assert.assertEquals("H512", this.getStringEncoder().encode("Heimbach"));
- Assert.assertEquals("H524", this.getStringEncoder().encode("Hanselmann"));
- Assert.assertEquals("H431", this.getStringEncoder().encode("Hildebrand"));
- Assert.assertEquals("K152", this.getStringEncoder().encode("Kavanagh"));
- Assert.assertEquals("L530", this.getStringEncoder().encode("Lind"));
- Assert.assertEquals("L222", this.getStringEncoder().encode("Lukaschowsky"));
- Assert.assertEquals("M235", this.getStringEncoder().encode("McDonnell"));
- Assert.assertEquals("M200", this.getStringEncoder().encode("McGee"));
- Assert.assertEquals("O155", this.getStringEncoder().encode("Opnian"));
- Assert.assertEquals("O155", this.getStringEncoder().encode("Oppenheimer"));
- Assert.assertEquals("R355", this.getStringEncoder().encode("Riedemanas"));
- Assert.assertEquals("Z300", this.getStringEncoder().encode("Zita"));
- Assert.assertEquals("Z325", this.getStringEncoder().encode("Zitzmeinn"));
+ assertEquals("A462", this.getStringEncoder().encode("Allricht"));
+ assertEquals("E166", this.getStringEncoder().encode("Eberhard"));
+ assertEquals("E521", this.getStringEncoder().encode("Engebrethson"));
+ assertEquals("H512", this.getStringEncoder().encode("Heimbach"));
+ assertEquals("H524", this.getStringEncoder().encode("Hanselmann"));
+ assertEquals("H431", this.getStringEncoder().encode("Hildebrand"));
+ assertEquals("K152", this.getStringEncoder().encode("Kavanagh"));
+ assertEquals("L530", this.getStringEncoder().encode("Lind"));
+ assertEquals("L222", this.getStringEncoder().encode("Lukaschowsky"));
+ assertEquals("M235", this.getStringEncoder().encode("McDonnell"));
+ assertEquals("M200", this.getStringEncoder().encode("McGee"));
+ assertEquals("O155", this.getStringEncoder().encode("Opnian"));
+ assertEquals("O155", this.getStringEncoder().encode("Oppenheimer"));
+ assertEquals("R355", this.getStringEncoder().encode("Riedemanas"));
+ assertEquals("Z300", this.getStringEncoder().encode("Zita"));
+ assertEquals("Z325", this.getStringEncoder().encode("Zitzmeinn"));
}
/**
@@ -152,15 +151,15 @@
*/
@Test
public void testEncodeBatch3() {
- Assert.assertEquals("W252", this.getStringEncoder().encode("Washington"));
- Assert.assertEquals("L000", this.getStringEncoder().encode("Lee"));
- Assert.assertEquals("G362", this.getStringEncoder().encode("Gutierrez"));
- Assert.assertEquals("P236", this.getStringEncoder().encode("Pfister"));
- Assert.assertEquals("J250", this.getStringEncoder().encode("Jackson"));
- Assert.assertEquals("T522", this.getStringEncoder().encode("Tymczak"));
+ assertEquals("W252", this.getStringEncoder().encode("Washington"));
+ assertEquals("L000", this.getStringEncoder().encode("Lee"));
+ assertEquals("G362", this.getStringEncoder().encode("Gutierrez"));
+ assertEquals("P236", this.getStringEncoder().encode("Pfister"));
+ assertEquals("J250", this.getStringEncoder().encode("Jackson"));
+ assertEquals("T522", this.getStringEncoder().encode("Tymczak"));
// For VanDeusen: D-250 (D, 2 for the S, 5 for the N, 0 added) is also
// possible.
- Assert.assertEquals("V532", this.getStringEncoder().encode("VanDeusen"));
+ assertEquals("V532", this.getStringEncoder().encode("VanDeusen"));
}
/**
@@ -168,14 +167,14 @@
*/
@Test
public void testEncodeBatch4() {
- Assert.assertEquals("H452", this.getStringEncoder().encode("HOLMES"));
- Assert.assertEquals("A355", this.getStringEncoder().encode("ADOMOMI"));
- Assert.assertEquals("V536", this.getStringEncoder().encode("VONDERLEHR"));
- Assert.assertEquals("B400", this.getStringEncoder().encode("BALL"));
- Assert.assertEquals("S000", this.getStringEncoder().encode("SHAW"));
- Assert.assertEquals("J250", this.getStringEncoder().encode("JACKSON"));
- Assert.assertEquals("S545", this.getStringEncoder().encode("SCANLON"));
- Assert.assertEquals("S532", this.getStringEncoder().encode("SAINTJOHN"));
+ assertEquals("H452", this.getStringEncoder().encode("HOLMES"));
+ assertEquals("A355", this.getStringEncoder().encode("ADOMOMI"));
+ assertEquals("V536", this.getStringEncoder().encode("VONDERLEHR"));
+ assertEquals("B400", this.getStringEncoder().encode("BALL"));
+ assertEquals("S000", this.getStringEncoder().encode("SHAW"));
+ assertEquals("J250", this.getStringEncoder().encode("JACKSON"));
+ assertEquals("S545", this.getStringEncoder().encode("SCANLON"));
+ assertEquals("S532", this.getStringEncoder().encode("SAINTJOHN"));
}
@@ -214,7 +213,7 @@
@Test
public void testEncodeIgnoreTrimmable() {
- Assert.assertEquals("W252", this.getStringEncoder().encode(" \t\n\r Washington \t\n\r "));
+ assertEquals("W252", this.getStringEncoder().encode(" \t\n\r Washington \t\n\r "));
}
/**
@@ -226,10 +225,10 @@
// http://www.archives.gov/research_room/genealogy/census/soundex.html:
// Ashcraft is coded A-261 (A, 2 for the S, C ignored, 6 for the R, 1
// for the F). It is not coded A-226.
- Assert.assertEquals("A261", this.getStringEncoder().encode("Ashcraft"));
- Assert.assertEquals("A261", this.getStringEncoder().encode("Ashcroft"));
- Assert.assertEquals("Y330", this.getStringEncoder().encode("yehudit"));
- Assert.assertEquals("Y330", this.getStringEncoder().encode("yhwdyt"));
+ assertEquals("A261", this.getStringEncoder().encode("Ashcraft"));
+ assertEquals("A261", this.getStringEncoder().encode("Ashcroft"));
+ assertEquals("Y330", this.getStringEncoder().encode("yehudit"));
+ assertEquals("Y330", this.getStringEncoder().encode("yhwdyt"));
}
/**
@@ -239,8 +238,8 @@
*/
@Test
public void testHWRuleEx2() {
- Assert.assertEquals("B312", this.getStringEncoder().encode("BOOTHDAVIS"));
- Assert.assertEquals("B312", this.getStringEncoder().encode("BOOTH-DAVIS"));
+ assertEquals("B312", this.getStringEncoder().encode("BOOTHDAVIS"));
+ assertEquals("B312", this.getStringEncoder().encode("BOOTH-DAVIS"));
}
/**
@@ -249,8 +248,8 @@
* @throws EncoderException for some failure scenarios */
@Test
public void testHWRuleEx3() throws EncoderException {
- Assert.assertEquals("S460", this.getStringEncoder().encode("Sgler"));
- Assert.assertEquals("S460", this.getStringEncoder().encode("Swhgler"));
+ assertEquals("S460", this.getStringEncoder().encode("Sgler"));
+ assertEquals("S460", this.getStringEncoder().encode("Swhgler"));
// Also S460:
this.checkEncodingVariations("S460", new String[]{
"SAILOR",
@@ -277,8 +276,8 @@
*/
@Test
public void testMsSqlServer1() {
- Assert.assertEquals("S530", this.getStringEncoder().encode("Smith"));
- Assert.assertEquals("S530", this.getStringEncoder().encode("Smythe"));
+ assertEquals("S530", this.getStringEncoder().encode("Smith"));
+ assertEquals("S530", this.getStringEncoder().encode("Smythe"));
}
/**
@@ -297,15 +296,15 @@
*/
@Test
public void testMsSqlServer3() {
- Assert.assertEquals("A500", this.getStringEncoder().encode("Ann"));
- Assert.assertEquals("A536", this.getStringEncoder().encode("Andrew"));
- Assert.assertEquals("J530", this.getStringEncoder().encode("Janet"));
- Assert.assertEquals("M626", this.getStringEncoder().encode("Margaret"));
- Assert.assertEquals("S315", this.getStringEncoder().encode("Steven"));
- Assert.assertEquals("M240", this.getStringEncoder().encode("Michael"));
- Assert.assertEquals("R163", this.getStringEncoder().encode("Robert"));
- Assert.assertEquals("L600", this.getStringEncoder().encode("Laura"));
- Assert.assertEquals("A500", this.getStringEncoder().encode("Anne"));
+ assertEquals("A500", this.getStringEncoder().encode("Ann"));
+ assertEquals("A536", this.getStringEncoder().encode("Andrew"));
+ assertEquals("J530", this.getStringEncoder().encode("Janet"));
+ assertEquals("M626", this.getStringEncoder().encode("Margaret"));
+ assertEquals("S315", this.getStringEncoder().encode("Steven"));
+ assertEquals("M240", this.getStringEncoder().encode("Michael"));
+ assertEquals("R163", this.getStringEncoder().encode("Robert"));
+ assertEquals("L600", this.getStringEncoder().encode("Laura"));
+ assertEquals("A500", this.getStringEncoder().encode("Anne"));
}
/**
@@ -313,17 +312,17 @@
*/
@Test
public void testNewInstance() {
- Assert.assertEquals("W452", new Soundex().soundex("Williams"));
+ assertEquals("W452", new Soundex().soundex("Williams"));
}
@Test
public void testNewInstance2() {
- Assert.assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING.toCharArray()).soundex("Williams"));
+ assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING.toCharArray()).soundex("Williams"));
}
@Test
public void testNewInstance3() {
- Assert.assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING).soundex("Williams"));
+ assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING).soundex("Williams"));
}
@Test
@@ -333,10 +332,10 @@
@Test
public void testSoundexUtilsNullBehaviour() {
- Assert.assertNull(SoundexUtils.clean(null));
- Assert.assertEquals("", SoundexUtils.clean(""));
- Assert.assertEquals(0, SoundexUtils.differenceEncoded(null, ""));
- Assert.assertEquals(0, SoundexUtils.differenceEncoded("", null));
+ assertNull(SoundexUtils.clean(null));
+ assertEquals("", SoundexUtils.clean(""));
+ assertEquals(0, SoundexUtils.differenceEncoded(null, ""));
+ assertEquals(0, SoundexUtils.differenceEncoded("", null));
}
/**
@@ -344,7 +343,7 @@
*/
@Test
public void testUsEnglishStatic() {
- Assert.assertEquals("W452", Soundex.US_ENGLISH.soundex("Williams"));
+ assertEquals("W452", Soundex.US_ENGLISH.soundex("Williams"));
}
/**
@@ -354,12 +353,12 @@
*/
@Test
public void testUsMappingEWithAcute() {
- Assert.assertEquals("E000", this.getStringEncoder().encode("e"));
+ assertEquals("E000", this.getStringEncoder().encode("e"));
if (Character.isLetter('\u00e9')) { // e-acute
// uppercase E-acute
assertThrows(IllegalArgumentException.class, () -> getStringEncoder().encode("\u00e9"));
} else {
- Assert.assertEquals("", this.getStringEncoder().encode("\u00e9"));
+ assertEquals("", this.getStringEncoder().encode("\u00e9"));
}
}
@@ -370,12 +369,12 @@
*/
@Test
public void testUsMappingOWithDiaeresis() {
- Assert.assertEquals("O000", this.getStringEncoder().encode("o"));
+ assertEquals("O000", this.getStringEncoder().encode("o"));
if (Character.isLetter('\u00f6')) { // o-umlaut
// uppercase O-umlaut
assertThrows(IllegalArgumentException.class, () -> getStringEncoder().encode("\u00f6"));
} else {
- Assert.assertEquals("", this.getStringEncoder().encode("\u00f6"));
+ assertEquals("", this.getStringEncoder().encode("\u00f6"));
}
}
@@ -384,40 +383,40 @@
*/
@Test
public void testWikipediaAmericanSoundex() {
- Assert.assertEquals("R163", this.getStringEncoder().encode("Robert"));
- Assert.assertEquals("R163", this.getStringEncoder().encode("Rupert"));
- Assert.assertEquals("A261", this.getStringEncoder().encode("Ashcraft"));
- Assert.assertEquals("A261", this.getStringEncoder().encode("Ashcroft"));
- Assert.assertEquals("T522", this.getStringEncoder().encode("Tymczak"));
- Assert.assertEquals("P236", this.getStringEncoder().encode("Pfister"));
+ assertEquals("R163", this.getStringEncoder().encode("Robert"));
+ assertEquals("R163", this.getStringEncoder().encode("Rupert"));
+ assertEquals("A261", this.getStringEncoder().encode("Ashcraft"));
+ assertEquals("A261", this.getStringEncoder().encode("Ashcroft"));
+ assertEquals("T522", this.getStringEncoder().encode("Tymczak"));
+ assertEquals("P236", this.getStringEncoder().encode("Pfister"));
}
@Test
// examples and algorithm rules from: http://www.genealogy.com/articles/research/00000060.html
public void testGenealogy() { // treat vowels and HW as silent
final Soundex s = Soundex.US_ENGLISH_GENEALOGY;
- Assert.assertEquals("H251", s.encode("Heggenburger"));
- Assert.assertEquals("B425", s.encode("Blackman"));
- Assert.assertEquals("S530", s.encode("Schmidt"));
- Assert.assertEquals("L150", s.encode("Lippmann"));
+ assertEquals("H251", s.encode("Heggenburger"));
+ assertEquals("B425", s.encode("Blackman"));
+ assertEquals("S530", s.encode("Schmidt"));
+ assertEquals("L150", s.encode("Lippmann"));
// Additional local example
- Assert.assertEquals("D200", s.encode("Dodds")); // 'o' is not a separator here - it is silent
- Assert.assertEquals("D200", s.encode("Dhdds")); // 'h' is silent
- Assert.assertEquals("D200", s.encode("Dwdds")); // 'w' is silent
+ assertEquals("D200", s.encode("Dodds")); // 'o' is not a separator here - it is silent
+ assertEquals("D200", s.encode("Dhdds")); // 'h' is silent
+ assertEquals("D200", s.encode("Dwdds")); // 'w' is silent
}
@Test
// examples and algorithm rules from: http://west-penwith.org.uk/misc/soundex.htm
public void testSimplifiedSoundex() { // treat vowels and HW as separators
final Soundex s = Soundex.US_ENGLISH_SIMPLIFIED;
- Assert.assertEquals("W452", s.encode("WILLIAMS"));
- Assert.assertEquals("B625", s.encode("BARAGWANATH"));
- Assert.assertEquals("D540", s.encode("DONNELL"));
- Assert.assertEquals("L300", s.encode("LLOYD"));
- Assert.assertEquals("W422", s.encode("WOOLCOCK"));
+ assertEquals("W452", s.encode("WILLIAMS"));
+ assertEquals("B625", s.encode("BARAGWANATH"));
+ assertEquals("D540", s.encode("DONNELL"));
+ assertEquals("L300", s.encode("LLOYD"));
+ assertEquals("W422", s.encode("WOOLCOCK"));
// Additional local examples
- Assert.assertEquals("D320", s.encode("Dodds"));
- Assert.assertEquals("D320", s.encode("Dwdds")); // w is a separator
- Assert.assertEquals("D320", s.encode("Dhdds")); // h is a separator
+ assertEquals("D320", s.encode("Dodds"));
+ assertEquals("D320", s.encode("Dwdds")); // w is a separator
+ assertEquals("D320", s.encode("Dhdds")); // h is a separator
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java b/src/test/java/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
index 4d9f930..3e65734 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
@@ -17,16 +17,14 @@
package org.apache.commons.codec.language.bm;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;
import org.apache.commons.codec.StringEncoderAbstractTest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests BeiderMorseEncoder.
@@ -37,7 +35,7 @@
private static final char[] TEST_CHARS = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'o', 'u' };
private void assertNotEmpty(final BeiderMorseEncoder bmpm, final String value) throws EncoderException {
- Assert.assertNotEquals(value, "", bmpm.encode(value));
+ assertNotEquals("", bmpm.encode(value), value);
}
private BeiderMorseEncoder createGenericApproxEncoder() {
@@ -124,10 +122,10 @@
assertThrows(IllegalArgumentException.class, () -> Languages.getInstance("thereIsNoSuchLanguage"));
}
- @Test(timeout = 10000L)
+ @Test
public void testLongestEnglishSurname() throws EncoderException {
final BeiderMorseEncoder bmpm = createGenericApproxEncoder();
- bmpm.encode("MacGhilleseatheanaich");
+ assertTimeout(Duration.ofMillis(10000L), () -> bmpm.encode("MacGhilleseatheanaich"));
}
@Test
@@ -158,21 +156,21 @@
public void testSetConcat() {
final BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
bmpm.setConcat(false);
- assertFalse("Should be able to set concat to false", bmpm.isConcat());
+ assertFalse(bmpm.isConcat(), "Should be able to set concat to false");
}
@Test
public void testSetNameTypeAsh() {
final BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
bmpm.setNameType(NameType.ASHKENAZI);
- assertEquals("Name type should have been set to ash", NameType.ASHKENAZI, bmpm.getNameType());
+ assertEquals(NameType.ASHKENAZI, bmpm.getNameType(), "Name type should have been set to ash");
}
@Test
public void testSetRuleTypeExact() {
final BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
bmpm.setRuleType(RuleType.EXACT);
- assertEquals("Rule type should have been set to exact", RuleType.EXACT, bmpm.getRuleType());
+ assertEquals(RuleType.EXACT, bmpm.getRuleType(), "Rule type should have been set to exact");
}
@Test
@@ -186,7 +184,7 @@
*
* @throws EncoderException for some failure scenarios
*/
- @Test(/* timeout = 20000L */)
+ @Test /* timeout = 20000L */
public void testSpeedCheck() throws EncoderException {
final BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
final StringBuilder stringBuffer = new StringBuilder();
diff --git a/src/test/java/org/apache/commons/codec/language/bm/CacheSubSequencePerformanceTest.java b/src/test/java/org/apache/commons/codec/language/bm/CacheSubSequencePerformanceTest.java
index 4df9e24..04168b8 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/CacheSubSequencePerformanceTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/CacheSubSequencePerformanceTest.java
@@ -17,7 +17,7 @@
package org.apache.commons.codec.language.bm;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class CacheSubSequencePerformanceTest {
diff --git a/src/test/java/org/apache/commons/codec/language/bm/LanguageGuessingTest.java b/src/test/java/org/apache/commons/codec/language/bm/LanguageGuessingTest.java
index 583a615..6f3fdf9 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/LanguageGuessingTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/LanguageGuessingTest.java
@@ -17,61 +17,52 @@
package org.apache.commons.codec.language.bm;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
-import java.util.Arrays;
-import java.util.List;
+import java.util.stream.Stream;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests guessLanguages API.
*
* @since 1.6
*/
-@RunWith(Parameterized.class)
public class LanguageGuessingTest {
- @Parameterized.Parameters(name = "{0}-{1}-{2}")
- public static List<Object[]> data() {
- return Arrays.asList(new Object[][] {
- { "Renault", "french" },
- { "Mickiewicz", "polish" },
- { "Thompson", "english" }, // this also hits german and greeklatin
- { "Nu\u00f1ez", "spanish" }, // Nuñez
- { "Carvalho", "portuguese" },
- { "\u010capek", "czech" }, // ÄŒapek
- { "Sjneijder", "dutch" },
- { "Klausewitz", "german" },
- { "K\u00fc\u00e7\u00fck", "turkish" }, // Küçük
- { "Giacometti", "italian" },
- { "Nagy", "hungarian" },
- { "Ceau\u015fescu", "romanian" }, // CeauÅŸescu
- { "Angelopoulos", "greeklatin" },
- { "\u0391\u03b3\u03b3\u03b5\u03bb\u03cc\u03c0\u03bf\u03c5\u03bb\u03bf\u03c2", "greek" }, // ΑγγελÏŒπουλος
- { "\u041f\u0443\u0448\u043a\u0438\u043d", "cyrillic" }, // Пушкин
- { "\u05db\u05d4\u05df", "hebrew" }, // כהן
- { "\u00e1cz", "any" }, // ácz
- { "\u00e1tz", "any" } }); // átz
+ public static Stream<Arguments> data() {
+ return Stream.of(
+ Arguments.of("Renault", "french"),
+ Arguments.of("Mickiewicz", "polish"),
+ Arguments.of("Thompson", "english"), // this also hits german and greeklatin
+ Arguments.of("Nu\u00f1ez", "spanish"), // Nuñez
+ Arguments.of("Carvalho", "portuguese"),
+ Arguments.of("\u010capek", "czech"), // ÄŒapek
+ Arguments.of("Sjneijder", "dutch"),
+ Arguments.of("Klausewitz", "german"),
+ Arguments.of("K\u00fc\u00e7\u00fck", "turkish"), // Küçük
+ Arguments.of("Giacometti", "italian"),
+ Arguments.of("Nagy", "hungarian"),
+ Arguments.of("Ceau\u015fescu", "romanian"), // CeauÅŸescu
+ Arguments.of("Angelopoulos", "greeklatin"),
+ Arguments.of("\u0391\u03b3\u03b3\u03b5\u03bb\u03cc\u03c0\u03bf\u03c5\u03bb\u03bf\u03c2", "greek"), // ΑγγελÏŒπουλος
+ Arguments.of("\u041f\u0443\u0448\u043a\u0438\u043d", "cyrillic"), // Пушкин
+ Arguments.of("\u05db\u05d4\u05df", "hebrew"), // כהן
+ Arguments.of("\u00e1cz", "any"), // ácz
+ Arguments.of("\u00e1tz", "any") // átz
+ );
}
private final Lang lang = Lang.instance(NameType.GENERIC);
- private final String language;
- private final String name;
- public LanguageGuessingTest(final String name, final String language) {
- this.name = name;
- this.language = language;
- }
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testLanguageGuessing(String name, String language) {
+ final Languages.LanguageSet guesses = this.lang.guessLanguages(name);
- @Test
- public void testLanguageGuessing() {
- final Languages.LanguageSet guesses = this.lang.guessLanguages(this.name);
-
- assertTrue("language predicted for name '" + this.name + "' is wrong: " + guesses + " should contain '" + this.language + "'",
- guesses.contains(this.language));
-
+ assertTrue(guesses.contains(language),
+ "language predicted for name '" + name + "' is wrong: " + guesses + " should contain '" + language + "'");
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java b/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
index ded17fe..c583a0c 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/PhoneticEnginePerformanceTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.codec.language.bm;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
/**
* Tests performance for {@link PhoneticEngine}.
diff --git a/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineRegressionTest.java b/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineRegressionTest.java
index cb1a7ed..f3c90f1 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineRegressionTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineRegressionTest.java
@@ -17,14 +17,14 @@
package org.apache.commons.codec.language.bm;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.TreeMap;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests PhoneticEngine and Languages.LanguageSet in ways very similar to code found in solr-3.6.0.
@@ -40,42 +40,58 @@
// concat is true, ruleType is EXACT
args = new TreeMap<>();
args.put("nameType", "GENERIC");
- assertEquals(encode(args, true, "Angelo"), "YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
args.put("ruleType", "EXACT");
- assertEquals(encode(args, true, "Angelo"), "anZelo|andZelo|angelo|anhelo|anjelo|anxelo");
- assertEquals(encode(args, true, "D'Angelo"), "(anZelo|andZelo|angelo|anhelo|anjelo|anxelo)-(danZelo|dandZelo|dangelo|danhelo|danjelo|danxelo)");
+ assertEquals("anZelo|andZelo|angelo|anhelo|anjelo|anxelo",
+ encode(args, true, "Angelo"));
+ assertEquals("(anZelo|andZelo|angelo|anhelo|anjelo|anxelo)-(danZelo|dandZelo|dangelo|danhelo|danjelo|danxelo)",
+ encode(args, true, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, true, "Angelo"), "andZelo|angelo|anxelo");
+ assertEquals("andZelo|angelo|anxelo",
+ encode(args, true, "Angelo"));
assertEquals(encode(args, true, "1234"), "");
// concat is false, ruleType is EXACT
args = new TreeMap<>();
- assertEquals(encode(args, false, "Angelo"), "YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
args.put("ruleType", "EXACT");
- assertEquals(encode(args, false, "Angelo"), "anZelo|andZelo|angelo|anhelo|anjelo|anxelo");
- assertEquals(encode(args, false, "D'Angelo"), "(anZelo|andZelo|angelo|anhelo|anjelo|anxelo)-(danZelo|dandZelo|dangelo|danhelo|danjelo|danxelo)");
+ assertEquals("anZelo|andZelo|angelo|anhelo|anjelo|anxelo",
+ encode(args, false, "Angelo"));
+ assertEquals("(anZelo|andZelo|angelo|anhelo|anjelo|anxelo)-(danZelo|dandZelo|dangelo|danhelo|danjelo|danxelo)",
+ encode(args, false, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, false, "Angelo"), "andZelo|angelo|anxelo");
+ assertEquals("andZelo|angelo|anxelo",
+ encode(args, false, "Angelo"));
assertEquals(encode(args, false, "1234"), "");
// concat is true, ruleType is APPROX
args = new TreeMap<>();
- assertEquals(encode(args, true, "Angelo"), "YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
args.put("ruleType", "APPROX");
- assertEquals(encode(args, true, "Angelo"), "YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo");
- assertEquals(encode(args, true, "D'Angelo"), "(YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo)-(dYngYlo|dYngilo|dagilo|dangYlo|dangilo|daniilo|danilo|danxilo|danzilo|dogilo|dongYlo|dongilo|doniilo|donilo|donxilo|donzilo)");
+ assertEquals("YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
+ assertEquals("(YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo)-(dYngYlo|dYngilo|dagilo|dangYlo|dangilo|daniilo|danilo|danxilo|danzilo|dogilo|dongYlo|dongilo|doniilo|donilo|donxilo|donzilo)",
+ encode(args, true, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, true, "Angelo"), "angilo|anxilo|anzilo|ongilo|onxilo|onzilo");
+ assertEquals("angilo|anxilo|anzilo|ongilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
assertEquals(encode(args, true, "1234"), "");
// concat is false, ruleType is APPROX
args = new TreeMap<>();
- assertEquals(encode(args, false, "Angelo"), "YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
args.put("ruleType", "APPROX");
- assertEquals(encode(args, false, "Angelo"), "YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo");
- assertEquals(encode(args, false, "D'Angelo"), "(YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo)-(dYngYlo|dYngilo|dagilo|dangYlo|dangilo|daniilo|danilo|danxilo|danzilo|dogilo|dongYlo|dongilo|doniilo|donilo|donxilo|donzilo)");
+ assertEquals("YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
+ assertEquals("(YngYlo|Yngilo|agilo|angYlo|angilo|aniilo|anilo|anxilo|anzilo|ogilo|ongYlo|ongilo|oniilo|onilo|onxilo|onzilo)-(dYngYlo|dYngilo|dagilo|dangYlo|dangilo|daniilo|danilo|danxilo|danzilo|dogilo|dongYlo|dongilo|doniilo|donilo|donxilo|donzilo)",
+ encode(args, false, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, false, "Angelo"), "angilo|anxilo|anzilo|ongilo|onxilo|onzilo");
+ assertEquals("angilo|anxilo|anzilo|ongilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
assertEquals(encode(args, false, "1234"), "");
}
@@ -86,45 +102,61 @@
// concat is true, ruleType is EXACT
args = new TreeMap<>();
args.put("nameType", "ASHKENAZI");
- assertEquals(encode(args, true, "Angelo"), "YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
args.put("ruleType", "EXACT");
- assertEquals(encode(args, true, "Angelo"), "andZelo|angelo|anhelo|anxelo");
- assertEquals(encode(args, true, "D'Angelo"), "dandZelo|dangelo|danhelo|danxelo");
+ assertEquals("andZelo|angelo|anhelo|anxelo",
+ encode(args, true, "Angelo"));
+ assertEquals("dandZelo|dangelo|danhelo|danxelo",
+ encode(args, true, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, true, "Angelo"), "angelo|anxelo");
+ assertEquals("angelo|anxelo",
+ encode(args, true, "Angelo"));
assertEquals(encode(args, true, "1234"), "");
// concat is false, ruleType is EXACT
args = new TreeMap<>();
args.put("nameType", "ASHKENAZI");
- assertEquals(encode(args, false, "Angelo"), "YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
args.put("ruleType", "EXACT");
- assertEquals(encode(args, false, "Angelo"), "andZelo|angelo|anhelo|anxelo");
- assertEquals(encode(args, false, "D'Angelo"), "dandZelo|dangelo|danhelo|danxelo");
+ assertEquals("andZelo|angelo|anhelo|anxelo",
+ encode(args, false, "Angelo"));
+ assertEquals("dandZelo|dangelo|danhelo|danxelo",
+ encode(args, false, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, false, "Angelo"), "angelo|anxelo");
+ assertEquals("angelo|anxelo",
+ encode(args, false, "Angelo"));
assertEquals(encode(args, false, "1234"), "");
// concat is true, ruleType is APPROX
args = new TreeMap<>();
args.put("nameType", "ASHKENAZI");
- assertEquals(encode(args, true, "Angelo"), "YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
args.put("ruleType", "APPROX");
- assertEquals(encode(args, true, "Angelo"), "YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo");
- assertEquals(encode(args, true, "D'Angelo"), "dYngYlo|dYngilo|dangYlo|dangilo|danilo|danxilo|danzilo|dongYlo|dongilo|donilo|donxilo|donzilo");
+ assertEquals("YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo",
+ encode(args, true, "Angelo"));
+ assertEquals("dYngYlo|dYngilo|dangYlo|dangilo|danilo|danxilo|danzilo|dongYlo|dongilo|donilo|donxilo|donzilo",
+ encode(args, true, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, true, "Angelo"), "angilo|anxilo|ongilo|onxilo");
+ assertEquals("angilo|anxilo|ongilo|onxilo",
+ encode(args, true, "Angelo"));
assertEquals(encode(args, true, "1234"), "");
// concat is false, ruleType is APPROX
args = new TreeMap<>();
args.put("nameType", "ASHKENAZI");
- assertEquals(encode(args, false, "Angelo"), "YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo");
+ assertEquals("YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
args.put("ruleType", "APPROX");
- assertEquals(encode(args, false, "Angelo"), "YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo");
- assertEquals(encode(args, false, "D'Angelo"), "dYngYlo|dYngilo|dangYlo|dangilo|danilo|danxilo|danzilo|dongYlo|dongilo|donilo|donxilo|donzilo");
+ assertEquals("YngYlo|Yngilo|angYlo|angilo|anilo|anxilo|anzilo|ongYlo|ongilo|onilo|onxilo|onzilo",
+ encode(args, false, "Angelo"));
+ assertEquals("dYngYlo|dYngilo|dangYlo|dangilo|danilo|danxilo|danzilo|dongYlo|dongilo|donilo|donxilo|donzilo",
+ encode(args, false, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, false, "Angelo"), "angilo|anxilo|ongilo|onxilo");
+ assertEquals("angilo|anxilo|ongilo|onxilo",
+ encode(args, false, "Angelo"));
assertEquals(encode(args, false, "1234"), "");
}
@@ -135,45 +167,61 @@
// concat is true, ruleType is EXACT
args = new TreeMap<>();
args.put("nameType", "SEPHARDIC");
- assertEquals(encode(args, true, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, true, "Angelo"));
args.put("ruleType", "EXACT");
- assertEquals(encode(args, true, "Angelo"), "anZelo|andZelo|anxelo");
- assertEquals(encode(args, true, "D'Angelo"), "anZelo|andZelo|anxelo");
+ assertEquals("anZelo|andZelo|anxelo",
+ encode(args, true, "Angelo"));
+ assertEquals("anZelo|andZelo|anxelo",
+ encode(args, true, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, true, "Angelo"), "andZelo|anxelo");
+ assertEquals("andZelo|anxelo",
+ encode(args, true, "Angelo"));
assertEquals(encode(args, true, "1234"), "");
// concat is false, ruleType is EXACT
args = new TreeMap<>();
args.put("nameType", "SEPHARDIC");
- assertEquals(encode(args, false, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, false, "Angelo"));
args.put("ruleType", "EXACT");
- assertEquals(encode(args, false, "Angelo"), "anZelo|andZelo|anxelo");
- assertEquals(encode(args, false, "D'Angelo"), "danZelo|dandZelo|danxelo");
+ assertEquals("anZelo|andZelo|anxelo",
+ encode(args, false, "Angelo"));
+ assertEquals("danZelo|dandZelo|danxelo",
+ encode(args, false, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, false, "Angelo"), "andZelo|anxelo");
+ assertEquals("andZelo|anxelo",
+ encode(args, false, "Angelo"));
assertEquals(encode(args, false, "1234"), "");
// concat is true, ruleType is APPROX
args = new TreeMap<>();
args.put("nameType", "SEPHARDIC");
- assertEquals(encode(args, true, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, true, "Angelo"));
args.put("ruleType", "APPROX");
- assertEquals(encode(args, true, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
- assertEquals(encode(args, true, "D'Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, true, "Angelo"));
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, true, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, true, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, true, "Angelo"));
assertEquals(encode(args, true, "1234"), "");
// concat is false, ruleType is APPROX
args = new TreeMap<>();
args.put("nameType", "SEPHARDIC");
- assertEquals(encode(args, false, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, false, "Angelo"));
args.put("ruleType", "APPROX");
- assertEquals(encode(args, false, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
- assertEquals(encode(args, false, "D'Angelo"), "danhila|danhilu|danzila|danzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, false, "Angelo"));
+ assertEquals("danhila|danhilu|danzila|danzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, false, "D'Angelo"));
args.put("languageSet", "italian,greek,spanish");
- assertEquals(encode(args, false, "Angelo"), "anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu");
+ assertEquals("anhila|anhilu|anzila|anzilu|nhila|nhilu|nzila|nzilu",
+ encode(args, false, "Angelo"));
assertEquals(encode(args, false, "1234"), "");
}
@@ -186,14 +234,18 @@
args.put("nameType", "GENERIC");
args.put("ruleType", "APPROX");
- assertEquals(encode(args, true, "abram"), "Ybram|Ybrom|abram|abran|abrom|abron|avram|avrom|obram|obran|obrom|obron|ovram|ovrom");
- assertEquals(encode(args, true, "Bendzin"), "bndzn|bntsn|bnzn|vndzn|vntsn");
+ assertEquals("Ybram|Ybrom|abram|abran|abrom|abron|avram|avrom|obram|obran|obrom|obron|ovram|ovrom",
+ encode(args, true, "abram"));
+ assertEquals("bndzn|bntsn|bnzn|vndzn|vntsn",
+ encode(args, true, "Bendzin"));
args.put("nameType", "ASHKENAZI");
args.put("ruleType", "APPROX");
- assertEquals(encode(args, true, "abram"), "Ybram|Ybrom|abram|abrom|avram|avrom|imbram|imbrom|obram|obrom|ombram|ombrom|ovram|ovrom");
- assertEquals(encode(args, true, "Halpern"), "YlpYrn|Ylpirn|alpYrn|alpirn|olpYrn|olpirn|xalpirn|xolpirn");
+ assertEquals("Ybram|Ybrom|abram|abrom|avram|avrom|imbram|imbrom|obram|obrom|ombram|ombrom|ovram|ovrom",
+ encode(args, true, "abram"));
+ assertEquals("YlpYrn|Ylpirn|alpYrn|alpirn|olpYrn|olpirn|xalpirn|xolpirn",
+ encode(args, true, "Halpern"));
}
diff --git a/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java b/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java
index 63dff24..1adae28 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java
@@ -17,84 +17,56 @@
package org.apache.commons.codec.language.bm;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
-import java.util.Arrays;
-import java.util.List;
+import java.util.stream.Stream;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests PhoneticEngine.
*
* @since 1.6
*/
-@RunWith(Parameterized.class)
public class PhoneticEngineTest {
private static final Integer TEN = Integer.valueOf(10);
- @Parameterized.Parameters(name = "{0}-{1}-{2}-{3}")
- public static List<Object[]> data() {
- return Arrays
- .asList(new Object[] { "Renault", "rinD|rinDlt|rina|rinalt|rino|rinolt|rinu|rinult", NameType.GENERIC, RuleType.APPROX, Boolean.TRUE, TEN },
- new Object[] { "Renault", "rYnDlt|rYnalt|rYnult|rinDlt|rinalt|rinolt|rinult", NameType.ASHKENAZI, RuleType.APPROX, Boolean.TRUE, TEN },
- new Object[] { "Renault", "rinDlt", NameType.ASHKENAZI, RuleType.APPROX, Boolean.TRUE, Integer.valueOf(1) },
- new Object[] { "Renault", "rinDlt", NameType.SEPHARDIC, RuleType.APPROX, Boolean.TRUE, TEN },
- new Object[] { "SntJohn-Smith", "sntjonsmit", NameType.GENERIC, RuleType.EXACT, Boolean.TRUE, TEN },
- new Object[] { "d'ortley", "(ortlaj|ortlej)-(dortlaj|dortlej)", NameType.GENERIC, RuleType.EXACT, Boolean.TRUE, TEN },
- new Object[] {
- "van helsing",
- "(elSink|elsink|helSink|helsink|helzink|xelsink)-(banhelsink|fanhelsink|fanhelzink|vanhelsink|vanhelzink|vanjelsink)",
- NameType.GENERIC,
- RuleType.EXACT,
- Boolean.FALSE, TEN },
- new Object[] {
- "Judenburg",
- "iudnbYrk|iudnbirk|iudnburk|xudnbirk|xudnburk|zudnbirk|zudnburk",
- NameType.GENERIC,
- RuleType.APPROX,
- Boolean.TRUE, TEN });
+ public static Stream<Arguments> data() {
+ return Stream.of(
+ Arguments.of("Renault", "rinD|rinDlt|rina|rinalt|rino|rinolt|rinu|rinult", NameType.GENERIC, RuleType.APPROX, Boolean.TRUE, TEN),
+ Arguments.of("Renault", "rYnDlt|rYnalt|rYnult|rinDlt|rinalt|rinolt|rinult", NameType.ASHKENAZI, RuleType.APPROX, Boolean.TRUE, TEN),
+ Arguments.of("Renault", "rinDlt", NameType.ASHKENAZI, RuleType.APPROX, Boolean.TRUE, Integer.valueOf(1)),
+ Arguments.of("Renault", "rinDlt", NameType.SEPHARDIC, RuleType.APPROX, Boolean.TRUE, TEN),
+ Arguments.of("SntJohn-Smith", "sntjonsmit", NameType.GENERIC, RuleType.EXACT, Boolean.TRUE, TEN),
+ Arguments.of("d'ortley", "(ortlaj|ortlej)-(dortlaj|dortlej)", NameType.GENERIC, RuleType.EXACT, Boolean.TRUE, TEN),
+ Arguments.of("van helsing", "(elSink|elsink|helSink|helsink|helzink|xelsink)-(banhelsink|fanhelsink|fanhelzink|vanhelsink|vanhelzink|vanjelsink)", NameType.GENERIC, RuleType.EXACT, Boolean.FALSE, TEN),
+ Arguments.of("Judenburg", "iudnbYrk|iudnbirk|iudnburk|xudnbirk|xudnburk|zudnbirk|zudnburk", NameType.GENERIC, RuleType.APPROX, Boolean.TRUE, TEN)
+ );
}
- private final boolean concat;
- private final String name;
- private final NameType nameType;
- private final String phoneticExpected;
- private final RuleType ruleType;
- private final int maxPhonemes;
+ // TODO Identify if there is a need to an assertTimeout(Duration.ofMillis(10000L) in some point, since this method was marked as @Test(timeout = 10000L)
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testEncode(final String name, final String phoneticExpected, final NameType nameType,
+ final RuleType ruleType, final boolean concat, final int maxPhonemes) {
+ final PhoneticEngine engine = new PhoneticEngine(nameType, ruleType, concat, maxPhonemes);
- public PhoneticEngineTest(final String name, final String phoneticExpected, final NameType nameType,
- final RuleType ruleType, final boolean concat, final int maxPhonemes) {
- this.name = name;
- this.phoneticExpected = phoneticExpected;
- this.nameType = nameType;
- this.ruleType = ruleType;
- this.concat = concat;
- this.maxPhonemes = maxPhonemes;
- }
+ final String phoneticActual = engine.encode(name);
- @Test(timeout = 10000L)
- public void testEncode() {
- final PhoneticEngine engine = new PhoneticEngine(this.nameType, this.ruleType, this.concat, this.maxPhonemes);
+ assertEquals(phoneticExpected, phoneticActual, "phoneme incorrect");
- final String phoneticActual = engine.encode(this.name);
-
- //System.err.println("expecting: " + this.phoneticExpected);
- //System.err.println("actual: " + phoneticActual);
- assertEquals("phoneme incorrect", this.phoneticExpected, phoneticActual);
-
- if (this.concat) {
+ if (concat) {
final String[] split = phoneticActual.split("\\|");
- assertTrue(split.length <= this.maxPhonemes);
+ assertTrue(split.length <= maxPhonemes);
} else {
final String[] words = phoneticActual.split("-");
for (final String word : words) {
final String[] split = word.split("\\|");
- assertTrue(split.length <= this.maxPhonemes);
+ assertTrue(split.length <= maxPhonemes);
}
}
}
diff --git a/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java b/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java
index d310cc4..d25cf4b 100644
--- a/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java
+++ b/src/test/java/org/apache/commons/codec/language/bm/RuleTest.java
@@ -17,12 +17,10 @@
package org.apache.commons.codec.language.bm;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import org.junit.jupiter.api.Test;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests Rule.
@@ -30,18 +28,6 @@
* @since 1.6
*/
public class RuleTest {
- private static class NegativeIntegerBaseMatcher extends BaseMatcher<Integer> {
- @Override
- public void describeTo(final Description description) {
- description.appendText("value should be negative");
- }
-
- @Override
- public boolean matches(final Object item) {
- return ((Integer) item).intValue() < 0;
- }
- }
-
private Rule.Phoneme[][] makePhonemes() {
final String[][] words = {
{ "rinD", "rinDlt", "rina", "rinalt", "rino", "rinolt", "rinu", "rinult" },
@@ -66,8 +52,8 @@
for (int j = i + 1; j < phs.length; j++) {
final int c = Rule.Phoneme.COMPARATOR.compare(phs[i], phs[j]);
- assertThat("Comparing " + phs[i].getPhonemeText() + " to " + phs[j].getPhonemeText() + " should be negative", Integer.valueOf(c),
- new NegativeIntegerBaseMatcher());
+ assertTrue(Integer.valueOf(c).intValue() < 0,
+ "Comparing " + phs[i].getPhonemeText() + " to " + phs[j].getPhonemeText() + " should be negative");
}
}
}
@@ -77,8 +63,8 @@
public void testPhonemeComparedToSelfIsZero() {
for (final Rule.Phoneme[] phs : makePhonemes()) {
for (final Rule.Phoneme ph : phs) {
- assertEquals("Phoneme compared to itself should be zero: " + ph.getPhonemeText(), 0,
- Rule.Phoneme.COMPARATOR.compare(ph, ph));
+ assertEquals(0, Rule.Phoneme.COMPARATOR.compare(ph, ph),
+ "Phoneme compared to itself should be zero: " + ph.getPhonemeText());
}
}
}
diff --git a/src/test/java/org/apache/commons/codec/net/BCodecTest.java b/src/test/java/org/apache/commons/codec/net/BCodecTest.java
index 0b85dec..276aeed 100644
--- a/src/test/java/org/apache/commons/codec/net/BCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/BCodecTest.java
@@ -17,10 +17,6 @@
package org.apache.commons.codec.net;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
@@ -28,8 +24,9 @@
import org.apache.commons.codec.CodecPolicy;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Quoted-printable codec test cases
@@ -88,15 +85,15 @@
final BCodec bcodec = new BCodec();
final String plain = "Hello there";
final String encoded = bcodec.encode(plain);
- assertEquals("Basic B encoding test", "=?UTF-8?B?SGVsbG8gdGhlcmU=?=", encoded);
- assertEquals("Basic B decoding test", plain, bcodec.decode(encoded));
+ assertEquals("=?UTF-8?B?SGVsbG8gdGhlcmU=?=", encoded, "Basic B encoding test");
+ assertEquals(plain, bcodec.decode(encoded), "Basic B decoding test");
}
@Test
public void testEncodeDecodeNull() throws Exception {
final BCodec bcodec = new BCodec();
- assertNull("Null string B encoding test", bcodec.encode((String) null));
- assertNull("Null string B decoding test", bcodec.decode((String) null));
+ assertNull(bcodec.encode((String) null), "Null string B encoding test");
+ assertNull(bcodec.decode((String) null), "Null string B decoding test");
}
@Test
@@ -104,7 +101,7 @@
final BCodec bcodec = new BCodec();
final String test = null;
final String result = bcodec.encode(test, "charset");
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -112,7 +109,7 @@
final BCodec bcodec = new BCodec();
final String test = null;
final String result = bcodec.decode(test);
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -121,12 +118,13 @@
final String plain = "what not";
final String encoded = (String) bcodec.encode((Object) plain);
- assertEquals("Basic B encoding test", "=?UTF-8?B?d2hhdCBub3Q=?=", encoded);
-
+ assertEquals("=?UTF-8?B?d2hhdCBub3Q=?=", encoded, "Basic B encoding test");
final Object result = bcodec.encode((Object) null);
- assertNull("Encoding a null Object should return null", result);
- assertThrows(EncoderException.class, () -> bcodec.encode(Double.valueOf(3.0d)));
+ assertNull(result, "Encoding a null Object should return null");
+
+ assertThrows(EncoderException.class, () -> bcodec.encode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
}
@Test
@@ -139,10 +137,9 @@
final BCodec bcodec = new BCodec();
final String decoded = "=?UTF-8?B?d2hhdCBub3Q=?=";
final String plain = (String) bcodec.decode((Object) decoded);
- assertEquals("Basic B decoding test", "what not", plain);
-
+ assertEquals("what not", plain, "Basic B decoding test");
final Object result = bcodec.decode((Object) null);
- assertNull("Decoding a null Object should return null", result);
+ assertNull(result, "Decoding a null Object should return null");
assertThrows(DecoderException.class, () -> bcodec.decode(Double.valueOf(3.0d)));
}
@@ -151,7 +148,7 @@
public void testBase64ImpossibleSamplesDefault() throws DecoderException {
final BCodec codec = new BCodec();
// Default encoding is lenient
- Assert.assertFalse(codec.isStrictDecoding());
+ assertFalse(codec.isStrictDecoding());
for (final String s : BASE64_IMPOSSIBLE_CASES) {
codec.decode(s);
}
@@ -161,7 +158,7 @@
public void testBase64ImpossibleSamplesLenient() throws DecoderException {
final BCodec codec = new BCodec(StandardCharsets.UTF_8, CodecPolicy.LENIENT);
// Default encoding is lenient
- Assert.assertFalse(codec.isStrictDecoding());
+ assertFalse(codec.isStrictDecoding());
for (final String s : BASE64_IMPOSSIBLE_CASES) {
codec.decode(s);
}
@@ -170,7 +167,7 @@
@Test
public void testBase64ImpossibleSamplesStrict() throws DecoderException {
final BCodec codec = new BCodec(StandardCharsets.UTF_8, CodecPolicy.STRICT);
- Assert.assertTrue(codec.isStrictDecoding());
+ assertTrue(codec.isStrictDecoding());
for (final String s : BASE64_IMPOSSIBLE_CASES) {
assertThrows(DecoderException.class, () -> codec.decode(s));
}
diff --git a/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java b/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java
index cf103d2..415ab32 100644
--- a/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java
@@ -17,20 +17,15 @@
package org.apache.commons.codec.net;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Percent codec test cases.
@@ -45,17 +40,17 @@
final String encodedS = new String(encoded, StandardCharsets.UTF_8);
final byte[] decoded = percentCodec.decode(encoded);
final String decodedS = new String(decoded, StandardCharsets.UTF_8);
- assertEquals("Basic PercentCodec encoding test", input, encodedS);
- assertEquals("Basic PercentCodec decoding test", input, decodedS);
+ assertEquals(input, encodedS, "Basic PercentCodec encoding test");
+ assertEquals(input, decodedS, "Basic PercentCodec decoding test");
}
@Test
- @Ignore
+ @Disabled // TODO Should be removed?
public void testBasicSpace() throws Exception {
final PercentCodec percentCodec = new PercentCodec();
final String input = " ";
final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8));
- Assert.assertArrayEquals("%20".getBytes(StandardCharsets.UTF_8), encoded);
+ assertArrayEquals("%20".getBytes(StandardCharsets.UTF_8), encoded);
}
@Test
@@ -64,9 +59,9 @@
final PercentCodec percentCodec = new PercentCodec("abcdef".getBytes(StandardCharsets.UTF_8), false);
final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8));
final String encodedS = new String(encoded, StandardCharsets.UTF_8);
- assertEquals("Configurable PercentCodec encoding test", "%61%62%63123_-.*%CE%B1%CE%B2", encodedS);
+ assertEquals("%61%62%63123_-.*%CE%B1%CE%B2", encodedS, "Configurable PercentCodec encoding test");
final byte[] decoded = percentCodec.decode(encoded);
- assertEquals("Configurable PercentCodec decoding test", new String(decoded, StandardCharsets.UTF_8), input);
+ assertEquals(new String(decoded, StandardCharsets.UTF_8), input, "Configurable PercentCodec decoding test");
}
@Test
@@ -109,11 +104,11 @@
@Test
public void testPercentEncoderDecoderWithNullOrEmptyInput() throws Exception {
final PercentCodec percentCodec = new PercentCodec(null, true);
- assertNull("Null input value encoding test", percentCodec.encode(null));
- assertNull("Null input value decoding test", percentCodec.decode(null));
+ assertNull(percentCodec.encode(null), "Null input value encoding test");
+ assertNull(percentCodec.decode(null), "Null input value decoding test");
final byte[] emptyInput = "".getBytes(StandardCharsets.UTF_8);
- assertEquals("Empty input value encoding test", percentCodec.encode(emptyInput), emptyInput);
- assertArrayEquals("Empty input value decoding test", percentCodec.decode(emptyInput), emptyInput);
+ assertEquals(percentCodec.encode(emptyInput), emptyInput, "Empty input value encoding test");
+ assertArrayEquals(percentCodec.decode(emptyInput), emptyInput, "Empty input value decoding test");
}
@Test
@@ -122,9 +117,9 @@
final PercentCodec percentCodec = new PercentCodec(null, true);
final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8));
final String encodedS = new String(encoded, StandardCharsets.UTF_8);
- assertEquals("PercentCodec plus for space encoding test", "a+b+c+d", encodedS);
+ assertEquals("a+b+c+d", encodedS, "PercentCodec plus for space encoding test");
final byte[] decode = percentCodec.decode(encoded);
- assertEquals("PercentCodec plus for space decoding test", new String(decode, StandardCharsets.UTF_8), input);
+ assertEquals(new String(decode, StandardCharsets.UTF_8), input, "PercentCodec plus for space decoding test");
}
@Test
@@ -135,8 +130,8 @@
final String encodedS = new String((byte[]) encoded, StandardCharsets.UTF_8);
final Object decoded = percentCodec.decode(encoded);
final String decodedS = new String((byte[]) decoded, StandardCharsets.UTF_8);
- assertEquals("Basic PercentCodec safe char encoding test", input, encodedS);
- assertEquals("Basic PercentCodec safe char decoding test", input, decodedS);
+ assertEquals(input, encodedS, "Basic PercentCodec safe char encoding test");
+ assertEquals(input, decodedS, "Basic PercentCodec safe char decoding test");
}
@Test
@@ -147,8 +142,8 @@
final String encodedS = new String(encoded, StandardCharsets.UTF_8);
final byte[] decoded = percentCodec.decode(encoded);
final String decodedS = new String(decoded, StandardCharsets.UTF_8);
- assertEquals("Basic PercentCodec unsafe char encoding test", "%CE%B1%CE%B2%CE%B3%CE%B4%CE%B5%CE%B6%25 ", encodedS);
- assertEquals("Basic PercentCodec unsafe char decoding test", input, decodedS);
+ assertEquals("%CE%B1%CE%B2%CE%B3%CE%B4%CE%B5%CE%B6%25 ", encodedS, "Basic PercentCodec unsafe char encoding test");
+ assertEquals(input, decodedS, "Basic PercentCodec unsafe char decoding test");
}
}
diff --git a/src/test/java/org/apache/commons/codec/net/QCodecTest.java b/src/test/java/org/apache/commons/codec/net/QCodecTest.java
index 34416d4..6e6fec2 100644
--- a/src/test/java/org/apache/commons/codec/net/QCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/QCodecTest.java
@@ -18,18 +18,14 @@
package org.apache.commons.codec.net;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-
import java.nio.charset.UnsupportedCharsetException;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Quoted-printable codec test cases
@@ -87,10 +83,8 @@
final QCodec qcodec = new QCodec();
final String plain = "= Hello there =\r\n";
final String encoded = qcodec.encode(plain);
- assertEquals("Basic Q encoding test",
- "=?UTF-8?Q?=3D Hello there =3D=0D=0A?=", encoded);
- assertEquals("Basic Q decoding test",
- plain, qcodec.decode(encoded));
+ assertEquals("=?UTF-8?Q?=3D Hello there =3D=0D=0A?=", encoded, "Basic Q encoding test");
+ assertEquals(plain, qcodec.decode(encoded), "Basic Q decoding test");
}
@Test
@@ -98,19 +92,15 @@
final QCodec qcodec = new QCodec();
final String plain = "?_=\r\n";
final String encoded = qcodec.encode(plain);
- assertEquals("Unsafe chars Q encoding test",
- "=?UTF-8?Q?=3F=5F=3D=0D=0A?=", encoded);
- assertEquals("Unsafe chars Q decoding test",
- plain, qcodec.decode(encoded));
+ assertEquals("=?UTF-8?Q?=3F=5F=3D=0D=0A?=", encoded, "Unsafe chars Q encoding test");
+ assertEquals(plain, qcodec.decode(encoded), "Unsafe chars Q decoding test");
}
@Test
public void testEncodeDecodeNull() throws Exception {
final QCodec qcodec = new QCodec();
- assertNull("Null string Q encoding test",
- qcodec.encode((String)null));
- assertNull("Null string Q decoding test",
- qcodec.decode((String)null));
+ assertNull(qcodec.encode((String)null), "Null string Q encoding test");
+ assertNull(qcodec.decode((String)null), "Null string Q decoding test");
}
@Test
@@ -118,7 +108,7 @@
final QCodec qcodec = new QCodec();
final String test = null;
final String result = qcodec.encode( test, "charset" );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -126,7 +116,7 @@
final QCodec qcodec = new QCodec();
final String test = null;
final String result = qcodec.decode( test );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@@ -135,12 +125,12 @@
final QCodec qcodec = new QCodec();
final String plain = "1+1 = 2";
final String encoded = (String) qcodec.encode((Object) plain);
- assertEquals("Basic Q encoding test", "=?UTF-8?Q?1+1 =3D 2?=", encoded);
+ assertEquals("=?UTF-8?Q?1+1 =3D 2?=", encoded, "Basic Q encoding test");
final Object result = qcodec.encode((Object) null);
- assertNull("Encoding a null Object should return null", result);
-
- assertThrows(EncoderException.class, () -> qcodec.encode(Double.valueOf(3.0d)));
+ assertNull(result, "Encoding a null Object should return null");
+ assertThrows(EncoderException.class, () -> qcodec.encode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
}
@@ -154,12 +144,12 @@
final QCodec qcodec = new QCodec();
final String decoded = "=?UTF-8?Q?1+1 =3D 2?=";
final String plain = (String) qcodec.decode((Object) decoded);
- assertEquals("Basic Q decoding test", "1+1 = 2", plain);
+ assertEquals("1+1 = 2", plain, "Basic Q decoding test");
final Object result = qcodec.decode((Object) null);
- assertNull("Decoding a null Object should return null", result);
-
- assertThrows(DecoderException.class, () -> qcodec.decode(Double.valueOf(3.0d)));
+ assertNull(result, "Decoding a null Object should return null");
+ assertThrows(DecoderException.class, () -> qcodec.decode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
}
@@ -171,14 +161,14 @@
final QCodec qcodec = new QCodec();
qcodec.setEncodeBlanks(false);
String s = qcodec.encode(plain);
- assertEquals("Blanks encoding with the Q codec test", encoded1, s);
+ assertEquals(encoded1, s, "Blanks encoding with the Q codec test");
qcodec.setEncodeBlanks(true);
s = qcodec.encode(plain);
- assertEquals("Blanks encoding with the Q codec test", encoded2, s);
+ assertEquals(encoded2, s, "Blanks encoding with the Q codec test");
s = qcodec.decode(encoded1);
- assertEquals("Blanks decoding with the Q codec test", plain, s);
+ assertEquals(plain, s, "Blanks decoding with the Q codec test");
s = qcodec.decode(encoded2);
- assertEquals("Blanks decoding with the Q codec test", plain, s);
+ assertEquals(plain, s, "Blanks decoding with the Q codec test");
}
diff --git a/src/test/java/org/apache/commons/codec/net/QuotedPrintableCodecTest.java b/src/test/java/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
index 3035008..36ad0f6 100644
--- a/src/test/java/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
@@ -17,15 +17,15 @@
package org.apache.commons.codec.net;
-import static org.junit.Assert.*;
-
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Quoted-printable codec test cases
@@ -75,10 +75,8 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "= Hello there =\r\n";
final String encoded = qpcodec.encode(plain);
- assertEquals("Basic quoted-printable encoding test",
- "=3D Hello there =3D=0D=0A", encoded);
- assertEquals("Basic quoted-printable decoding test",
- plain, qpcodec.decode(encoded));
+ assertEquals("=3D Hello there =3D=0D=0A", encoded, "Basic quoted-printable encoding test");
+ assertEquals(plain, qpcodec.decode(encoded), "Basic quoted-printable decoding test");
}
@Test
@@ -86,10 +84,8 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "abc123_-.*~!@#$%^&()+{}\"\\;:`,/[]";
final String encoded = qpcodec.encode(plain);
- assertEquals("Safe chars quoted-printable encoding test",
- plain, encoded);
- assertEquals("Safe chars quoted-printable decoding test",
- plain, qpcodec.decode(encoded));
+ assertEquals(plain, encoded, "Safe chars quoted-printable encoding test");
+ assertEquals(plain, qpcodec.decode(encoded), "Safe chars quoted-printable decoding test");
}
@@ -98,24 +94,20 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "=\r\n";
final String encoded = qpcodec.encode(plain);
- assertEquals("Unsafe chars quoted-printable encoding test",
- "=3D=0D=0A", encoded);
- assertEquals("Unsafe chars quoted-printable decoding test",
- plain, qpcodec.decode(encoded));
+ assertEquals("=3D=0D=0A", encoded, "Unsafe chars quoted-printable encoding test");
+ assertEquals(plain, qpcodec.decode(encoded), "Unsafe chars quoted-printable decoding test");
}
@Test
public void testEncodeDecodeNull() throws Exception {
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
- assertNull("Null string quoted-printable encoding test",
- qpcodec.encode((String)null));
- assertNull("Null string quoted-printable decoding test",
- qpcodec.decode((String)null));
+ assertNull(qpcodec.encode((String)null), "Null string quoted-printable encoding test");
+ assertNull(qpcodec.decode((String)null), "Null string quoted-printable decoding test");
}
@Test
- public void testDecodeInvalid() throws Exception {
+ public void testDecodeInvalid() {
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
assertThrows(DecoderException.class, () -> qpcodec.decode("="));
assertThrows(DecoderException.class, () -> qpcodec.decode("=A"));
@@ -127,7 +119,7 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final byte[] plain = null;
final byte[] encoded = qpcodec.encode(plain);
- assertNull("Encoding a null string should return null", encoded);
+ assertNull(encoded, "Encoding a null string should return null");
}
@Test
@@ -136,18 +128,15 @@
final String plain = "1+1 = 2";
final String encoded = new String(QuotedPrintableCodec.
encodeQuotedPrintable(null, plain.getBytes(StandardCharsets.UTF_8)));
- assertEquals("Basic quoted-printable encoding test",
- "1+1 =3D 2", encoded);
- assertEquals("Basic quoted-printable decoding test",
- plain, qpcodec.decode(encoded));
-
+ assertEquals("1+1 =3D 2", encoded, "Basic quoted-printable encoding test");
+ assertEquals(plain, qpcodec.decode(encoded), "Basic quoted-printable decoding test");
}
@Test
public void testDecodeWithNullArray() throws Exception {
final byte[] plain = null;
final byte[] result = QuotedPrintableCodec.decodeQuotedPrintable( plain );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -155,7 +144,7 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String test = null;
final String result = qpcodec.encode( test, "charset" );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -163,7 +152,7 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String test = null;
final String result = qpcodec.decode( test, "charset" );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -171,17 +160,18 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "1+1 = 2";
String encoded = (String) qpcodec.encode((Object) plain);
- assertEquals("Basic quoted-printable encoding test", "1+1 =3D 2", encoded);
+ assertEquals("1+1 =3D 2", encoded, "Basic quoted-printable encoding test");
final byte[] plainBA = plain.getBytes(StandardCharsets.UTF_8);
final byte[] encodedBA = (byte[]) qpcodec.encode((Object) plainBA);
encoded = new String(encodedBA);
- assertEquals("Basic quoted-printable encoding test", "1+1 =3D 2", encoded);
+ assertEquals("1+1 =3D 2", encoded, "Basic quoted-printable encoding test");
final Object result = qpcodec.encode((Object) null);
- assertNull("Encoding a null Object should return null", result);
+ assertNull(result, "Encoding a null Object should return null");
- assertThrows(EncoderException.class, () -> qpcodec.encode(Double.valueOf(3.0d)));
+ assertThrows(EncoderException.class, () -> qpcodec.encode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
}
@Test
@@ -194,19 +184,18 @@
final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
final String plain = "1+1 =3D 2";
String decoded = (String) qpcodec.decode((Object) plain);
- assertEquals("Basic quoted-printable decoding test",
- "1+1 = 2", decoded);
+ assertEquals("1+1 = 2", decoded, "Basic quoted-printable decoding test");
final byte[] plainBA = plain.getBytes(StandardCharsets.UTF_8);
final byte[] decodedBA = (byte[]) qpcodec.decode((Object) plainBA);
decoded = new String(decodedBA);
- assertEquals("Basic quoted-printable decoding test",
- "1+1 = 2", decoded);
+ assertEquals("1+1 = 2", decoded, "Basic quoted-printable decoding test");
final Object result = qpcodec.decode((Object) null);
- assertNull("Decoding a null Object should return null", result);
+ assertNull(result, "Decoding a null Object should return null");
- assertThrows(DecoderException.class, () -> qpcodec.decode(Double.valueOf(3.0d)));
+ assertThrows(DecoderException.class, () -> qpcodec.decode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
}
@Test
diff --git a/src/test/java/org/apache/commons/codec/net/RFC1522CodecTest.java b/src/test/java/org/apache/commons/codec/net/RFC1522CodecTest.java
index 8a6baf3..978cd1c 100644
--- a/src/test/java/org/apache/commons/codec/net/RFC1522CodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/RFC1522CodecTest.java
@@ -17,12 +17,12 @@
package org.apache.commons.codec.net;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.codec.DecoderException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* RFC 1522 compliant codec test cases
diff --git a/src/test/java/org/apache/commons/codec/net/URLCodecTest.java b/src/test/java/org/apache/commons/codec/net/URLCodecTest.java
index 73b3d10..08bbf22 100644
--- a/src/test/java/org/apache/commons/codec/net/URLCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/URLCodecTest.java
@@ -17,17 +17,15 @@
package org.apache.commons.codec.net;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* URL codec test cases
@@ -83,10 +81,8 @@
final URLCodec urlCodec = new URLCodec();
final String plain = "Hello there!";
final String encoded = urlCodec.encode(plain);
- assertEquals("Basic URL encoding test",
- "Hello+there%21", encoded);
- assertEquals("Basic URL decoding test",
- plain, urlCodec.decode(encoded));
+ assertEquals("Hello+there%21", encoded, "Basic URL encoding test");
+ assertEquals(plain, urlCodec.decode(encoded), "Basic URL decoding test");
this.validateState(urlCodec);
}
@@ -96,10 +92,8 @@
final URLCodec urlCodec = new URLCodec();
final String plain = "abc123_-.*";
final String encoded = urlCodec.encode(plain);
- assertEquals("Safe chars URL encoding test",
- plain, encoded);
- assertEquals("Safe chars URL decoding test",
- plain, urlCodec.decode(encoded));
+ assertEquals(plain, encoded, "Safe chars URL encoding test");
+ assertEquals(plain, urlCodec.decode(encoded), "Safe chars URL decoding test");
this.validateState(urlCodec);
}
@@ -109,10 +103,8 @@
final URLCodec urlCodec = new URLCodec();
final String plain = "~!@#$%^&()+{}\"\\;:`,/[]";
final String encoded = urlCodec.encode(plain);
- assertEquals("Unsafe chars URL encoding test",
- "%7E%21%40%23%24%25%5E%26%28%29%2B%7B%7D%22%5C%3B%3A%60%2C%2F%5B%5D", encoded);
- assertEquals("Unsafe chars URL decoding test",
- plain, urlCodec.decode(encoded));
+ assertEquals("%7E%21%40%23%24%25%5E%26%28%29%2B%7B%7D%22%5C%3B%3A%60%2C%2F%5B%5D", encoded, "Unsafe chars URL encoding test");
+ assertEquals(plain, urlCodec.decode(encoded), "Unsafe chars URL decoding test");
this.validateState(urlCodec);
}
@@ -120,10 +112,8 @@
@Test
public void testEncodeDecodeNull() throws Exception {
final URLCodec urlCodec = new URLCodec();
- assertNull("Null string URL encoding test",
- urlCodec.encode((String)null));
- assertNull("Null string URL decoding test",
- urlCodec.decode((String)null));
+ assertNull(urlCodec.encode((String)null), "Null string URL encoding test");
+ assertNull(urlCodec.decode((String)null), "Null string URL decoding test");
this.validateState(urlCodec);
}
@@ -134,7 +124,7 @@
assertThrows(DecoderException.class, () -> urlCodec.decode("%"));
assertThrows(DecoderException.class, () -> urlCodec.decode("%A"));
// Bad 1st char after %
- assertThrows(DecoderException.class, () -> urlCodec.decode("%A"));
+ assertThrows(DecoderException.class, () -> urlCodec.decode("%WW"));
// Bad 2nd char after %
assertThrows(DecoderException.class, () -> urlCodec.decode("%0W"));
this.validateState(urlCodec);
@@ -158,7 +148,7 @@
final URLCodec urlCodec = new URLCodec();
final byte[] plain = null;
final byte[] encoded = urlCodec.encode(plain);
- assertNull("Encoding a null string should return null", encoded);
+ assertNull(encoded, "Encoding a null string should return null");
this.validateState(urlCodec);
}
@@ -167,10 +157,8 @@
final URLCodec urlCodec = new URLCodec();
final String plain = "Hello there!";
final String encoded = new String( URLCodec.encodeUrl(null, plain.getBytes(StandardCharsets.UTF_8)));
- assertEquals("Basic URL encoding test",
- "Hello+there%21", encoded);
- assertEquals("Basic URL decoding test",
- plain, urlCodec.decode(encoded));
+ assertEquals("Hello+there%21", encoded, "Basic URL encoding test");
+ assertEquals(plain, urlCodec.decode(encoded), "Basic URL decoding test");
this.validateState(urlCodec);
}
@@ -178,7 +166,7 @@
public void testDecodeWithNullArray() throws Exception {
final byte[] plain = null;
final byte[] result = URLCodec.decodeUrl( plain );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -186,7 +174,7 @@
final URLCodec urlCodec = new URLCodec();
final String test = null;
final String result = urlCodec.encode( test, "charset" );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -194,7 +182,7 @@
final URLCodec urlCodec = new URLCodec();
final String test = null;
final String result = urlCodec.decode( test, "charset" );
- assertNull("Result should be null", result);
+ assertNull(result, "Result should be null");
}
@Test
@@ -202,18 +190,18 @@
final URLCodec urlCodec = new URLCodec();
final String plain = "Hello there!";
String encoded = (String) urlCodec.encode((Object) plain);
- assertEquals("Basic URL encoding test", "Hello+there%21", encoded);
+ assertEquals("Hello+there%21", encoded, "Basic URL encoding test");
final byte[] plainBA = plain.getBytes(StandardCharsets.UTF_8);
final byte[] encodedBA = (byte[]) urlCodec.encode((Object) plainBA);
encoded = new String(encodedBA);
- assertEquals("Basic URL encoding test", "Hello+there%21", encoded);
+ assertEquals("Hello+there%21", encoded, "Basic URL encoding test");
final Object result = urlCodec.encode((Object) null);
- assertNull("Encoding a null Object should return null", result);
+ assertNull(result, "Encoding a null Object should return null");
- assertThrows(EncoderException.class, () -> urlCodec.encode(Double.valueOf(3.0d)));
-
+ assertThrows(EncoderException.class, () -> urlCodec.encode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
this.validateState(urlCodec);
}
@@ -221,8 +209,8 @@
public void testInvalidEncoding() {
final URLCodec urlCodec = new URLCodec("NONSENSE");
final String plain = "Hello there!";
- assertThrows("We set the encoding to a bogus NONSENSE value", EncoderException.class, () -> urlCodec.encode(plain));
- assertThrows("We set the encoding to a bogus NONSENSE value", DecoderException.class, () -> urlCodec.decode(plain));
+ assertThrows(EncoderException.class, () -> urlCodec.encode(plain), "We set the encoding to a bogus NONSENSE value");
+ assertThrows(DecoderException.class, () -> urlCodec.decode(plain), "We set the encoding to a bogus NONSENSE value");
this.validateState(urlCodec);
}
@@ -231,20 +219,17 @@
final URLCodec urlCodec = new URLCodec();
final String plain = "Hello+there%21";
String decoded = (String) urlCodec.decode((Object) plain);
- assertEquals("Basic URL decoding test",
- "Hello there!", decoded);
-
+ assertEquals("Hello there!", decoded, "Basic URL decoding test");
final byte[] plainBA = plain.getBytes(StandardCharsets.UTF_8);
final byte[] decodedBA = (byte[]) urlCodec.decode((Object) plainBA);
decoded = new String(decodedBA);
- assertEquals("Basic URL decoding test",
- "Hello there!", decoded);
-
+ assertEquals("Hello there!", decoded, "Basic URL decoding test");
final Object result = urlCodec.decode((Object) null);
- assertNull("Decoding a null Object should return null", result);
- assertThrows(DecoderException.class, () -> urlCodec.decode(Double.valueOf(3.0d)));
+ assertNull(result, "Decoding a null Object should return null");
+ assertThrows(DecoderException.class, () -> urlCodec.decode(Double.valueOf(3.0d)),
+ "Trying to url encode a Double object should cause an exception.");
this.validateState(urlCodec);
}
diff --git a/src/test/java/org/apache/commons/codec/net/UtilsTest.java b/src/test/java/org/apache/commons/codec/net/UtilsTest.java
index dfb2af3..50378f0 100644
--- a/src/test/java/org/apache/commons/codec/net/UtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/net/UtilsTest.java
@@ -17,7 +17,8 @@
package org.apache.commons.codec.net;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
/**
* Tests Utils.