Use assertThrows() in test.
MODIFY
src/test/java/org/apache/commons/io/ThreadMonitorTestCase.java
src/test/java/org/apache/commons/io/ThreadMonitorTestCase.java
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration;
@@ -80,13 +81,10 @@ public void testNoTimeoutZero() {
*/
@Test
public void testTimeout() {
- try {
+ assertThrows(InterruptedException.class, () -> {
final Thread monitor = ThreadMonitor.start(Duration.ofMillis(100));
TestUtils.sleep(400);
ThreadMonitor.stop(monitor);
- fail("Expected InterruptedException");
- } catch (final InterruptedException e) {
- // expected result - timeout
- }
+ });
}
}

Use assertThrows() in test.