diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java index b2038ddff..8d8b14fca 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java @@ -1,6 +1,5 @@ package cn.hutool.crypto; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -8,17 +7,21 @@ import java.security.KeyPair; import java.security.PrivateKey; import java.security.PublicKey; +import static org.junit.jupiter.api.Assertions.*; + public class KeyUtilTest { /** * 测试关闭BouncyCastle支持时是否会正常抛出异常,即关闭是否有效 */ - @Test(expected = CryptoException.class) + @Test @Disabled public void generateKeyPairTest() { - GlobalBouncyCastleProvider.setUseBouncyCastle(false); - KeyPair pair = KeyUtil.generateKeyPair("SM2"); - assertNotNull(pair); + assertThrows(CryptoException.class, () -> { + GlobalBouncyCastleProvider.setUseBouncyCastle(false); + KeyPair pair = KeyUtil.generateKeyPair("SM2"); + assertNotNull(pair); + }); } @Test diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java index 60053ce03..bc8065cc4 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java @@ -12,7 +12,6 @@ import org.bouncycastle.crypto.DataLengthException; import org.bouncycastle.crypto.engines.SM2Engine; import org.bouncycastle.crypto.params.ECPrivateKeyParameters; import org.bouncycastle.jcajce.spec.OpenSSHPrivateKeySpec; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; @@ -20,6 +19,8 @@ import java.security.KeyPair; import java.security.PrivateKey; import java.security.PublicKey; +import static org.junit.jupiter.api.Assertions.*; + /** * SM2算法单元测试 * @@ -338,10 +339,12 @@ public class SM2Test { new SM2(null, publicKey); } - @Test(expected = DataLengthException.class) + @Test public void issueIA824PTest() { - SM2 sm2 = SmUtil.sm2(); - String emptyStr = ""; - sm2.encryptHex(emptyStr, KeyType.PublicKey); + assertThrows(DataLengthException.class, () -> { + SM2 sm2 = SmUtil.sm2(); + String emptyStr = ""; + sm2.encryptHex(emptyStr, KeyType.PublicKey); + }); } }