package aQute.tester.bundle.engine;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.junit.platform.engine.ConfigurationParameters;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.ExecutionRequest;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestEngine;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;

public class BundleDescriptor extends AbstractTestDescriptor {

	final private Bundle							bundle;
	final private BundleException					bundleException;
	final private Map<TestDescriptor, TestEngine>	engineMap	= new HashMap<>();

	public static String displayNameOf(Bundle bundle) {
		final Optional<String> bundleName = Optional.ofNullable(bundle.getHeaders()
			.get(aQute.bnd.osgi.Constants.BUNDLE_NAME));
		return "[" + bundle.getBundleId() + "] " + bundleName.orElse(bundle.getSymbolicName()) + ';'
			+ bundle.getVersion();
	}

	public BundleDescriptor(Bundle bundle, UniqueId uniqueId) {
		this(bundle, uniqueId, null);
	}

	public BundleDescriptor(Bundle bundle, UniqueId uniqueId, BundleException bundleException) {
		super(uniqueId, displayNameOf(bundle));
		this.bundle = bundle;
		this.bundleException = bundleException;
	}

	public Bundle getBundle() {
		return bundle;
	}

	public void addChild(TestDescriptor descriptor, TestEngine engine) {
		engineMap.put(descriptor, engine);
		addChild(descriptor);
	}

	public void executeChild(TestDescriptor descriptor, EngineExecutionListener listener, ConfigurationParameters params) {
		TestEngine engine = engineMap.get(descriptor);
		ExecutionRequest er = new ExecutionRequest(descriptor, listener, params);
		engine.execute(er);

	}
	@Override
	public Type getType() {
		return bundleException == null ? Type.CONTAINER : Type.TEST;
	}

	public BundleException getException() {
		return bundleException;
	}
}

@@ -564,16 +564,50 @@
 ption;%0A%0A
+import aQute.bnd.osgi.Constants;%0A%0A
 public c
@@ -966,31 +966,16 @@
 %09%09%09.get(
-aQute.bnd.osgi.
 Constant
@@ -1053,24 +1053,28 @@
 e.orElse
+Get
 (bundle
-.
+::
 getSymbo
@@ -1080,18 +1080,16 @@
 olicName
-()
 ) + ';'%0A

Use method reference for optional else operation