summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@collab.net>2018-07-17 16:03:31 +0900
committerDavid Pursehouse <dpursehouse@collab.net>2018-07-18 09:37:41 +0900
commit7c677298ddcfab53d0adb3d25cd6ea595b8d2fdb (patch)
treeabf4d6f03c573076bca43154cf6581d4c6572562
parent7957f93c5b645422adf21c91989fade74729c0e7 (diff)
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
-rw-r--r--gerrit-server/src/test/java/com/google/gerrit/server/query/NotPredicateTest.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/NotPredicateTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/NotPredicateTest.java
index f70b8fc85e..13a566c855 100644
--- a/gerrit-server/src/test/java/com/google/gerrit/server/query/NotPredicateTest.java
+++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/NotPredicateTest.java
@@ -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) {