Now we are using JUnit4, can use expected=throwable.class for simple failure checks
Note: not suitable for cases where an earlier statement can generate the same exception. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1387417 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
77d33a665a
commit
8cb5f67c58
|
@ -18,7 +18,6 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
|
@ -105,25 +104,17 @@ public class CompareToBuilderTest {
|
|||
assertTrue(CompareToBuilder.reflectionCompare(o2, o1) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testReflectionCompareEx1() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
try {
|
||||
CompareToBuilder.reflectionCompare(o1, null);
|
||||
} catch (NullPointerException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
CompareToBuilder.reflectionCompare(o1, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void testReflectionCompareEx2() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
Object o2 = new Object();
|
||||
try {
|
||||
CompareToBuilder.reflectionCompare(o1, o2);
|
||||
fail();
|
||||
} catch (ClassCastException ex) {}
|
||||
CompareToBuilder.reflectionCompare(o1, o2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -295,14 +286,11 @@ public class CompareToBuilderTest {
|
|||
assertTrue(new CompareToBuilder().append(null, o1).build().intValue() < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void testObjectEx2() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
Object o2 = new Object();
|
||||
try {
|
||||
new CompareToBuilder().append(o1, o2);
|
||||
fail();
|
||||
} catch (ClassCastException ex) {}
|
||||
new CompareToBuilder().append(o1, o2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.lang3.builder;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -1014,15 +1012,12 @@ public class ToStringBuilderTest {
|
|||
/**
|
||||
* Tests ReflectionToStringBuilder setUpToClass().
|
||||
*/
|
||||
@Test
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_setUpToClass_invalid() {
|
||||
Integer val = Integer.valueOf(5);
|
||||
ReflectionToStringBuilder test = new ReflectionToStringBuilder(val);
|
||||
try {
|
||||
test.setUpToClass(String.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
} finally {
|
||||
test.toString();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.commons.lang3.concurrent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -38,14 +37,9 @@ public class CallableBackgroundInitializerTest {
|
|||
* Tries to create an instance without a Callable. This should cause an
|
||||
* exception.
|
||||
*/
|
||||
@Test
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testInitNullCallable() {
|
||||
try {
|
||||
new CallableBackgroundInitializer<Object>(null);
|
||||
fail("Could create instance without a Callable!");
|
||||
} catch (IllegalArgumentException iex) {
|
||||
// ok
|
||||
}
|
||||
new CallableBackgroundInitializer<Object>(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,15 +58,10 @@ public class CallableBackgroundInitializerTest {
|
|||
* Tries to pass a null Callable to the constructor that takes an executor.
|
||||
* This should cause an exception.
|
||||
*/
|
||||
@Test
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testInitExecutorNullCallable() {
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
new CallableBackgroundInitializer<Integer>(null, exec);
|
||||
fail("Could create instance without a Callable!");
|
||||
} catch (IllegalArgumentException iex) {
|
||||
// ok
|
||||
}
|
||||
new CallableBackgroundInitializer<Integer>(null, exec);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue