Author: sebb
Date: Wed Sep 19 00:31:53 2012
New Revision: 1387417
URL: http://svn.apache.org/viewvc?rev=1387417&view=rev
Log:
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.
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java?rev=1387417&r1=1387416&r2=1387417&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
(original)
+++
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
Wed Sep 19 00:31:53 2012
@@ -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
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java?rev=1387417&r1=1387416&r2=1387417&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
(original)
+++
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
Wed Sep 19 00:31:53 2012
@@ -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();
}
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java?rev=1387417&r1=1387416&r2=1387417&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
(original)
+++
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/CallableBackgroundInitializerTest.java
Wed Sep 19 00:31:53 2012
@@ -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 CallableBackgroundInitializ
* 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 CallableBackgroundInitializ
* 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);
}
/**