This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 80fffec CODEC-285 replace JUnit v4 test expected with assertThrows
(#112)
80fffec is described below
commit 80fffec4ee9d44a18a4742d53971ed054b1346e6
Author: John Patrick <[email protected]>
AuthorDate: Sun Feb 20 00:27:32 2022 +0000
CODEC-285 replace JUnit v4 test expected with assertThrows (#112)
---
.../commons/codec/BinaryEncoderAbstractTest.java | 2 +-
.../codec/binary/Base16InputStreamTest.java | 4 +-
.../apache/commons/codec/binary/Base16Test.java | 12 +++---
.../codec/binary/Base32InputStreamTest.java | 4 +-
.../codec/binary/Base64InputStreamTest.java | 4 +-
.../apache/commons/codec/binary/Base64Test.java | 6 +--
.../commons/codec/binary/BaseNCodecTest.java | 5 ++-
.../org/apache/commons/codec/binary/HexTest.java | 16 ++++----
.../org/apache/commons/codec/cli/DigestTest.java | 17 ++++----
.../apache/commons/codec/digest/Apr1CryptTest.java | 13 ++++---
.../org/apache/commons/codec/digest/CryptTest.java | 5 ++-
.../commons/codec/digest/DigestUtilsTest.java | 5 ++-
.../commons/codec/digest/HmacAlgorithmsTest.java | 38 +++++++++---------
.../apache/commons/codec/digest/HmacUtilsTest.java | 45 +++++++++++-----------
.../apache/commons/codec/digest/Md5CryptTest.java | 9 +++--
.../commons/codec/digest/Sha256CryptTest.java | 9 +++--
.../commons/codec/digest/Sha512CryptTest.java | 13 ++++---
.../apache/commons/codec/digest/UnixCryptTest.java | 17 ++++----
.../codec/language/ColognePhoneticTest.java | 8 ++--
.../codec/language/bm/BeiderMorseEncoderTest.java | 21 +++++-----
.../org/apache/commons/codec/net/BCodecTest.java | 4 +-
.../apache/commons/codec/net/PercentCodecTest.java | 13 ++++---
.../org/apache/commons/codec/net/QCodecTest.java | 4 +-
.../codec/net/QuotedPrintableCodecTest.java | 4 +-
.../apache/commons/codec/net/RFC1522CodecTest.java | 2 +-
25 files changed, 146 insertions(+), 134 deletions(-)
diff --git
a/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
b/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
index 0780375..bf96e33 100644
--- a/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
+++ b/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
@@ -34,7 +34,7 @@ public abstract class BinaryEncoderAbstractTest {
}
@Test
- public void testEncodeNull() throws Exception {
+ public void testEncodeNull() {
assertThrows(EncoderException.class, () -> makeEncoder().encode(null));
}
}
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 9b1edb8..14d56b0 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base16InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base16InputStreamTest.java
@@ -403,11 +403,11 @@ public class Base16InputStreamTest {
*
* @throws IOException for some failure scenarios.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testSkipWrongArgument() throws IOException {
final InputStream ins = new
ByteArrayInputStream(StringUtils.getBytesIso8859_1(ENCODED_B16));
try (final Base16InputStream b16Stream = new Base16InputStream(ins)) {
- b16Stream.skip(-10);
+ assertThrows(IllegalArgumentException.class, () ->
b16Stream.skip(-10));
}
}
}
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 4f99a82..e957673 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base16Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base16Test.java
@@ -97,11 +97,11 @@ public class Base16Test {
* isBase16 throws RuntimeException on some
* non-Base16 bytes
*/
- @Test(expected=RuntimeException.class)
+ @Test
public void testCodec68() {
final byte[] x = { 'n', 'H', '=', '=', (byte) 0x9c };
final Base16 b16 = new Base16();
- b16.decode(x);
+ assertThrows(RuntimeException.class, () -> b16.decode(x));
}
@Test
@@ -460,10 +460,10 @@ public class Base16Test {
return buf.toString();
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void checkEncodeLengthBounds() {
final Base16 base16 = new Base16();
- base16.encode(new byte[10], 0, 1 << 30);
+ assertThrows(IllegalArgumentException.class, () -> base16.encode(new
byte[10], 0, 1 << 30));
}
@Test
@@ -565,13 +565,13 @@ public class Base16Test {
assertEquals((byte)0xEF, context.buffer[0]);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testStrictDecoding() {
final String encoded = "aabbccdde"; // Note the trailing `e` which
does not make up a hex-pair and so is only 1/2 byte
final Base16 b16 = new Base16(true, CodecPolicy.STRICT);
assertEquals(CodecPolicy.STRICT, b16.getCodecPolicy());
- b16.decode(StringUtils.getBytesUtf8(encoded));
+ assertThrows(IllegalArgumentException.class, () ->
b16.decode(StringUtils.getBytesUtf8(encoded)));
}
@Test
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 5f686b5..06deca8 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
@@ -523,11 +523,11 @@ public class Base32InputStreamTest {
* @throws Throwable
* for some failure scenarios.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testSkipWrongArgument() throws Throwable {
final InputStream ins = new
ByteArrayInputStream(StringUtils.getBytesIso8859_1(ENCODED_FOO));
try (final Base32InputStream b32stream = new Base32InputStream(ins)) {
- b32stream.skip(-10);
+ assertThrows(IllegalArgumentException.class, () ->
b32stream.skip(-10));
}
}
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 294a90b..0472b99 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
@@ -562,11 +562,11 @@ public class Base64InputStreamTest {
* @throws Throwable
* for some failure scenarios.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testSkipWrongArgument() throws Throwable {
final InputStream ins = new
ByteArrayInputStream(StringUtils.getBytesIso8859_1(ENCODED_B64));
try (final Base64InputStream b64stream = new Base64InputStream(ins)) {
- b64stream.skip(-10);
+ assertThrows(IllegalArgumentException.class, () ->
b64stream.skip(-10));
}
}
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 d4e8611..c7730e9 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
@@ -422,7 +422,7 @@ public class Base64Test {
Base64.encodeBase64(in, false, false, out.length);
}
- private void testEncodeOverMaxSize(final int maxSize) throws Exception {
+ private void testEncodeOverMaxSize(final int maxSize) {
assertThrows(IllegalArgumentException.class, () ->
Base64.encodeBase64(BaseNTestData.DECODED, true, false, maxSize));
}
@@ -521,7 +521,7 @@ public class Base64Test {
}
@Test
- public void testObjectDecodeWithInvalidParameter() throws Exception {
+ public void testObjectDecodeWithInvalidParameter() {
assertThrows(DecoderException.class, () -> new
Base64().decode(Integer.valueOf(5)));
}
@@ -540,7 +540,7 @@ public class Base64Test {
}
@Test
- public void testObjectEncodeWithInvalidParameter() throws Exception {
+ public void testObjectEncodeWithInvalidParameter() {
assertThrows(EncoderException.class, () -> new
Base64().encode("Yadayadayada"));
}
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 3b89c4d..f17feed 100644
--- a/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java
@@ -21,6 +21,7 @@ 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;
@@ -356,7 +357,7 @@ public class BaseNCodecTest {
return Runtime.getRuntime().maxMemory() - allocatedMemory;
}
- @Test(expected = OutOfMemoryError.class)
+ @Test
public void testEnsureBufferSizeThrowsOnOverflow() {
final BaseNCodec ncodec = new NoOpBaseNCodec();
final Context context = new Context();
@@ -365,7 +366,7 @@ public class BaseNCodecTest {
context.buffer = new byte[length];
context.pos = length;
final int extra = Integer.MAX_VALUE;
- ncodec.ensureBufferSize(extra, context);
+ assertThrows(OutOfMemoryError.class, () ->
ncodec.ensureBufferSize(extra, context));
}
/**
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 ff4b04c..0aa78d2 100644
--- a/src/test/java/org/apache/commons/codec/binary/HexTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/HexTest.java
@@ -192,9 +192,9 @@ public class HexTest {
assertEquals(name, sourceString, actualStringFromBytes);
}
- @Test(expected = UnsupportedCharsetException.class)
+ @Test
public void testCustomCharsetBadName() {
- new Hex(BAD_ENCODING_NAME);
+ assertThrows(UnsupportedCharsetException.class, () -> new
Hex(BAD_ENCODING_NAME));
}
@Test
@@ -298,16 +298,16 @@ public class HexTest {
checkDecodeHexCharArrayOddCharacters(new char[] { 'A', 'B', 'C', 'D',
'E' });
}
- @Test(expected = DecoderException.class)
- public void testDecodeHexCharArrayOutBufferUnderSized() throws
DecoderException {
+ @Test
+ public void testDecodeHexCharArrayOutBufferUnderSized() {
final byte[] out = new byte[4];
- Hex.decodeHex("aabbccddeeff".toCharArray(), out, 0);
+ assertThrows(DecoderException.class, () ->
Hex.decodeHex("aabbccddeeff".toCharArray(), out, 0));
}
- @Test(expected = DecoderException.class)
- public void testDecodeHexCharArrayOutBufferUnderSizedByOffset() throws
DecoderException {
+ @Test
+ public void testDecodeHexCharArrayOutBufferUnderSizedByOffset() {
final byte[] out = new byte[6];
- Hex.decodeHex("aabbccddeeff".toCharArray(), out, 1);
+ assertThrows(DecoderException.class, () ->
Hex.decodeHex("aabbccddeeff".toCharArray(), out, 1));
}
@Test
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 e5d279b..6b7ccc2 100644
--- a/src/test/java/org/apache/commons/codec/cli/DigestTest.java
+++ b/src/test/java/org/apache/commons/codec/cli/DigestTest.java
@@ -21,6 +21,7 @@ import org.junit.Test;
import java.io.IOException;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests {@link Digest}.
@@ -31,20 +32,16 @@ public class DigestTest {
/**
* Tests if empty arguments are handled correctly.
- *
- * @throws IllegalArgumentException for some failure scenarios.
*/
- @Test(expected = IllegalArgumentException.class)
- public void testEmptyArguments() throws IOException {
- Digest.main(new String[0]);
+ @Test
+ public void testEmptyArguments() {
+ assertThrows(IllegalArgumentException.class, () -> Digest.main(new
String[0]));
}
/**
* Tests if null arguments are handled correctly.
- *
- * @throws IllegalArgumentException for some failure scenarios.
*/
- @Test(expected = IllegalArgumentException.class)
- public void testNullArguments() throws IOException {
- Digest.main(null);
+ @Test
+ public void testNullArguments() {
+ assertThrows(IllegalArgumentException.class, () -> Digest.main(null));
}
}
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 5571476..55ae16a 100644
--- a/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java
@@ -19,6 +19,7 @@ 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;
@@ -87,14 +88,14 @@ public class Apr1CryptTest {
assertEquals("$apr1$12345678$0lqb/6VUFP8JY/s/jTrIk0",
Md5Crypt.apr1Crypt("secret", "12345678901234567890"));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testApr1CryptNullData() {
- Md5Crypt.apr1Crypt((byte[]) null);
+ assertThrows(NullPointerException.class, () ->
Md5Crypt.apr1Crypt((byte[]) null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testApr1CryptWithEmptySalt() {
- Md5Crypt.apr1Crypt("secret".getBytes(), "");
+ assertThrows(IllegalArgumentException.class, () ->
Md5Crypt.apr1Crypt("secret".getBytes(), ""));
}
@Test
@@ -106,8 +107,8 @@ public class Apr1CryptTest {
assertNotSame(hash, hash2);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testApr1CryptWithInvalidSalt() {
- Md5Crypt.apr1Crypt(new byte[0], "!");
+ assertThrows(IllegalArgumentException.class, () ->
Md5Crypt.apr1Crypt(new byte[0], "!"));
}
}
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 a896649..8633200 100644
--- a/src/test/java/org/apache/commons/codec/digest/CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/CryptTest.java
@@ -19,6 +19,7 @@ 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;
@@ -50,9 +51,9 @@ public class CryptTest {
* as NULL. Our implementation should throw an Exception as any resulting
* hash would not be verifyable with other implementations of crypt().
*/
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testCryptWithEmptySalt() {
- Crypt.crypt("secret", "");
+ assertThrows(IllegalArgumentException.class, () ->
Crypt.crypt("secret", ""));
}
}
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 d33747f..a27ac67 100644
--- a/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
@@ -23,6 +23,7 @@ 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 java.io.ByteArrayInputStream;
import java.io.File;
@@ -134,9 +135,9 @@ public class DigestUtilsTest {
assertEquals(MessageDigestAlgorithms.MD5,
digestUtils.getMessageDigest().getAlgorithm());
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testInternalNoSuchAlgorithmException() {
- DigestUtils.getDigest("Bogus Bogus");
+ assertThrows(IllegalArgumentException.class, () ->
DigestUtils.getDigest("Bogus Bogus"));
}
@Test
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 fecb7c5..0538670 100644
--- a/src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java
@@ -37,6 +37,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* Tests {@link HmacAlgorithms}.
*
@@ -143,44 +145,44 @@ public class HmacAlgorithmsTest {
Mac.getInstance(algorithm);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testGetHmacEmptyKey() {
- HmacUtils.getInitializedMac(hmacAlgorithm, EMPTY_BYTE_ARRAY);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getInitializedMac(hmacAlgorithm, EMPTY_BYTE_ARRAY));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testGetHmacNullKey() {
- HmacUtils.getInitializedMac(hmacAlgorithm, null);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getInitializedMac(hmacAlgorithm, null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testHmacFailByteArray() {
- new HmacUtils(hmacAlgorithm, (byte[])
null).hmac(STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () -> new
HmacUtils(hmacAlgorithm, (byte[]) null).hmac(STANDARD_PHRASE_BYTES));
}
- @Test(expected = IllegalArgumentException.class)
- public void testHmacFailInputStream() throws IOException {
- new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new
ByteArrayInputStream(STANDARD_PHRASE_BYTES));
+ @Test
+ public void testHmacFailInputStream() {
+ assertThrows(IllegalArgumentException.class, () -> new
HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new
ByteArrayInputStream(STANDARD_PHRASE_BYTES)));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testHmacFailString() {
- new HmacUtils(hmacAlgorithm, (String)
null).hmac(STANDARD_PHRASE_STRING);
+ assertThrows(IllegalArgumentException.class, () -> new
HmacUtils(hmacAlgorithm, (String) null).hmac(STANDARD_PHRASE_STRING));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testHmacHexFailByteArray() {
- new HmacUtils(hmacAlgorithm, (byte[])
null).hmac(STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () -> new
HmacUtils(hmacAlgorithm, (byte[]) null).hmac(STANDARD_PHRASE_BYTES));
}
- @Test(expected = IllegalArgumentException.class)
- public void testHmacHexFailInputStream() throws IOException {
- new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new
ByteArrayInputStream(STANDARD_PHRASE_BYTES));
+ @Test
+ public void testHmacHexFailInputStream() {
+ assertThrows(IllegalArgumentException.class, () -> new
HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new
ByteArrayInputStream(STANDARD_PHRASE_BYTES)));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testHmacHexFailString() {
- new HmacUtils(hmacAlgorithm, (String)
null).hmac(STANDARD_PHRASE_STRING);
+ assertThrows(IllegalArgumentException.class, () -> new
HmacUtils(hmacAlgorithm, (String) null).hmac(STANDARD_PHRASE_STRING));
}
@Test
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 aa9d11e..4808e12 100644
--- a/src/test/java/org/apache/commons/codec/digest/HmacUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/HmacUtilsTest.java
@@ -17,6 +17,7 @@
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;
@@ -36,9 +37,9 @@ import org.junit.Test;
public class HmacUtilsTest {
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testEmptyKey() {
- HmacUtils.getHmacMd5(new byte[] {});
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getHmacMd5(new byte[] {}));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
@@ -121,19 +122,19 @@ public class HmacUtilsTest {
.doFinal());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInitializedMacNullAlgo() {
- HmacUtils.getInitializedMac((String) null,
HmacAlgorithmsTest.STANDARD_KEY_BYTES);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getInitializedMac((String) null,
HmacAlgorithmsTest.STANDARD_KEY_BYTES));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInitializedMacNullKey() {
- HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, null);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInternalNoSuchAlgorithmException() {
- HmacUtils.getInitializedMac("Bogus Bogus",
StringUtils.getBytesUtf8("akey"));
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getInitializedMac("Bogus Bogus", StringUtils.getBytesUtf8("akey")));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
@@ -153,20 +154,20 @@ public class HmacUtilsTest {
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testMd5HMacFail() {
- HmacUtils.hmacMd5((byte[]) null,
HmacAlgorithmsTest.STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.hmacMd5((byte[]) null, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNullKey() {
- HmacUtils.getHmacMd5(null);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.getHmacMd5(null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSecretKeySpecAllowsEmtyKeys() {
- new SecretKeySpec(new byte[] {}, "HmacMD5");
+ assertThrows(IllegalArgumentException.class, () -> new
SecretKeySpec(new byte[] {}, "HmacMD5"));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
@@ -187,9 +188,9 @@ public class HmacUtilsTest {
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha1HMacFail() {
- HmacUtils.hmacSha1((byte[]) null,
HmacAlgorithmsTest.STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.hmacSha1((byte[]) null, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
@@ -210,9 +211,9 @@ public class HmacUtilsTest {
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha256HMacFail() {
- HmacUtils.hmacSha256((byte[]) null,
HmacAlgorithmsTest.STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.hmacSha256((byte[]) null, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
@@ -233,9 +234,9 @@ public class HmacUtilsTest {
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha384HMacFail() {
- HmacUtils.hmacSha384((byte[]) null,
HmacAlgorithmsTest.STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.hmacSha384((byte[]) null, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
@@ -256,8 +257,8 @@ public class HmacUtilsTest {
}
@SuppressWarnings("deprecation") // most of the static methods are
deprecated
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha512HMacFail() {
- HmacUtils.hmacSha512((byte[]) null,
HmacAlgorithmsTest.STANDARD_PHRASE_BYTES);
+ assertThrows(IllegalArgumentException.class, () ->
HmacUtils.hmacSha512((byte[]) null, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
}
}
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 21401f3..8fa4c18 100644
--- a/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java
@@ -19,6 +19,7 @@ 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;
@@ -73,13 +74,13 @@ public class Md5CryptTest {
assertEquals("$1$1234$MoxekaNNUgfPRVqoeYjCD/",
Crypt.crypt("12345678901234567890", "$1$1234"));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testMd5CryptNullData() {
- Md5Crypt.md5Crypt((byte[]) null);
+ assertThrows(NullPointerException.class, () ->
Md5Crypt.md5Crypt((byte[]) null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testMd5CryptWithEmptySalt() {
- Md5Crypt.md5Crypt("secret".getBytes(), "");
+ assertThrows(IllegalArgumentException.class, () ->
Md5Crypt.md5Crypt("secret".getBytes(), ""));
}
}
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 f609012..0d1d0bb 100644
--- a/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java
@@ -18,6 +18,7 @@ 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 java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -73,14 +74,14 @@ public class Sha256CryptTest {
assertTrue(Sha2Crypt.sha256Crypt("secret".getBytes(),
null).matches("^\\$5\\$[a-zA-Z0-9./]{0,16}\\$.{1,}$"));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testSha256CryptNullData() {
- Sha2Crypt.sha256Crypt((byte[]) null);
+ assertThrows(NullPointerException.class, () ->
Sha2Crypt.sha256Crypt((byte[]) null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha256CryptWithEmptySalt() {
- Sha2Crypt.sha256Crypt("secret".getBytes(), "");
+ assertThrows(IllegalArgumentException.class, () ->
Sha2Crypt.sha256Crypt("secret".getBytes(), ""));
}
@Test
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 4f488b4..b29c4c5 100644
--- a/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java
@@ -18,6 +18,7 @@ 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 java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -63,9 +64,9 @@ public class Sha512CryptTest {
assertTrue(Sha2Crypt.sha512Crypt("secret".getBytes(), null,
threadLocalRandom).matches("^\\$6\\$[a-zA-Z0-9./]{0,16}\\$.{1,}$"));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testSha512CryptNullData() {
- Sha2Crypt.sha512Crypt((byte[]) null);
+ assertThrows(NullPointerException.class, () ->
Sha2Crypt.sha512Crypt((byte[]) null));
}
@Ignore
@@ -82,14 +83,14 @@ public class Sha512CryptTest {
assertEquals("$5$rounds=9999$abcd$Rh/8ngVh9oyuS6lL3.fsq.9xbvXJsfyKWxSjO2mPIa7",
Sha2Crypt.sha256Crypt("secret".getBytes(StandardCharsets.UTF_8),
"$5$rounds=9999$abcd"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha2CryptWrongSalt() {
- Sha2Crypt.sha512Crypt("secret".getBytes(StandardCharsets.UTF_8), "xx");
+ assertThrows(IllegalArgumentException.class, () ->
Sha2Crypt.sha512Crypt("secret".getBytes(StandardCharsets.UTF_8), "xx"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSha512CryptWithEmptySalt() {
- Sha2Crypt.sha512Crypt("secret".getBytes(), "");
+ assertThrows(IllegalArgumentException.class, () ->
Sha2Crypt.sha512Crypt("secret".getBytes(), ""));
}
@Test
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 466adcb..77cf939 100644
--- a/src/test/java/org/apache/commons/codec/digest/UnixCryptTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/UnixCryptTest.java
@@ -20,6 +20,7 @@ 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 java.nio.charset.StandardCharsets;
@@ -70,27 +71,27 @@ public class UnixCryptTest {
* E.g. with glibc 2.13, crypt("secret", "x") = "xxZREZpkHZpkI" but
* crypt("secret", "xx") = "xxWAum7tHdIUw" which makes it unverifyable.
*/
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testUnixCryptWithHalfSalt() {
- UnixCrypt.crypt("secret", "x");
+ assertThrows(IllegalArgumentException.class, () ->
UnixCrypt.crypt("secret", "x"));
}
/**
* Unimplemented "$foo$" salt prefixes would be threated as UnixCrypt salt.
*/
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testUnicCryptInvalidSalt() {
- UnixCrypt.crypt("secret", "$a");
+ assertThrows(IllegalArgumentException.class, () ->
UnixCrypt.crypt("secret", "$a"));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testUnixCryptNullData() {
- UnixCrypt.crypt((byte[]) null);
+ assertThrows(NullPointerException.class, () ->
UnixCrypt.crypt((byte[]) null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testUnixCryptWithEmptySalt() {
- UnixCrypt.crypt("secret", "");
+ assertThrows(IllegalArgumentException.class, () ->
UnixCrypt.crypt("secret", ""));
}
@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 98e904e..fcae367 100644
--- a/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java
+++ b/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java
@@ -27,6 +27,8 @@ import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* Tests the {@code ColognePhonetic} class.
*
@@ -96,10 +98,10 @@ public class ColognePhoneticTest extends
StringEncoderAbstractTest<ColognePhonet
return new ColognePhonetic();
}
- @Test(expected=org.junit.ComparisonFailure.class)
+ @Test
// Ensure that override still allows tests to work
- public void testCanFail() throws EncoderException {
- this.checkEncoding("/", "Fehler");
+ public void testCanFail() {
+ assertThrows(org.junit.ComparisonFailure.class, () ->
this.checkEncoding("/", "Fehler"));
}
@Test
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 aba399c..4d9f930 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
@@ -20,6 +20,7 @@ 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;
@@ -108,19 +109,19 @@ public class BeiderMorseEncoderTest extends
StringEncoderAbstractTest<StringEnco
bmpm.encode("gna");
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidLangIllegalArgumentException() {
- Rule.getInstance(NameType.GENERIC, RuleType.APPROX, "noSuchLanguage");
+ assertThrows(IllegalArgumentException.class, () ->
Rule.getInstance(NameType.GENERIC, RuleType.APPROX, "noSuchLanguage"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidLangIllegalStateException() {
- Lang.loadFromResource("thisIsAMadeUpResourceName",
Languages.getInstance(NameType.GENERIC));
+ assertThrows(IllegalArgumentException.class, () ->
Lang.loadFromResource("thisIsAMadeUpResourceName",
Languages.getInstance(NameType.GENERIC)));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidLanguageIllegalArgumentException() {
- Languages.getInstance("thereIsNoSuchLanguage");
+ assertThrows(IllegalArgumentException.class, () ->
Languages.getInstance("thereIsNoSuchLanguage"));
}
@Test(timeout = 10000L)
@@ -129,10 +130,10 @@ public class BeiderMorseEncoderTest extends
StringEncoderAbstractTest<StringEnco
bmpm.encode("MacGhilleseatheanaich");
}
- @Test(expected = IndexOutOfBoundsException.class)
+ @Test
public void testNegativeIndexForRuleMatchIndexOutOfBoundsException() {
final Rule r = new Rule("a", "", "", new Rule.Phoneme("",
Languages.ANY_LANGUAGE));
- r.patternAndContextMatches("bob", -1);
+ assertThrows(IndexOutOfBoundsException.class, () ->
r.patternAndContextMatches("bob", -1));
}
@Test
@@ -174,10 +175,10 @@ public class BeiderMorseEncoderTest extends
StringEncoderAbstractTest<StringEnco
assertEquals("Rule type should have been set to exact",
RuleType.EXACT, bmpm.getRuleType());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSetRuleTypeToRulesIllegalArgumentException() {
final BeiderMorseEncoder bmpm = new BeiderMorseEncoder();
- bmpm.setRuleType(RuleType.RULES);
+ assertThrows(IllegalArgumentException.class, () ->
bmpm.setRuleType(RuleType.RULES));
}
/**
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 a3abc13..0b85dec 100644
--- a/src/test/java/org/apache/commons/codec/net/BCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/BCodecTest.java
@@ -129,9 +129,9 @@ public class BCodecTest {
assertThrows(EncoderException.class, () ->
bcodec.encode(Double.valueOf(3.0d)));
}
- @Test(expected=UnsupportedCharsetException.class)
+ @Test
public void testInvalidEncoding() {
- new BCodec("NONSENSE");
+ assertThrows(UnsupportedCharsetException.class, () -> new
BCodec("NONSENSE"));
}
@Test
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 3e2e7f1..cf103d2 100644
--- a/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java
@@ -21,6 +21,7 @@ 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;
@@ -87,10 +88,10 @@ public class PercentCodecTest {
assertNull(percentCodec.decode((Object) null));
}
- @Test(expected = DecoderException.class)
- public void testDecodeUnsupportedObject() throws Exception {
+ @Test
+ public void testDecodeUnsupportedObject() {
final PercentCodec percentCodec = new PercentCodec();
- percentCodec.decode("test");
+ assertThrows(DecoderException.class, () ->
percentCodec.decode("test"));
}
@Test
@@ -99,10 +100,10 @@ public class PercentCodecTest {
assertNull(percentCodec.encode((Object) null));
}
- @Test(expected = EncoderException.class)
- public void testEncodeUnsupportedObject() throws Exception {
+ @Test
+ public void testEncodeUnsupportedObject() {
final PercentCodec percentCodec = new PercentCodec();
- percentCodec.encode("test");
+ assertThrows(EncoderException.class, () ->
percentCodec.encode("test"));
}
@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 566c8d6..34416d4 100644
--- a/src/test/java/org/apache/commons/codec/net/QCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/QCodecTest.java
@@ -144,9 +144,9 @@ public class QCodecTest {
}
- @Test(expected=UnsupportedCharsetException.class)
+ @Test
public void testInvalidEncoding() {
- new QCodec("NONSENSE");
+ assertThrows(UnsupportedCharsetException.class, () -> new
QCodec("NONSENSE"));
}
@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 94149f4..3035008 100644
--- a/src/test/java/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
@@ -184,9 +184,9 @@ public class QuotedPrintableCodecTest {
assertThrows(EncoderException.class, () ->
qpcodec.encode(Double.valueOf(3.0d)));
}
- @Test(expected=UnsupportedCharsetException.class)
+ @Test
public void testInvalidEncoding() {
- new QuotedPrintableCodec("NONSENSE");
+ assertThrows(UnsupportedCharsetException.class, () -> new
QuotedPrintableCodec("NONSENSE"));
}
@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 5ec4dec..8a6baf3 100644
--- a/src/test/java/org/apache/commons/codec/net/RFC1522CodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/RFC1522CodecTest.java
@@ -56,7 +56,7 @@ public class RFC1522CodecTest {
assertNull(testcodec.encodeText(null, CharEncoding.UTF_8));
}
- private void assertExpectedDecoderException(final String s) throws
Exception {
+ private void assertExpectedDecoderException(final String s) {
assertThrows(DecoderException.class, () -> new
RFC1522TestCodec().decodeText(s));
}