Skip to content

Commit

Permalink
Eliminate older junit dependency (#437)
Browse files Browse the repository at this point in the history
The older junit dependency is still configured in the pom.xml mvn
file as a dependency. This update removes this dependency and migrates
all codes to junit jupiter framework. In particular the following
changes were made.

1. The `pom.xml` file was updated to remove the junit dependency. It
was replaced by just the hamcrest portion of the features that are used
in the project.

1. All imports are now being done from the `org.junit.jupiter.api`
package instead of `org.junit`.

1. Various assertions required the message string to be last argument
to the method instead of first.

Back-ported from: #410

Signed-off-by: Jason Katonica <[email protected]>
  • Loading branch information
jasonkatonica authored Feb 5, 2025
1 parent 2a5dbc2 commit 91331ab
Show file tree
Hide file tree
Showing 104 changed files with 896 additions and 979 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
87 changes: 37 additions & 50 deletions src/test/java/ibm/jceplus/junit/base/BaseTestAES.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class BaseTestAES extends BaseTestCipher {

Expand Down Expand Up @@ -795,29 +795,27 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
byte[] newPlainText = cp.doFinal(cipherText);

boolean success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);

// Verify the text again
cp.init(Cipher.DECRYPT_MODE, key, params);
byte[] newPlainText2 = cp.doFinal(cipherText, 0, cipherText.length);
success = Arrays.equals(newPlainText2, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand All @@ -839,10 +837,9 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify the text
Expand All @@ -859,12 +856,11 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti
System.arraycopy(newPlainText2, 0, newPlainText, l, newPlainText2.length);

boolean success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand All @@ -888,10 +884,9 @@ protected void encryptDecryptPartialUpdate(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify the text
Expand All @@ -908,13 +903,11 @@ protected void encryptDecryptPartialUpdate(String algorithm,
System.arraycopy(newPlainText2, 0, newPlainText, l, newPlainText2.length);

boolean success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, partial msglen=" + message.length,
success);
assertTrue(success, "Decrypted text does not match expected, partial msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand All @@ -938,32 +931,30 @@ protected void encryptDecryptReuseObject(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify that the cipher object can be used to encrypt again without re-init
byte[] cipherText2 = cp.doFinal(message);
boolean success = Arrays.equals(cipherText2, cipherText);
assertTrue("Re-encrypted text does not match", success);
assertTrue(success, "Re-encrypted text does not match");

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
byte[] newPlainText = cp.doFinal(cipherText);
success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);

// Verify that the cipher object can be used to decrypt again without re-init
byte[] newPlainText2 = cp.doFinal(cipherText, 0, cipherText.length);
success = Arrays.equals(newPlainText2, newPlainText);
assertTrue("Re-decrypted text does not match", success);
assertTrue(success, "Re-decrypted text does not match");
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand Down Expand Up @@ -992,14 +983,13 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

boolean success = Arrays.equals(cipherText, cipherText0);
assertTrue("Encrypted text does not match expected result", success);
assertTrue(success, "Encrypted text does not match expected result");

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
Expand All @@ -1008,12 +998,11 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm,
byte[] newPlainText = Arrays.copyOf(resultBuffer, resultLen);

success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand Down Expand Up @@ -1045,14 +1034,13 @@ protected void encryptDecryptUpdateCopySafe(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

boolean success = Arrays.equals(cipherText, cipherText0);
assertTrue("Encrypted text does not match expected result", success);
assertTrue(success, "Encrypted text does not match expected result");

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
Expand All @@ -1065,12 +1053,11 @@ protected void encryptDecryptUpdateCopySafe(String algorithm,
System.arraycopy(plainText2, 0, newPlainText, plainText1Len, plainText2.length);

success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand Down
Loading

0 comments on commit 91331ab

Please sign in to comment.