NotPredicateTest: Fix misuse of ExpectedException
Any additional statements after the statement that is expected to throw will never be executed in a passing test. This can lead to inappropriately passing tests where later incorrect assertions are skipped by the thrown exception [1]. [1] http://errorprone.info/bugpattern/ExpectedExceptionChecker Change-Id: I06a08ddd15e32decf5c18289ba228c2c78b31065
This commit is contained in:
parent
7957f93c5b
commit
7c677298dd
|
@ -50,17 +50,26 @@ public class NotPredicateTest extends PredicateTest {
|
|||
final TestPredicate p = f("author", "bob");
|
||||
final Predicate<String> n = not(p);
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
n.getChildren().clear();
|
||||
assertOnlyChild("clear", p, n);
|
||||
try {
|
||||
n.getChildren().clear();
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
assertOnlyChild("clear", p, n);
|
||||
}
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
n.getChildren().remove(0);
|
||||
assertOnlyChild("remove(0)", p, n);
|
||||
try {
|
||||
n.getChildren().remove(0);
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
assertOnlyChild("remove(0)", p, n);
|
||||
}
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
n.getChildren().iterator().remove();
|
||||
assertOnlyChild("remove(0)", p, n);
|
||||
try {
|
||||
n.getChildren().iterator().remove();
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
assertOnlyChild("remove()", p, n);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertOnlyChild(String o, Predicate<String> c, Predicate<String> p) {
|
||||
|
|
Loading…
Reference in New Issue