/*
 * 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.support.hierarchical;

import static org.junit.gen5.commons.meta.API.Usage.Experimental;
import static org.junit.gen5.engine.TestExecutionResult.aborted;
import static org.junit.gen5.engine.TestExecutionResult.failed;
import static org.junit.gen5.engine.TestExecutionResult.successful;
import static org.junit.gen5.engine.support.hierarchical.BlacklistedExceptions.rethrowIfBlacklisted;

import org.junit.gen5.commons.meta.API;
import org.junit.gen5.engine.TestExecutionResult;
import org.opentest4j.TestAbortedException;

/**
 * Executes a single test wrapped in an {@link Executable} and returns a
 * {@link TestExecutionResult} by converting exceptions.
 *
 * @since 5.0
 */
@API(Experimental)
public class SingleTestExecutor {

	public interface Executable {

		void execute() throws Throwable;

	}

	public TestExecutionResult executeSafely(Executable executable) {
		try {
			executable.execute();
			return successful();
		}
		catch (TestAbortedException e) {
			return aborted(e);
		}
		catch (Throwable t) {
			rethrowIfBlacklisted(t);
			return failed(t);
		}
	}
}

@@ -872,15 +872,32 @@
  * E
-xecutes
+ncapsulates execution of
  a s
@@ -943,16 +943,19 @@
 ble%7D and
+%0A *
  returns
@@ -956,19 +956,16 @@
 eturns a
-%0A *
  %7B@link 
@@ -1091,78 +1091,956 @@
 %7B%0A%0A%09
-public interface Executable %7B%0A%0A%09%09void execute() throws Throwable;%0A%0A%09%7D%0A
+/**%0A%09 * Functional interface of a single test to be executed by%0A%09 * %7B@link SingleTestExecutor%7D.%0A%09 */%0A%09public interface Executable %7B%0A%0A%09%09/**%0A%09%09 * Execute the test.%0A%09%09 *%0A%09%09 * @throws TestAbortedException to signal abortion%0A%09%09 * @throws Throwable to signal failure%0A%09%09 */%0A%09%09void execute() throws TestAbortedException, Throwable;%0A%0A%09%7D%0A%0A%09/**%0A%09 * Executes the supplied %7B@link Executable executable%7D and returns a%0A%09 * %7B@link TestExecutionResult%7D based on its outcome.%0A%09 *%0A%09 * %3Cp%3EIn case %7B@code executable%7D throws a %3Cem%3Eblacklisted%3C/em%3E exception,%0A%09 * e.g. an %7B@link OutOfMemoryError%7D, this method will rethrow it.%0A%09 *%0A%09 * @param executable the test to be executed%0A%09 * @return %7B@linkplain TestExecutionResult#aborted aborted%7D, when%0A%09 * %7B@code executable%7D throws a %7B@link TestAbortedException%7D;%0A%09 * %7B@linkplain TestExecutionResult#failed failed%7D, on a different%0A%09 * %7B@link Throwable%7D; %7B@linkplain TestExecutionResult#successful%0A%09 * successful%7D, otherwise.%0A%09 */
 %0A%09pu

Document SingleTestExecutor (#234)