JUnit4 allows use of expected exceptions
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1388108 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f25a596ae9
commit
247cf8c4dc
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,34 +43,18 @@ import org.junit.Test;
|
|||
*/
|
||||
public class EventListenerSupportTest
|
||||
{
|
||||
@Test
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testAddNullListener()
|
||||
{
|
||||
EventListenerSupport<VetoableChangeListener> 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<VetoableChangeListener> 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue