You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/12/09 20:09:27 UTC
[commons-crypto] branch master updated: Use try-with-resources
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
The following commit(s) were added to refs/heads/master by this push:
new 58ed69f Use try-with-resources
58ed69f is described below
commit 58ed69fea171f9fc9acf395db2df8539987aedf6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 9 15:09:23 2022 -0500
Use try-with-resources
---
.../commons/crypto/cipher/CryptoCipherFactoryTest.java | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
index 3132b0d..69f49f1 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
@@ -20,6 +20,7 @@ package org.apache.commons.crypto.cipher;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Properties;
@@ -41,16 +42,17 @@ public class CryptoCipherFactoryTest {
}
@Test
- public void testEmptyCipher() throws GeneralSecurityException {
+ public void testEmptyCipher() throws GeneralSecurityException, IOException {
final Properties properties = new Properties();
properties.setProperty(CryptoCipherFactory.CLASSES_KEY, ""); // TODO should this really mean use the default?
- final CryptoCipher defaultCipher = CryptoCipherFactory.getCryptoCipher(
- AES.CBC_NO_PADDING, properties);
- final String name = defaultCipher.getClass().getName();
- if (OpenSsl.getLoadingFailureReason() == null) {
- assertEquals(OpenSslCipher.class.getName(), name);
- } else {
- assertEquals(JceCipher.class.getName(), name);
+ try (CryptoCipher defaultCipher = CryptoCipherFactory.getCryptoCipher(
+ AES.CBC_NO_PADDING, properties)) {
+ final String name = defaultCipher.getClass().getName();
+ if (OpenSsl.getLoadingFailureReason() == null) {
+ assertEquals(OpenSslCipher.class.getName(), name);
+ } else {
+ assertEquals(JceCipher.class.getName(), name);
+ }
}
}