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
This commit is contained in:
Benedikt Ritter 2014-01-11 19:39:21 +00:00
parent 5f8d99694b
commit 28daf04ae2
1 changed files with 45 additions and 50 deletions

View File

@ -35,55 +35,50 @@ public class RandomUtilsTest {
*/ */
private static final double DELTA = 1e-5; private static final double DELTA = 1e-5;
/**
* Tests exceptions
*/
@Test
public void testExceptions() throws Exception {
try {
RandomUtils.nextBytes(-1);
fail();
} catch (IllegalArgumentException e) {}
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextInt(2, 1); public void testNextBytesNegative() throws Exception {
fail(); RandomUtils.nextBytes(-1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextDouble(2, 1); public void testNextIntNegative() throws Exception {
fail(); RandomUtils.nextInt(-1, 1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextLong(2, 1); public void testNextLongNegative() throws Exception {
fail(); RandomUtils.nextLong(-1, 1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextFloat(2, 1); public void testNextDoubleNegative() throws Exception {
fail(); RandomUtils.nextDouble(-1, 1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextInt(-1, 1); public void testNextFloatNegative() throws Exception {
fail(); RandomUtils.nextFloat(-1, 1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextDouble(-1, 1); public void testNextIntLowerGreaterUpper() throws Exception {
fail(); RandomUtils.nextInt(2, 1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextLong(-1, 1); public void testNextLongLowerGreaterUpper() throws Exception {
fail(); RandomUtils.nextLong(2, 1);
} catch (IllegalArgumentException e) {} }
try { @Test(expected = IllegalArgumentException.class)
RandomUtils.nextFloat(-1, 1); public void testNextDoubleLowerGreaterUpper() throws Exception {
fail(); RandomUtils.nextDouble(2, 1);
} catch (IllegalArgumentException e) {} }
@Test(expected = IllegalArgumentException.class)
public void testNextFloatLowerGreaterUpper() throws Exception {
RandomUtils.nextFloat(2, 1);
} }
/** /**