Let JUnit 4 check the Exception

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1026191 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2010-10-22 01:18:19 +00:00
parent 6f7691f90b
commit 8fc1425e84
1 changed files with 123 additions and 271 deletions

View File

@ -141,13 +141,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cInteger)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cInteger));
} }
@Test public void testNotPredicateEx() { @Test(expected=IllegalArgumentException.class)
try { public void testNotPredicateEx() {
PredicateUtils.notPredicate(null); PredicateUtils.notPredicate(null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// andPredicate // andPredicate
@ -160,13 +156,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
} }
@Test public void testAndPredicateEx() { @Test(expected=IllegalArgumentException.class)
try { public void testAndPredicateEx() {
PredicateUtils.andPredicate(null, null); PredicateUtils.andPredicate(null, null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// allPredicate // allPredicate
@ -213,58 +205,38 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertTrue(AllPredicate.allPredicate(coll), null); assertTrue(AllPredicate.allPredicate(coll), null);
} }
@Test public void testAllPredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testAllPredicateEx1() {
AllPredicate.allPredicate((Predicate<Object>[]) null); AllPredicate.allPredicate((Predicate<Object>[]) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testAllPredicateEx2() { @Test(expected=IllegalArgumentException.class)
try { public void testAllPredicateEx2() {
AllPredicate.<Object>allPredicate(new Predicate[] { null }); AllPredicate.<Object>allPredicate(new Predicate[] { null });
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testAllPredicateEx3() { @Test(expected=IllegalArgumentException.class)
try { public void testAllPredicateEx3() {
AllPredicate.allPredicate(new Predicate[] { null, null }); AllPredicate.allPredicate(new Predicate[] { null, null });
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testAllPredicateEx4() { @Test(expected=IllegalArgumentException.class)
try { public void testAllPredicateEx4() {
AllPredicate.allPredicate((Collection<Predicate<Object>>) null); AllPredicate.allPredicate((Collection<Predicate<Object>>) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testAllPredicateEx5() { @Test public void testAllPredicateEx5() {
AllPredicate.allPredicate(Collections.<Predicate<Object>>emptyList()); AllPredicate.allPredicate(Collections.<Predicate<Object>>emptyList());
} }
@Test public void testAllPredicateEx6() { @Test(expected=IllegalArgumentException.class)
try { public void testAllPredicateEx6() {
Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>();
coll.add(null); coll.add(null);
coll.add(null); coll.add(null);
AllPredicate.allPredicate(coll); AllPredicate.allPredicate(coll);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// orPredicate // orPredicate
@ -277,13 +249,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
} }
@Test public void testOrPredicateEx() { @Test(expected=IllegalArgumentException.class)
try { public void testOrPredicateEx() {
PredicateUtils.orPredicate(null, null); PredicateUtils.orPredicate(null, null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// anyPredicate // anyPredicate
@ -331,58 +299,38 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertFalse(PredicateUtils.anyPredicate(coll), null); assertFalse(PredicateUtils.anyPredicate(coll), null);
} }
@Test public void testAnyPredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testAnyPredicateEx1() {
PredicateUtils.anyPredicate((Predicate<Object>[]) null); PredicateUtils.anyPredicate((Predicate<Object>[]) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testAnyPredicateEx2() { @Test(expected=IllegalArgumentException.class)
try { public void testAnyPredicateEx2() {
PredicateUtils.anyPredicate(new Predicate[] {null}); PredicateUtils.anyPredicate(new Predicate[] {null});
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testAnyPredicateEx3() { @Test(expected=IllegalArgumentException.class)
try { public void testAnyPredicateEx3() {
PredicateUtils.anyPredicate(new Predicate[] {null, null}); PredicateUtils.anyPredicate(new Predicate[] {null, null});
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testAnyPredicateEx4() { @Test(expected=IllegalArgumentException.class)
try { public void testAnyPredicateEx4() {
PredicateUtils.anyPredicate((Collection<Predicate<Object>>) null); PredicateUtils.anyPredicate((Collection<Predicate<Object>>) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testAnyPredicateEx5() { @Test public void testAnyPredicateEx5() {
PredicateUtils.anyPredicate(Collections.<Predicate<Object>>emptyList()); PredicateUtils.anyPredicate(Collections.<Predicate<Object>>emptyList());
} }
@Test public void testAnyPredicateEx6() { @Test(expected=IllegalArgumentException.class)
try { public void testAnyPredicateEx6() {
Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>();
coll.add(null); coll.add(null);
coll.add(null); coll.add(null);
PredicateUtils.anyPredicate(coll); PredicateUtils.anyPredicate(coll);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// eitherPredicate // eitherPredicate
@ -395,13 +343,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
} }
@Test public void testEitherPredicateEx() { @Test(expected=IllegalArgumentException.class)
try { public void testEitherPredicateEx() {
PredicateUtils.eitherPredicate(null, null); PredicateUtils.eitherPredicate(null, null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// onePredicate // onePredicate
@ -452,42 +396,26 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertFalse(PredicateUtils.onePredicate(coll), null); assertFalse(PredicateUtils.onePredicate(coll), null);
} }
@Test public void testOnePredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testOnePredicateEx1() {
PredicateUtils.onePredicate((Predicate<Object>[]) null); PredicateUtils.onePredicate((Predicate<Object>[]) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testOnePredicateEx2() { @Test(expected=IllegalArgumentException.class)
try { public void testOnePredicateEx2() {
PredicateUtils.onePredicate(new Predicate[] {null}); PredicateUtils.onePredicate(new Predicate[] {null});
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testOnePredicateEx3() { @Test(expected=IllegalArgumentException.class)
try { public void testOnePredicateEx3() {
PredicateUtils.onePredicate(new Predicate[] {null, null}); PredicateUtils.onePredicate(new Predicate[] {null, null});
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testOnePredicateEx4() { @Test(expected=IllegalArgumentException.class)
try { public void testOnePredicateEx4() {
PredicateUtils.onePredicate((Collection<Predicate<Object>>) null); PredicateUtils.onePredicate((Collection<Predicate<Object>>) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -495,16 +423,12 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
PredicateUtils.onePredicate(Collections.EMPTY_LIST); PredicateUtils.onePredicate(Collections.EMPTY_LIST);
} }
@Test public void testOnePredicateEx6() { @Test(expected=IllegalArgumentException.class)
try { public void testOnePredicateEx6() {
Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>();
coll.add(null); coll.add(null);
coll.add(null); coll.add(null);
PredicateUtils.onePredicate(coll); PredicateUtils.onePredicate(coll);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// neitherPredicate // neitherPredicate
@ -517,13 +441,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(true, PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null));
} }
@Test public void testNeitherPredicateEx() { @Test(expected=IllegalArgumentException.class)
try { public void testNeitherPredicateEx() {
PredicateUtils.neitherPredicate(null, null); PredicateUtils.neitherPredicate(null, null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// nonePredicate // nonePredicate
@ -570,58 +490,38 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertTrue(PredicateUtils.nonePredicate(coll), null); assertTrue(PredicateUtils.nonePredicate(coll), null);
} }
@Test public void testNonePredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testNonePredicateEx1() {
PredicateUtils.nonePredicate((Predicate<Object>[]) null); PredicateUtils.nonePredicate((Predicate<Object>[]) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testNonePredicateEx2() { @Test(expected=IllegalArgumentException.class)
try { public void testNonePredicateEx2() {
PredicateUtils.nonePredicate(new Predicate[] {null}); PredicateUtils.nonePredicate(new Predicate[] {null});
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test public void testNonePredicateEx3() { @Test(expected=IllegalArgumentException.class)
try { public void testNonePredicateEx3() {
PredicateUtils.nonePredicate(new Predicate[] {null, null}); PredicateUtils.nonePredicate(new Predicate[] {null, null});
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testNonePredicateEx4() { @Test(expected=IllegalArgumentException.class)
try { public void testNonePredicateEx4() {
PredicateUtils.nonePredicate((Collection<Predicate<Object>>) null); PredicateUtils.nonePredicate((Collection<Predicate<Object>>) null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testNonePredicateEx5() { @Test public void testNonePredicateEx5() {
PredicateUtils.nonePredicate(Collections.<Predicate<Object>>emptyList()); PredicateUtils.nonePredicate(Collections.<Predicate<Object>>emptyList());
} }
@Test public void testNonePredicateEx6() { @Test(expected=IllegalArgumentException.class)
try { public void testNonePredicateEx6() {
Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>();
coll.add(null); coll.add(null);
coll.add(null); coll.add(null);
PredicateUtils.nonePredicate(coll); PredicateUtils.nonePredicate(coll);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// instanceofPredicate // instanceofPredicate
@ -656,22 +556,14 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(true, PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(true)); assertEquals(true, PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(true));
} }
@Test public void testAsPredicateTransformerEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testAsPredicateTransformerEx1() {
PredicateUtils.asPredicate(null); PredicateUtils.asPredicate(null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testAsPredicateTransformerEx2() { @Test(expected=FunctorException.class)
try { public void testAsPredicateTransformerEx2() {
PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(null); PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(null);
} catch (FunctorException ex) {
return;
}
fail();
} }
// invokerPredicate // invokerPredicate
@ -684,31 +576,19 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.invokerPredicate("isEmpty").evaluate(list)); assertEquals(false, PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
} }
@Test public void testInvokerPredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testInvokerPredicateEx1() {
PredicateUtils.invokerPredicate(null); PredicateUtils.invokerPredicate(null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testInvokerPredicateEx2() { @Test(expected=FunctorException.class)
try { public void testInvokerPredicateEx2() {
PredicateUtils.invokerPredicate("isEmpty").evaluate(null); PredicateUtils.invokerPredicate("isEmpty").evaluate(null);
} catch (FunctorException ex) {
return;
}
fail();
} }
@Test public void testInvokerPredicateEx3() { @Test(expected=FunctorException.class)
try { public void testInvokerPredicateEx3() {
PredicateUtils.invokerPredicate("noSuchMethod").evaluate(new Object()); PredicateUtils.invokerPredicate("noSuchMethod").evaluate(new Object());
} catch (FunctorException ex) {
return;
}
fail();
} }
// invokerPredicate2 // invokerPredicate2
@ -723,54 +603,34 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
"contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list)); "contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list));
} }
@Test public void testInvokerPredicate2Ex1() { @Test(expected=IllegalArgumentException.class)
try { public void testInvokerPredicate2Ex1() {
PredicateUtils.invokerPredicate(null, null, null); PredicateUtils.invokerPredicate(null, null, null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
@Test public void testInvokerPredicate2Ex2() { @Test(expected=FunctorException.class)
try { public void testInvokerPredicate2Ex2() {
PredicateUtils.invokerPredicate("contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(null); PredicateUtils.invokerPredicate("contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(null);
} catch (FunctorException ex) {
return;
}
fail();
} }
@Test public void testInvokerPredicate2Ex3() { @Test(expected=FunctorException.class)
try { public void testInvokerPredicate2Ex3() {
PredicateUtils.invokerPredicate( PredicateUtils.invokerPredicate(
"noSuchMethod", new Class[] {Object.class}, new Object[] {cString}).evaluate(new Object()); "noSuchMethod", new Class[] {Object.class}, new Object[] {cString}).evaluate(new Object());
} catch (FunctorException ex) {
return;
}
fail();
} }
// nullIsException // nullIsException
//------------------------------------------------------------------ //------------------------------------------------------------------
@Test public void testNullIsExceptionPredicate() { @Test(expected=FunctorException.class)
public void testNullIsExceptionPredicate() {
assertEquals(true, PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(new Object())); assertEquals(true, PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(new Object()));
try { PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(null);
PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(null);
} catch (FunctorException ex) {
return;
}
fail();
} }
@Test public void testNullIsExceptionPredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testNullIsExceptionPredicateEx1() {
PredicateUtils.nullIsExceptionPredicate(null); PredicateUtils.nullIsExceptionPredicate(null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// nullIsTrue // nullIsTrue
@ -782,13 +642,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.nullIsTruePredicate(FalsePredicate.falsePredicate()).evaluate(new Object())); assertEquals(false, PredicateUtils.nullIsTruePredicate(FalsePredicate.falsePredicate()).evaluate(new Object()));
} }
@Test public void testNullIsTruePredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testNullIsTruePredicateEx1() {
PredicateUtils.nullIsTruePredicate(null); PredicateUtils.nullIsTruePredicate(null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// nullIsFalse // nullIsFalse
@ -800,13 +656,9 @@ public class TestPredicateUtils extends BasicPredicateTestBase {
assertEquals(false, PredicateUtils.nullIsFalsePredicate(FalsePredicate.falsePredicate()).evaluate(new Object())); assertEquals(false, PredicateUtils.nullIsFalsePredicate(FalsePredicate.falsePredicate()).evaluate(new Object()));
} }
@Test public void testNullIsFalsePredicateEx1() { @Test(expected=IllegalArgumentException.class)
try { public void testNullIsFalsePredicateEx1() {
PredicateUtils.nullIsFalsePredicate(null); PredicateUtils.nullIsFalsePredicate(null);
} catch (IllegalArgumentException ex) {
return;
}
fail();
} }
// transformed // transformed