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

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