From 994ac87ae66616608b3d7512d9b70f540bf6f719 Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 9 Aug 2024 14:34:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=B1Ju?= =?UTF-8?q?nit4=E5=8F=98=E6=9B=B4=E4=B8=BAJunit5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/cn/hutool/crypto/KeyUtilTest.java | 13 ++++++++----- .../java/cn/hutool/crypto/asymmetric/SM2Test.java | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) 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); + }); } }