diff --git a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java index f5f63012c..78c7ba9e2 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java @@ -156,15 +156,10 @@ public class BackgroundInitializerTest { /** * Tests calling get() before start(). This should cause an exception. */ - @Test + @Test(expected=IllegalStateException.class) public void testGetBeforeStart() throws ConcurrentException { BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl(); - try { - init.get(); - fail("Could call get() before start()!"); - } catch (IllegalStateException istex) { - // ok - } + init.get(); } /** diff --git a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java index 40ab46411..1d58ca19f 100644 --- a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java +++ b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java @@ -43,34 +43,18 @@ import org.junit.Test; */ public class EventListenerSupportTest { - @Test + @Test(expected=NullPointerException.class) public void testAddNullListener() { EventListenerSupport listenerSupport = EventListenerSupport.create(VetoableChangeListener.class); - try - { - listenerSupport.addListener(null); - fail("Should not be able to add a null listener."); - } - catch (NullPointerException e) - { - - } + listenerSupport.addListener(null); } - @Test + @Test(expected=NullPointerException.class) public void testRemoveNullListener() { EventListenerSupport listenerSupport = EventListenerSupport.create(VetoableChangeListener.class); - try - { - listenerSupport.removeListener(null); - fail("Should not be able to remove a null listener."); - } - catch (NullPointerException e) - { - - } + listenerSupport.removeListener(null); } @Test @@ -89,32 +73,16 @@ public class EventListenerSupportTest assertSame(calledListeners.get(1), listener2); } - @Test + @Test(expected=IllegalArgumentException.class) public void testCreateWithNonInterfaceParameter() { - try - { - EventListenerSupport.create(String.class); - fail("Should not be able to create using non-interface class."); - } - catch (IllegalArgumentException e) - { - - } + EventListenerSupport.create(String.class); } - @Test + @Test(expected=NullPointerException.class) public void testCreateWithNullParameter() { - try - { - EventListenerSupport.create(null); - fail("Should not be able to create using null class."); - } - catch (NullPointerException e) - { - - } + EventListenerSupport.create(null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java index 5ef8ebb4e..7d8c1e86e 100644 --- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java @@ -452,13 +452,9 @@ public class ExceptionUtilsTest { assertFalse(match); } - @Test + @Test(expected=IllegalArgumentException.class) public void testRemoveCommonFrames_ListList() throws Exception { - try { - ExceptionUtils.removeCommonFrames(null, null); - fail(); - } catch (IllegalArgumentException ex) { - } + ExceptionUtils.removeCommonFrames(null, null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/math/FractionTest.java b/src/test/java/org/apache/commons/lang3/math/FractionTest.java index f7763c678..aa81f65b2 100644 --- a/src/test/java/org/apache/commons/lang3/math/FractionTest.java +++ b/src/test/java/org/apache/commons/lang3/math/FractionTest.java @@ -430,12 +430,9 @@ public class FractionTest { } } - @Test + @Test(expected=IllegalArgumentException.class) public void testFactory_String() { - try { - Fraction.getFraction(null); - fail("expecting IllegalArgumentException"); - } catch (IllegalArgumentException ex) {} + Fraction.getFraction(null); } diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java index f195a35b9..5109f8fbc 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableBooleanTest.java @@ -38,12 +38,12 @@ public class MutableBooleanTest { mutBool.setValue(true); assertEquals(+1, mutBool.compareTo(new MutableBoolean(false))); assertEquals(0, mutBool.compareTo(new MutableBoolean(true))); - - try { - mutBool.compareTo(null); - fail(); - } catch (NullPointerException ex) { - } + } + + @Test(expected=NullPointerException.class) + public void testCompareToNull() { + final MutableBoolean mutBool = new MutableBoolean(false); + mutBool.compareTo(null); } // ---------------------------------------------------------------- @@ -57,11 +57,11 @@ public class MutableBooleanTest { assertTrue(new MutableBoolean(Boolean.TRUE).booleanValue()); assertFalse(new MutableBoolean(Boolean.FALSE).booleanValue()); - try { - new MutableBoolean(null); - fail(); - } catch (NullPointerException ex) { - } + } + + @Test(expected=NullPointerException.class) + public void testConstructorNull() { + new MutableBoolean(null); } @Test @@ -105,11 +105,12 @@ public class MutableBooleanTest { mutBool.setValue(true); assertTrue(mutBool.booleanValue()); - try { - mutBool.setValue(null); - fail(); - } catch (NullPointerException ex) { - } + } + + @Test(expected=NullPointerException.class) + public void testSetNull() { + final MutableBoolean mutBool = new MutableBoolean(false); + mutBool.setValue(null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java index 5c4b87e85..069cc3897 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableByteTest.java @@ -39,10 +39,11 @@ public class MutableByteTest { assertEquals((byte) 2, new MutableByte("2").byteValue()); - try { - new MutableByte((Number)null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testConstructorNull() { + new MutableByte((Number)null); } @Test @@ -62,10 +63,12 @@ public class MutableByteTest { mutNum.setValue(new MutableByte((byte) 3)); assertEquals((byte) 3, mutNum.byteValue()); assertEquals(Byte.valueOf((byte) 3), mutNum.getValue()); - try { - mutNum.setValue(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testSetNull() { + final MutableByte mutNum = new MutableByte((byte) 0); + mutNum.setValue(null); } @Test @@ -105,10 +108,12 @@ public class MutableByteTest { assertEquals((byte) 0, mutNum.compareTo(new MutableByte((byte) 0))); assertEquals((byte) +1, mutNum.compareTo(new MutableByte((byte) -1))); assertEquals((byte) -1, mutNum.compareTo(new MutableByte((byte) 1))); - try { - mutNum.compareTo(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testCompareToNull() { + final MutableByte mutNum = new MutableByte((byte) 0); + mutNum.compareTo(null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java index 05adcf4bd..5a2b1213b 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableDoubleTest.java @@ -39,10 +39,11 @@ public class MutableDoubleTest { assertEquals(2d, new MutableDouble("2.0").doubleValue(), 0.0001d); - try { - new MutableDouble((Number)null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testConstructorNull() { + new MutableDouble((Number)null); } @Test @@ -62,10 +63,12 @@ public class MutableDoubleTest { mutNum.setValue(new MutableDouble(3d)); assertEquals(3d, mutNum.doubleValue(), 0.0001d); assertEquals(Double.valueOf(3d), mutNum.getValue()); - try { - mutNum.setValue(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testSetNull() { + final MutableDouble mutNum = new MutableDouble(0d); + mutNum.setValue(null); } @Test @@ -117,10 +120,12 @@ public class MutableDoubleTest { assertEquals(0, mutNum.compareTo(new MutableDouble(0d))); assertEquals(+1, mutNum.compareTo(new MutableDouble(-1d))); assertEquals(-1, mutNum.compareTo(new MutableDouble(1d))); - try { - mutNum.compareTo(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testCompareToNull() { + final MutableDouble mutNum = new MutableDouble(0d); + mutNum.compareTo(null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java index 048c1c30e..80971ca49 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableFloatTest.java @@ -39,10 +39,11 @@ public class MutableFloatTest { assertEquals(2f, new MutableFloat("2.0").floatValue(), 0.0001f); - try { - new MutableFloat((Number)null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testConstructorNull() { + new MutableFloat((Number)null); } @Test @@ -62,10 +63,12 @@ public class MutableFloatTest { mutNum.setValue(new MutableFloat(3f)); assertEquals(3f, mutNum.floatValue(), 0.0001f); assertEquals(Float.valueOf(3f), mutNum.getValue()); - try { - mutNum.setValue(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testSetNull() { + final MutableFloat mutNum = new MutableFloat(0f); + mutNum.setValue(null); } @Test @@ -117,10 +120,12 @@ public class MutableFloatTest { assertEquals(0, mutNum.compareTo(new MutableFloat(0f))); assertEquals(+1, mutNum.compareTo(new MutableFloat(-1f))); assertEquals(-1, mutNum.compareTo(new MutableFloat(1f))); - try { - mutNum.compareTo(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testCompareToNull() { + final MutableFloat mutNum = new MutableFloat(0f); + mutNum.compareTo(null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java index 446dc0c6d..b223c91bd 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableIntTest.java @@ -39,10 +39,11 @@ public class MutableIntTest { assertEquals(2, new MutableInt("2").intValue()); - try { - new MutableInt((Number)null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testConstructorNull() { + new MutableInt((Number)null); } @Test @@ -62,10 +63,12 @@ public class MutableIntTest { mutNum.setValue(new MutableLong(3)); assertEquals(3, mutNum.intValue()); assertEquals(Integer.valueOf(3), mutNum.getValue()); - try { - mutNum.setValue(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testSetNull() { + final MutableInt mutNum = new MutableInt(0); + mutNum.setValue(null); } @Test @@ -112,10 +115,12 @@ public class MutableIntTest { assertEquals(0, mutNum.compareTo(new MutableInt(0))); assertEquals(+1, mutNum.compareTo(new MutableInt(-1))); assertEquals(-1, mutNum.compareTo(new MutableInt(1))); - try { - mutNum.compareTo(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testCompareToNull() { + final MutableInt mutNum = new MutableInt(0); + mutNum.compareTo(null); } @Test diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java index cf0b1976d..00ada45f6 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java @@ -39,10 +39,11 @@ public class MutableLongTest { assertEquals(2, new MutableLong("2").longValue()); - try { - new MutableLong((Number)null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testConstructorNull() { + new MutableLong((Number)null); } @Test @@ -62,10 +63,12 @@ public class MutableLongTest { mutNum.setValue(new MutableLong(3)); assertEquals(3, mutNum.longValue()); assertEquals(Long.valueOf(3), mutNum.getValue()); - try { - mutNum.setValue(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testSetNull() { + final MutableLong mutNum = new MutableLong(0); + mutNum.setValue(null); } @Test @@ -105,10 +108,12 @@ public class MutableLongTest { assertEquals(0, mutNum.compareTo(new MutableLong(0))); assertEquals(+1, mutNum.compareTo(new MutableLong(-1))); assertEquals(-1, mutNum.compareTo(new MutableLong(1))); - try { - mutNum.compareTo(null); - fail(); - } catch (NullPointerException ex) {} + } + + @Test(expected=NullPointerException.class) + public void testCompareToNull() { + final MutableLong mutNum = new MutableLong(0); + mutNum.compareTo(null); } @Test