From be112bc91f28da5374ba22daf1595eef7d4ab708 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 1 Sep 2024 18:50:05 -0400 Subject: [PATCH] Use Assertions.assertInstanceOf() --- .../java/org/apache/commons/crypto/NativeCodeLoaderTest.java | 3 ++- src/test/java/org/apache/commons/crypto/OsInfoTest.java | 3 ++- .../org/apache/commons/crypto/cipher/AbstractCipherTest.java | 3 ++- .../java/org/apache/commons/crypto/cipher/GcmCipherTest.java | 3 ++- .../apache/commons/crypto/jna/OpenSslJnaCryptoRandomTest.java | 4 ++-- .../apache/commons/crypto/random/JavaCryptoRandomTest.java | 4 ++-- .../apache/commons/crypto/random/OpenSslCryptoRandomTest.java | 4 ++-- .../org/apache/commons/crypto/random/OsCryptoRandomTest.java | 4 ++-- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java b/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java index 780de58a5..17cb27de2 100644 --- a/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java +++ b/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java @@ -18,6 +18,7 @@ package org.apache.commons.crypto; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -80,7 +81,7 @@ public void testUnSuccessfulLoad() throws Exception { System.setProperty(Crypto.LIB_NAME_KEY, empty.getFileName().toString()); final Throwable result = NativeCodeLoader.loadLibrary(); assertNotNull(result); - assertTrue(result instanceof UnsatisfiedLinkError); + assertInstanceOf(UnsatisfiedLinkError.class, result); } finally { Files.delete(empty); if (nameKey != null) { diff --git a/src/test/java/org/apache/commons/crypto/OsInfoTest.java b/src/test/java/org/apache/commons/crypto/OsInfoTest.java index f1b9f10b7..23b71359e 100644 --- a/src/test/java/org/apache/commons/crypto/OsInfoTest.java +++ b/src/test/java/org/apache/commons/crypto/OsInfoTest.java @@ -17,9 +17,10 @@ */ package org.apache.commons.crypto; -import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; + public class OsInfoTest { private static final String EXPECTED_PATH_PROPERTY = "OsInfoTest.expectedPath"; diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java index 286db59ab..a45bda9ae 100644 --- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java +++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java @@ -34,13 +34,14 @@ import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; -import jakarta.xml.bind.DatatypeConverter; import org.apache.commons.crypto.utils.AES; import org.apache.commons.crypto.utils.ReflectionUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import jakarta.xml.bind.DatatypeConverter; + public abstract class AbstractCipherTest { public static final String OPENSSL_CIPHER_CLASSNAME = OpenSslCipher.class.getName(); diff --git a/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java index 05f6a5fbf..3c28f5f38 100644 --- a/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java +++ b/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java @@ -30,13 +30,14 @@ import javax.crypto.AEADBadTagException; import javax.crypto.Cipher; import javax.crypto.spec.GCMParameterSpec; -import jakarta.xml.bind.DatatypeConverter; import org.apache.commons.crypto.utils.AES; import org.apache.commons.crypto.utils.Utils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import jakarta.xml.bind.DatatypeConverter; + public class GcmCipherTest { private static final String GCM_NO_PADDING = "AES/GCM/NoPadding"; diff --git a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandomTest.java index 9d0f30807..96ef918f9 100644 --- a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandomTest.java +++ b/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandomTest.java @@ -17,7 +17,7 @@ */ package org.apache.commons.crypto.jna; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import java.security.GeneralSecurityException; import java.util.Properties; @@ -35,7 +35,7 @@ public CryptoRandom getCryptoRandom() throws GeneralSecurityException { final Properties props = new Properties(); props.setProperty(CryptoRandomFactory.CLASSES_KEY, OpenSslJnaCryptoRandom.class.getName()); final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props); - assertTrue(random instanceof OpenSslJnaCryptoRandom, "The CryptoRandom should be: " + OpenSslJnaCryptoRandom.class.getName()); + assertInstanceOf(OpenSslJnaCryptoRandom.class, random, "The CryptoRandom should be: " + OpenSslJnaCryptoRandom.class.getName()); return random; } diff --git a/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java index 6ad26d4aa..359d669a7 100644 --- a/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java +++ b/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java @@ -17,7 +17,7 @@ */ package org.apache.commons.crypto.random; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import java.security.GeneralSecurityException; import java.util.Properties; @@ -29,7 +29,7 @@ public CryptoRandom getCryptoRandom() throws GeneralSecurityException { final Properties props = new Properties(); props.setProperty(CryptoRandomFactory.CLASSES_KEY, JavaCryptoRandom.class.getName()); final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props); - assertTrue(random instanceof JavaCryptoRandom, "The CryptoRandom should be: " + JavaCryptoRandom.class.getName()); + assertInstanceOf(JavaCryptoRandom.class, random, "The CryptoRandom should be: " + JavaCryptoRandom.class.getName()); return random; } diff --git a/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java index f2443d527..09dac85ae 100644 --- a/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java +++ b/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java @@ -17,7 +17,7 @@ */ package org.apache.commons.crypto.random; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.security.GeneralSecurityException; @@ -39,7 +39,7 @@ public CryptoRandom getCryptoRandom() throws GeneralSecurityException { final Properties props = new Properties(); props.setProperty(CryptoRandomFactory.CLASSES_KEY, OpenSslCryptoRandom.class.getName()); final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props); - assertTrue(random instanceof OpenSslCryptoRandom, "The CryptoRandom should be: " + OpenSslCryptoRandom.class.getName()); + assertInstanceOf(OpenSslCryptoRandom.class, random, "The CryptoRandom should be: " + OpenSslCryptoRandom.class.getName()); return random; } diff --git a/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java index 0d85e7f09..9a7c4ac63 100644 --- a/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java +++ b/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java @@ -18,8 +18,8 @@ package org.apache.commons.crypto.random; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.FileNotFoundException; @@ -39,7 +39,7 @@ public CryptoRandom getCryptoRandom() throws GeneralSecurityException { final Properties props = new Properties(); props.setProperty(CryptoRandomFactory.CLASSES_KEY, OsCryptoRandom.class.getName()); final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props); - assertTrue(random instanceof OsCryptoRandom, "The CryptoRandom should be: " + OsCryptoRandom.class.getName()); + assertInstanceOf(OsCryptoRandom.class, random, "The CryptoRandom should be: " + OsCryptoRandom.class.getName()); return random; }