Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce support for blacklisted exceptions
This commit introduces a BlacklistedExceptions utility class for rethrowing blacklisted exceptions (i.e., errors that always terminate the test plan execution immediately). HierarchicalTestExecutor and SingleTestExecutor have been retrofitted to support blacklisted exceptions. Issue: #83 ------------------------------------------------------------------------ On behalf of the community, the JUnit Lambda Team thanks msg systems ag (http://www.msg-systems.com) for supporting the JUnit crowdfunding campaign! ------------------------------------------------------------------------
- Loading branch information
Showing
4 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
junit-engine-api/src/main/java/org/junit/gen5/engine/BlacklistedExceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2015-2016 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.gen5.commons.util.ExceptionUtils; | ||
|
||
/** | ||
* Internal utilities for working with <em>blacklisted</em> exceptions. | ||
* | ||
* <p><em>Blacklisted</em> exceptions are those that should always terminate | ||
* test plan execution immediately. | ||
* | ||
* <h4>Currently Blacklisted Exceptions</h4> | ||
* <ul> | ||
* <li>{@link OutOfMemoryError}</li> | ||
* </ul> | ||
* | ||
* @since 5.0 | ||
*/ | ||
final class BlacklistedExceptions { | ||
|
||
private static final List<Class<? extends Throwable>> blacklist = Collections.singletonList(OutOfMemoryError.class); | ||
|
||
private BlacklistedExceptions() { | ||
/* no-op */ | ||
} | ||
|
||
/** | ||
* Rethrow the supplied {@link Throwable exception} if it is | ||
* <em>blacklisted</em>. | ||
* | ||
* <p>If the supplied {@code exception} is not <em>blacklisted</em>, | ||
* this method does nothing. | ||
*/ | ||
static void rethrowIfBlackListed(Throwable exception) { | ||
if (blacklist.stream().anyMatch(exceptionType -> exceptionType.isInstance(exception))) { | ||
ExceptionUtils.throwAsRuntimeException(exception); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters