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 48ae8fe Sort members 48ae8fe is described below commit 48ae8fe43039fa13451a883ba12590ae25c86c56 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Dec 12 07:03:24 2022 -0500 Sort members --- .../crypto/random/CryptoRandomFactoryTest.java | 102 ++++++++++----------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java index dbaa567..c3b08d5 100644 --- a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java +++ b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java @@ -32,15 +32,12 @@ import org.junit.jupiter.api.Test; public class CryptoRandomFactoryTest { @Test - public void testNull() { - assertThrows(NullPointerException.class, () -> CryptoRandomFactory.getCryptoRandom(null)); - } - - @Test - public void testEmpty() throws Exception { + public void testAbstractRandom() { final Properties props = new Properties(); - props.setProperty(CryptoRandomFactory.CLASSES_KEY, ""); - CryptoRandomFactory.getCryptoRandom(props).close(); + props.setProperty(CryptoRandomFactory.CLASSES_KEY, AbstractRandom.class.getName()); + final Exception ex = assertThrows(GeneralSecurityException.class, () -> CryptoRandomFactory.getCryptoRandom(props)); + final String message = ex.getMessage(); + assertTrue(message.contains("InstantiationException"), message); } @Test @@ -57,16 +54,42 @@ public class CryptoRandomFactoryTest { } @Test - public void testGetOSRandom() throws GeneralSecurityException, IOException { - // Windows does not have a /dev/random device - assumeTrue(!System.getProperty("os.name").contains("Windows")); - final Properties props = new Properties(); - props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OS.getClassName()); - try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props)) { - assertEquals(OsCryptoRandom.class.getName(), random.getClass().getName()); + public void testDefaultRandomClass() throws GeneralSecurityException, IOException { + try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom()) { + assertEquals(OpenSslCryptoRandom.class.getName(), random.getClass().getName()); } } + @Test + public void testDummmyRandom() { + final Properties props = new Properties(); + props.setProperty(CryptoRandomFactory.CLASSES_KEY, DummyRandom.class.getName()); + final Exception ex = assertThrows(GeneralSecurityException.class, () -> CryptoRandomFactory.getCryptoRandom(props)); + final String message = ex.getMessage(); + assertTrue(message.contains("NoSuchMethodException"), message); + } + + @Test + public void testEmpty() throws Exception { + final Properties props = new Properties(); + props.setProperty(CryptoRandomFactory.CLASSES_KEY, ""); + CryptoRandomFactory.getCryptoRandom(props).close(); + } + + @Test + public void testFailingRandom() { + final Properties props = new Properties(); + props.setProperty(CryptoRandomFactory.CLASSES_KEY, FailingRandom.class.getName()); + final Exception ex = assertThrows(GeneralSecurityException.class, () -> CryptoRandomFactory.getCryptoRandom(props)); + + Throwable cause = ex.getCause(); + assertEquals(IllegalArgumentException.class, cause.getClass()); + cause = cause.getCause(); + assertEquals(InvocationTargetException.class, cause.getClass()); + cause = cause.getCause(); + assertEquals(UnsatisfiedLinkError.class, cause.getClass()); + } + @Test public void testFullClassName() throws GeneralSecurityException, IOException { final Properties props = new Properties(); @@ -76,6 +99,17 @@ public class CryptoRandomFactoryTest { } } + @Test + public void testGetOSRandom() throws GeneralSecurityException, IOException { + // Windows does not have a /dev/random device + assumeTrue(!System.getProperty("os.name").contains("Windows")); + final Properties props = new Properties(); + props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OS.getClassName()); + try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props)) { + assertEquals(OsCryptoRandom.class.getName(), random.getClass().getName()); + } + } + @Test public void testInvalidRandom() { final Properties properties = new Properties(); @@ -93,31 +127,6 @@ public class CryptoRandomFactoryTest { } } - @Test - public void testDefaultRandomClass() throws GeneralSecurityException, IOException { - try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom()) { - assertEquals(OpenSslCryptoRandom.class.getName(), random.getClass().getName()); - } - } - - @Test - public void testAbstractRandom() { - final Properties props = new Properties(); - props.setProperty(CryptoRandomFactory.CLASSES_KEY, AbstractRandom.class.getName()); - final Exception ex = assertThrows(GeneralSecurityException.class, () -> CryptoRandomFactory.getCryptoRandom(props)); - final String message = ex.getMessage(); - assertTrue(message.contains("InstantiationException"), message); - } - - @Test - public void testDummmyRandom() { - final Properties props = new Properties(); - props.setProperty(CryptoRandomFactory.CLASSES_KEY, DummyRandom.class.getName()); - final Exception ex = assertThrows(GeneralSecurityException.class, () -> CryptoRandomFactory.getCryptoRandom(props)); - final String message = ex.getMessage(); - assertTrue(message.contains("NoSuchMethodException"), message); - } - @Test public void testNoClasses() { final Properties props = new Properties(); @@ -128,17 +137,8 @@ public class CryptoRandomFactoryTest { } @Test - public void testFailingRandom() { - final Properties props = new Properties(); - props.setProperty(CryptoRandomFactory.CLASSES_KEY, FailingRandom.class.getName()); - final Exception ex = assertThrows(GeneralSecurityException.class, () -> CryptoRandomFactory.getCryptoRandom(props)); - - Throwable cause = ex.getCause(); - assertEquals(IllegalArgumentException.class, cause.getClass()); - cause = cause.getCause(); - assertEquals(InvocationTargetException.class, cause.getClass()); - cause = cause.getCause(); - assertEquals(UnsatisfiedLinkError.class, cause.getClass()); + public void testNull() { + assertThrows(NullPointerException.class, () -> CryptoRandomFactory.getCryptoRandom(null)); } }