Skip to content

Commit 661d46a

Browse files
pivovaritbvkatwijk
andcommitted
Fix CheckedRunnableTest#shouldApplyAnUncheckedFunctionThatThrows (#2956)
* `shouldApplyAnUncheckedFunctionThatThrows` always passed, when removing the `throw new Error()` because the failed asserting was immediately caught. ```java final Runnable runnable = CheckedRunnable.of(() -> { /*throw new Error();*/ }).unchecked(); // Test would still pass ``` Fixed by using `assertThrows` from JUnit ---- backport of: #2954 Co-authored-by: Boris van Katwijk <[email protected]>
1 parent 75250e3 commit 661d46a

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

vavr/src/test/java/io/vavr/CheckedRunnableTest.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,13 @@ public void shouldApplyAnUncheckedFunctionThatDoesNotThrow() {
5050
try {
5151
runnable.run();
5252
} catch(Throwable x) {
53-
Assertions.fail("Did not excepect an exception but received: " + x.getMessage());
53+
Assertions.fail("Did not expect an exception but received: " + x.getMessage());
5454
}
5555
}
5656

5757
@Test
5858
public void shouldApplyAnUncheckedFunctionThatThrows() {
5959
final Runnable runnable = CheckedRunnable.of(() -> { throw new Error(); }).unchecked();
60-
try {
61-
runnable.run();
62-
Assertions.fail("Did excepect an exception.");
63-
} catch(Error x) {
64-
// ok!
65-
}
60+
Assertions.assertThrows(Error.class, () -> runnable.run());
6661
}
6762
}

0 commit comments

Comments
 (0)