Skip to content

Commit

Permalink
Use Assertions.assertInstanceOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 1, 2024
1 parent 8c7bb8a commit be112bc
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/crypto/OsInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit be112bc

Please sign in to comment.