All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.tester.bundle.engine.StaticFailureDescriptor Maven / Gradle / Ivy

Go to download

A bnd tester using JUnit Platform. Like biz.aQute.tester, this bundle will add itself to the -runbundles at the end. At startup, this bundle will then look for TestEngine implementations among the loaded bundles and use them to execute the tests. This bundle does NOT contain the necessary TestEngine implementations for JUnit 3, 4 or 5 - it will import them just like any other bundle.

There is a newer version: 7.1.0
Show newest version
package aQute.tester.bundle.engine;

import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;

public class StaticFailureDescriptor extends AbstractTestDescriptor {
	private final Throwable error;

	public StaticFailureDescriptor(UniqueId id, String name) {
		this(id, name, null);
	}

	public StaticFailureDescriptor(UniqueId id, String name, Throwable error) {
		super(id, name);
		this.error = error;
	}

	public Throwable getError() {
		return error;
	}

	@Override
	public Type getType() {
		return hasChildren() ? ((error != null) ? Type.CONTAINER_AND_TEST : Type.CONTAINER) : Type.TEST;
	}

	public boolean hasChildren() {
		return !getChildren().isEmpty();
	}

	// Defensive guarding.
	@Override
	public void addChild(TestDescriptor t) {
		if (t instanceof StaticFailureDescriptor) {
			super.addChild(t);
		} else {
			throw new IllegalArgumentException(
				"StaticFailureDescriptor can only take StaticFailureDescriptors as children");
		}
	}

	public void execute(EngineExecutionListener listener) {
		listener.executionStarted(this);
		getChildren().stream()
			.map(StaticFailureDescriptor.class::cast)
			.forEach(descriptor -> descriptor.execute(listener));
		listener.executionFinished(this,
			error == null ? TestExecutionResult.successful() : TestExecutionResult.failed(error));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy