"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptor.java" between
junit5-r5.3.2.tar.gz and junit5-r5.4.0.tar.gz

About: JUnit 5 is a unit testing framework for the Java programming language.

JupiterTestDescriptor.java  (junit5-r5.3.2):JupiterTestDescriptor.java  (junit5-r5.4.0)
/* /*
* Copyright 2015-2018 the original author or authors. * Copyright 2015-2019 the original author or authors.
* *
* All rights reserved. This program and the accompanying materials are * All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which * made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at * accompanies this distribution and is available at
* *
* http://www.eclipse.org/legal/epl-v20.html * http://www.eclipse.org/legal/epl-v20.html
*/ */
package org.junit.jupiter.engine.descriptor; package org.junit.jupiter.engine.descriptor;
import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection; import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toSet; import static java.util.stream.Collectors.toSet;
import static org.apiguardian.api.API.Status.INTERNAL; import static org.apiguardian.api.API.Status.INTERNAL;
import static org.junit.jupiter.engine.descriptor.DisplayNameUtils.determineDisp layName;
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
import static org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnno tations; import static org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnno tations;
import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedElement;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Supplier;
import org.apiguardian.api.API; import org.apiguardian.api.API;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ResourceAccessMode; import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock; import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.engine.config.JupiterConfiguration;
import org.junit.jupiter.engine.execution.ConditionEvaluator; import org.junit.jupiter.engine.execution.ConditionEvaluator;
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext; import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
import org.junit.platform.commons.JUnitException; import org.junit.platform.commons.JUnitException;
import org.junit.platform.commons.logging.Logger; import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory; import org.junit.platform.commons.logging.LoggerFactory;
import org.junit.platform.commons.util.ExceptionUtils; import org.junit.platform.commons.util.ExceptionUtils;
import org.junit.platform.commons.util.StringUtils;
import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestSource; import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.TestTag; import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.UniqueId; import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor; import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
import org.junit.platform.engine.support.hierarchical.ExclusiveResource; import org.junit.platform.engine.support.hierarchical.ExclusiveResource;
import org.junit.platform.engine.support.hierarchical.ExclusiveResource.LockMode ; import org.junit.platform.engine.support.hierarchical.ExclusiveResource.LockMode ;
import org.junit.platform.engine.support.hierarchical.Node; import org.junit.platform.engine.support.hierarchical.Node;
/** /**
* @since 5.0 * @since 5.0
*/ */
@API(status = INTERNAL, since = "5.0") @API(status = INTERNAL, since = "5.0")
public abstract class JupiterTestDescriptor extends AbstractTestDescriptor public abstract class JupiterTestDescriptor extends AbstractTestDescriptor
implements Node<JupiterEngineExecutionContext> { implements Node<JupiterEngineExecutionContext> {
private static final Logger logger = LoggerFactory.getLogger(JupiterTestD escriptor.class); private static final Logger logger = LoggerFactory.getLogger(JupiterTestD escriptor.class);
private static final ConditionEvaluator conditionEvaluator = new Conditio nEvaluator(); private static final ConditionEvaluator conditionEvaluator = new Conditio nEvaluator();
JupiterTestDescriptor(UniqueId uniqueId, String displayName, TestSource s protected final JupiterConfiguration configuration;
ource) {
JupiterTestDescriptor(UniqueId uniqueId, AnnotatedElement element, Suppli
er<String> displayNameSupplier,
TestSource source, JupiterConfiguration configuration) {
this(uniqueId, determineDisplayName(element, displayNameSupplier)
, source, configuration);
}
JupiterTestDescriptor(UniqueId uniqueId, String displayName, TestSource s
ource,
JupiterConfiguration configuration) {
super(uniqueId, displayName, source); super(uniqueId, displayName, source);
this.configuration = configuration;
} }
// --- TestDescriptor --------------------------------------------------- --- // --- TestDescriptor --------------------------------------------------- ---
protected static Set<TestTag> getTags(AnnotatedElement element) { protected static Set<TestTag> getTags(AnnotatedElement element) {
// @formatter:off // @formatter:off
return findRepeatableAnnotations(element, Tag.class).stream() return findRepeatableAnnotations(element, Tag.class).stream()
.map(Tag::value) .map(Tag::value)
.filter(tag -> { .filter(tag -> {
boolean isValid = TestTag.isValid(tag); boolean isValid = TestTag.isValid(tag);
skipping to change at line 91 skipping to change at line 100
"Configuration error: inv alid tag syntax in @Tag(\"%s\") declaration on [%s]. Tag will be ignored.", "Configuration error: inv alid tag syntax in @Tag(\"%s\") declaration on [%s]. Tag will be ignored.",
tag, element)); tag, element));
} }
return isValid; return isValid;
}) })
.map(TestTag::create) .map(TestTag::create)
.collect(collectingAndThen(toCollection(LinkedHas hSet::new), Collections::unmodifiableSet)); .collect(collectingAndThen(toCollection(LinkedHas hSet::new), Collections::unmodifiableSet));
// @formatter:on // @formatter:on
} }
protected static <E extends AnnotatedElement> String determineDisplayName
(E element,
Function<E, String> defaultDisplayNameGenerator) {
Optional<DisplayName> displayNameAnnotation = findAnnotation(elem
ent, DisplayName.class);
if (displayNameAnnotation.isPresent()) {
String displayName = displayNameAnnotation.get().value().
trim();
// TODO [#242] Replace logging with precondition check on
ce we have a proper mechanism for
// handling validation exceptions during the TestEngine d
iscovery phase.
if (StringUtils.isBlank(displayName)) {
logger.warn(() -> String.format(
"Configuration error: @DisplayName on [%s
] must be declared with a non-empty value.", element));
}
else {
return displayName;
}
}
// else
return defaultDisplayNameGenerator.apply(element);
}
// --- Node ------------------------------------------------------------- --- // --- Node ------------------------------------------------------------- ---
@Override @Override
public final ExecutionMode getExecutionMode() { public final ExecutionMode getExecutionMode() {
Optional<ExecutionMode> executionMode = getExplicitExecutionMode( ); Optional<ExecutionMode> executionMode = getExplicitExecutionMode( );
if (executionMode.isPresent()) { if (executionMode.isPresent()) {
return executionMode.get(); return executionMode.get();
} }
Optional<TestDescriptor> parent = getParent(); Optional<TestDescriptor> parent = getParent();
while (parent.isPresent() && parent.get() instanceof JupiterTestD escriptor) { while (parent.isPresent() && parent.get() instanceof JupiterTestD escriptor) {
skipping to change at line 133 skipping to change at line 121
executionMode = jupiterParent.getExplicitExecutionMode(); executionMode = jupiterParent.getExplicitExecutionMode();
if (executionMode.isPresent()) { if (executionMode.isPresent()) {
return executionMode.get(); return executionMode.get();
} }
executionMode = jupiterParent.getDefaultChildExecutionMod e(); executionMode = jupiterParent.getDefaultChildExecutionMod e();
if (executionMode.isPresent()) { if (executionMode.isPresent()) {
return executionMode.get(); return executionMode.get();
} }
parent = jupiterParent.getParent(); parent = jupiterParent.getParent();
} }
return ExecutionMode.CONCURRENT; return toExecutionMode(configuration.getDefaultExecutionMode());
} }
protected Optional<ExecutionMode> getExplicitExecutionMode() { protected Optional<ExecutionMode> getExplicitExecutionMode() {
return Optional.empty(); return Optional.empty();
} }
protected Optional<ExecutionMode> getDefaultChildExecutionMode() { protected Optional<ExecutionMode> getDefaultChildExecutionMode() {
return Optional.empty(); return Optional.empty();
} }
protected Optional<ExecutionMode> getExecutionModeFromAnnotation(Annotate dElement element) { protected Optional<ExecutionMode> getExecutionModeFromAnnotation(Annotate dElement element) {
// @formatter:off // @formatter:off
return findAnnotation(element, Execution.class) return findAnnotation(element, Execution.class)
.map(Execution::value) .map(Execution::value)
.map(JupiterTestDescriptor::toExecutionMode); .map(JupiterTestDescriptor::toExecutionMode);
// @formatter:on // @formatter:on
} }
private static ExecutionMode toExecutionMode(org.junit.jupiter.api.parall el.ExecutionMode mode) { public static ExecutionMode toExecutionMode(org.junit.jupiter.api.paralle l.ExecutionMode mode) {
switch (mode) { switch (mode) {
case CONCURRENT: case CONCURRENT:
return ExecutionMode.CONCURRENT; return ExecutionMode.CONCURRENT;
case SAME_THREAD: case SAME_THREAD:
return ExecutionMode.SAME_THREAD; return ExecutionMode.SAME_THREAD;
} }
throw new JUnitException("Unknown ExecutionMode: " + mode); throw new JUnitException("Unknown ExecutionMode: " + mode);
} }
protected Set<ExclusiveResource> getExclusiveResourcesFromAnnotation(Anno tatedElement element) { protected Set<ExclusiveResource> getExclusiveResourcesFromAnnotation(Anno tatedElement element) {
skipping to change at line 182 skipping to change at line 170
case READ: case READ:
return LockMode.READ; return LockMode.READ;
case READ_WRITE: case READ_WRITE:
return LockMode.READ_WRITE; return LockMode.READ_WRITE;
} }
throw new JUnitException("Unknown ResourceAccessMode: " + mode); throw new JUnitException("Unknown ResourceAccessMode: " + mode);
} }
@Override @Override
public SkipResult shouldBeSkipped(JupiterEngineExecutionContext context) throws Exception { public SkipResult shouldBeSkipped(JupiterEngineExecutionContext context) throws Exception {
context.getThrowableCollector().assertEmpty();
ConditionEvaluationResult evaluationResult = conditionEvaluator.e valuate(context.getExtensionRegistry(), ConditionEvaluationResult evaluationResult = conditionEvaluator.e valuate(context.getExtensionRegistry(),
context.getConfigurationParameters(), context.getExtensio nContext()); context.getConfiguration(), context.getExtensionContext() );
return toSkipResult(evaluationResult); return toSkipResult(evaluationResult);
} }
private SkipResult toSkipResult(ConditionEvaluationResult evaluationResul t) { private SkipResult toSkipResult(ConditionEvaluationResult evaluationResul t) {
if (evaluationResult.isDisabled()) { if (evaluationResult.isDisabled()) {
return SkipResult.skip(evaluationResult.getReason().orEls e("<unknown>")); return SkipResult.skip(evaluationResult.getReason().orEls e("<unknown>"));
} }
return SkipResult.doNotSkip(); return SkipResult.doNotSkip();
} }
 End of changes. 13 change blocks. 
36 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)