org.junit.jupiter.engine.descriptor.AbstractExtensionContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-jupiter-engine Show documentation
Show all versions of junit-jupiter-engine Show documentation
Module "junit-jupiter-engine" of JUnit 5.
/*
* 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.jupiter.engine.descriptor;
import static java.util.stream.Collectors.toCollection;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.engine.execution.ExtensionValuesStore;
import org.junit.jupiter.engine.execution.NamespaceAwareStore;
import org.junit.platform.commons.util.Preconditions;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.reporting.ReportEntry;
/**
* @since 5.0
*/
abstract class AbstractExtensionContext implements ExtensionContext {
private final ExtensionContext parent;
private final EngineExecutionListener engineExecutionListener;
private final T testDescriptor;
private final ExtensionValuesStore valuesStore;
AbstractExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener,
T testDescriptor) {
this.parent = parent;
this.engineExecutionListener = engineExecutionListener;
this.testDescriptor = testDescriptor;
this.valuesStore = createStore(parent);
}
private ExtensionValuesStore createStore(ExtensionContext parent) {
ExtensionValuesStore parentStore = null;
if (parent != null) {
parentStore = ((AbstractExtensionContext) parent).valuesStore;
}
return new ExtensionValuesStore(parentStore);
}
@Override
public void publishReportEntry(Map values) {
engineExecutionListener.reportingEntryPublished(this.testDescriptor, ReportEntry.from(values));
}
@Override
public Optional getParent() {
return Optional.ofNullable(parent);
}
protected T getTestDescriptor() {
return testDescriptor;
}
@Override
public Store getStore(Namespace namespace) {
Preconditions.notNull(namespace, "Namespace must not be null");
return new NamespaceAwareStore(valuesStore, namespace);
}
@Override
public Set getTags() {
return testDescriptor.getTags().stream().map(TestTag::getName).collect(toCollection(LinkedHashSet::new));
}
}