Skip to content

Commit 60aaf96

Browse files
oehmekcooney
authored andcommitted
Make ErrorCollector#checkSucceeds generic
Closes junit-team#1013
1 parent e94c543 commit 60aaf96

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/org/junit/rules/ErrorCollector.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public Object call() throws Exception {
7373
* Execution continues, but the test will fail at the end if
7474
* {@code callable} threw an exception.
7575
*/
76-
public Object checkSucceeds(Callable<Object> callable) {
76+
public <T> T checkSucceeds(Callable<T> callable) {
7777
try {
7878
return callable.call();
7979
} catch (Throwable e) {
8080
addError(e);
8181
return null;
8282
}
8383
}
84-
}
84+
}

src/test/java/org/junit/tests/experimental/rules/VerifierRuleTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,17 @@ public Object call() throws Exception {
8484
throw new RuntimeException("first!");
8585
}
8686
});
87-
collector.checkSucceeds(new Callable<Object>() {
88-
public Object call() throws Exception {
87+
collector.checkSucceeds(new Callable<Integer>() {
88+
public Integer call() throws Exception {
8989
throw new RuntimeException("second!");
9090
}
9191
});
92+
Integer result = collector.checkSucceeds(new Callable<Integer>() {
93+
public Integer call() throws Exception {
94+
return 1;
95+
}
96+
});
97+
assertEquals(Integer.valueOf(1), result);
9298
}
9399
}
94100

0 commit comments

Comments
 (0)