Skip to content

Commit

Permalink
Failed resolution logging only for explicitly requested elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink authored and bechte committed Apr 29, 2016
1 parent 6bf76b6 commit 253a69d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
Expand Up @@ -10,6 +10,7 @@

package org.junit.gen5.engine.junit5.discoveryNEW;

import static java.lang.String.format;
import static org.junit.gen5.commons.util.ReflectionUtils.findMethods;

import java.lang.reflect.AnnotatedElement;
Expand All @@ -36,6 +37,8 @@

public class DiscoverySelectorResolver {

private static final Logger LOG = Logger.getLogger(DiscoverySelectorResolver.class.getName());

private final JUnit5EngineDescriptor engineDescriptor;
private final Set<ElementResolver> resolvers = new HashSet<>();

Expand All @@ -58,12 +61,24 @@ public void resolveSelectors(EngineDiscoveryRequest request) {
pruneTree();
}

private void pruneTree() {
TestDescriptor.Visitor removeDescriptorsWithoutTests = (descriptor, remove) -> {
if (!descriptor.isRoot() && !descriptor.hasTests())
remove.run();
};
engineDescriptor.accept(removeDescriptorsWithoutTests);
private void resolveClass(Class<?> testClass) {
Set<TestDescriptor> potentialParents = Collections.singleton(engineDescriptor);
if (resolveElementWithChildren(testClass, potentialParents).isEmpty()) {
LOG.info(() -> {
String classDescription = testClass.getName();
return format("Class '%s' could not be resolved", classDescription);
});
}
}

private void resolveMethod(Class<?> testClass, Method testMethod) {
Set<TestDescriptor> potentialParents = resolve(testClass, engineDescriptor);
if (resolveElementWithChildren(testMethod, potentialParents).isEmpty()) {
LOG.info(() -> {
String methodDescription = testMethod.getDeclaringClass().getName() + "#" + testMethod.getName();
return format("Method '%s' could not be resolved", methodDescription);
});
}
}

private void resolveUniqueId(UniqueId uniqueId) {
Expand All @@ -72,6 +87,14 @@ private void resolveUniqueId(UniqueId uniqueId) {
resolveUniqueId(engineDescriptor, segments);
}

private void pruneTree() {
TestDescriptor.Visitor removeDescriptorsWithoutTests = (descriptor, remove) -> {
if (!descriptor.isRoot() && !descriptor.hasTests())
remove.run();
};
engineDescriptor.accept(removeDescriptorsWithoutTests);
}

private void resolveUniqueId(TestDescriptor parent, List<UniqueId.Segment> remainingSegments) {
if (remainingSegments.isEmpty()) {
resolveChildren(parent);
Expand All @@ -93,22 +116,14 @@ private void resolveUniqueId(TestDescriptor parent, List<UniqueId.Segment> remai
});
}

private void resolveMethod(Class<?> testClass, Method testMethod) {
Set<TestDescriptor> potentialParents = resolve(testClass, engineDescriptor);
resolveElementWithChildren(testMethod, potentialParents);
}

private void resolveClass(Class<?> testClass) {
Set<TestDescriptor> potentialParents = Collections.singleton(engineDescriptor);
resolveElementWithChildren(testClass, potentialParents);
}

private void resolveElementWithChildren(AnnotatedElement element, Set<TestDescriptor> potentialParents) {
private Set<TestDescriptor> resolveElementWithChildren(AnnotatedElement element,
Set<TestDescriptor> potentialParents) {
Set<TestDescriptor> resolvedDescriptors = new HashSet<>();
potentialParents.forEach(parent -> {
resolvedDescriptors.addAll(resolve(element, parent));
});
resolvedDescriptors.forEach(this::resolveChildren);
return resolvedDescriptors;
}

private void resolveChildren(TestDescriptor descriptor) {
Expand Down
Expand Up @@ -28,22 +28,14 @@ public class TestContainerResolver implements ElementResolver {

public static final String SEGMENT_TYPE = "class";

private static final Logger LOG = Logger.getLogger(TestContainerResolver.class.getName());

@Override
public Set<TestDescriptor> resolve(AnnotatedElement element, TestDescriptor parent) {
if (!(element instanceof Class))
return Collections.emptySet();

Class<?> clazz = (Class<?>) element;
if (!isPotentialTestContainer(clazz)) {
LOG.info(() -> {
String classDescription = clazz.getName();
return format("Class '%s' is not a test container", classDescription);
});
if (!isPotentialTestContainer(clazz))
return Collections.emptySet();
}
;

UniqueId uniqueId = createUniqueId(clazz, parent);
return Collections.singleton(resolveClass(clazz, parent, uniqueId));
Expand Down
Expand Up @@ -30,8 +30,6 @@ public class TestMethodResolver implements ElementResolver {

public static final String SEGMENT_TYPE = "method";

private static final Logger LOG = Logger.getLogger(TestMethodResolver.class.getName());

private boolean canResolveElement(AnnotatedElement element, TestDescriptor parent) {
//Do not collapse
if (!(element instanceof Method))
Expand All @@ -50,14 +48,8 @@ public Set<TestDescriptor> resolve(AnnotatedElement element, TestDescriptor pare
return Collections.emptySet();

Method testMethod = (Method) element;
if (!isTestMethod(testMethod)) {
LOG.info(() -> {
String methodDescription = testMethod.getDeclaringClass().getName() + "#" + testMethod.getName();
return format("Method '%s' is not a test method", methodDescription);
});

if (!isTestMethod(testMethod))
return Collections.emptySet();
}

UniqueId uniqueId = createUniqueId(testMethod, parent);
return Collections.singleton(resolveMethod(testMethod, (ClassTestDescriptor) parent, uniqueId));
Expand Down

0 comments on commit 253a69d

Please sign in to comment.