Bug 312333 Exceptions in JUnit's PartService
With the code from Head there are 3 NPEs in UIAllTests: testShowPart_Id_Unrendered_ACTIVATE testShowPart_Id_Unrendered_ACTIVATE2 testShowPart_Id_Unrendered_ACTIVATE3 They all seem to have the same cause: context of the activated part is null.
tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/HeadlessContextPresentationEngine.java
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.model.application.MContribution;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
import org.eclipse.e4.workbench.ui.IPresentationEngine;
import org.eclipse.e4.workbench.ui.UIEvents;
import org.eclipse.e4.workbench.ui.internal.Activator;
import org.eclipse.e4.workbench.ui.internal.Policy;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
public class HeadlessContextPresentationEngine implements IPresentationEngine {
	@Inject
	private IEventBroker eventBroker;
	@Inject
	private IContributionFactory contributionFactory;
	private EventHandler childHandler;
	private EventHandler activeChildHandler;
	private boolean createContributions = true;
	private static IEclipseContext getParentContext(MUIElement element) {
		MElementContainer<MUIElement> parent = element.getParent();
		IEclipseContext context = null;
		while (parent != null) {
			if (parent instanceof MContext) {
				return ((MContext) parent).getContext();