From 28daf04ae265d03b49f4ae7b05a16b075a105e4a Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sat, 11 Jan 2014 19:39:21 +0000 Subject: [PATCH] Use annotation based testing for failure cases git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1557446 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang3/RandomUtilsTest.java | 95 +++++++++---------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java index eb0049799..3adedbab1 100644 --- a/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java @@ -34,56 +34,51 @@ public class RandomUtilsTest { * For comparing doubles and floats */ private static final double DELTA = 1e-5; - - /** - * Tests exceptions - */ - @Test - public void testExceptions() throws Exception { - try { - RandomUtils.nextBytes(-1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextInt(2, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextDouble(2, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextLong(2, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextFloat(2, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextInt(-1, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextDouble(-1, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextLong(-1, 1); - fail(); - } catch (IllegalArgumentException e) {} - - try { - RandomUtils.nextFloat(-1, 1); - fail(); - } catch (IllegalArgumentException e) {} + + + @Test(expected = IllegalArgumentException.class) + public void testNextBytesNegative() throws Exception { + RandomUtils.nextBytes(-1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextIntNegative() throws Exception { + RandomUtils.nextInt(-1, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextLongNegative() throws Exception { + RandomUtils.nextLong(-1, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextDoubleNegative() throws Exception { + RandomUtils.nextDouble(-1, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextFloatNegative() throws Exception { + RandomUtils.nextFloat(-1, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextIntLowerGreaterUpper() throws Exception { + RandomUtils.nextInt(2, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextLongLowerGreaterUpper() throws Exception { + RandomUtils.nextLong(2, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextDoubleLowerGreaterUpper() throws Exception { + RandomUtils.nextDouble(2, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testNextFloatLowerGreaterUpper() throws Exception { + RandomUtils.nextFloat(2, 1); } /**