Skip to content

Commit

Permalink
methods can be resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Nov 4, 2015
1 parent a150c7c commit 3f9923b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 452 deletions.

This file was deleted.

This file was deleted.

Expand Up @@ -15,7 +15,6 @@
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;

import org.junit.gen5.commons.util.AnnotationUtils;
import org.junit.gen5.engine.AbstractTestDescriptor;
import org.junit.gen5.engine.ClassNameSpecification;
Expand Down Expand Up @@ -65,14 +64,23 @@ private void resolveUniqueId(UniqueId uniqueId) {
}
}

private void resolveMethod(Method method, String uniqueId, EngineDescriptor root, boolean withChildren) {
private void resolveMethod(Method method, String uniqueId, AbstractTestDescriptor parent, boolean withChildren) {
if (!methodTester.accept(method)) {
throwCannotResolveMethodException(method);
}
Class<?> enclosingClass = method.getDeclaringClass();
UniqueId parentId = UniqueId.fromClass(enclosingClass, root);
parent = resolveClass(enclosingClass, parentId.getUniqueId(), parent, false);

MethodTestDescriptor descriptor = getOrCreateMethodDescriptor(method, uniqueId);
parent.addChild(descriptor);
testDescriptors.add(descriptor);

//todo methods could have children too
}

private ClassTestDescriptor resolveClass(Class<?> clazz, String uniqueId, AbstractTestDescriptor parent,
boolean withChildren) {
boolean withChildren) {
if (!classTester.accept(clazz)) {
throwCannotResolveClassException(clazz);
}
Expand All @@ -81,7 +89,7 @@ private ClassTestDescriptor resolveClass(Class<?> clazz, String uniqueId, Abstra
UniqueId parentId = UniqueId.fromClass(enclosingClass, root);
parent = resolveClass(enclosingClass, parentId.getUniqueId(), parent, false);
}
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId, clazz);
ClassTestDescriptor descriptor = getOrCreateClassDescriptor(clazz, uniqueId);
parent.addChild(descriptor);
testDescriptors.add(descriptor);

Expand All @@ -91,14 +99,44 @@ private ClassTestDescriptor resolveClass(Class<?> clazz, String uniqueId, Abstra

for (Method method : testMethodCandidates) {
UniqueId methodId = UniqueId.fromMethod(method, clazz, root);
MethodTestDescriptor methodDescriptor = new MethodTestDescriptor(methodId.getUniqueId(), method);
MethodTestDescriptor methodDescriptor = getOrCreateMethodDescriptor(method, methodId.getUniqueId());
descriptor.addChild(methodDescriptor);
testDescriptors.add(methodDescriptor);
}
}
return descriptor;
}

private MethodTestDescriptor getOrCreateMethodDescriptor(Method method, String uniqueId) {
TestDescriptor existingDescriptor = descriptorByUniqueId(uniqueId);
if (existingDescriptor == null) {
return new MethodTestDescriptor(uniqueId, method);
}
else {
return (MethodTestDescriptor) existingDescriptor;
}
}

private ClassTestDescriptor getOrCreateClassDescriptor(Class<?> clazz, String uniqueId) {
TestDescriptor existingDescriptor = descriptorByUniqueId(uniqueId);
if (existingDescriptor == null) {
return new ClassTestDescriptor(uniqueId, clazz);
}
else {
return (ClassTestDescriptor) existingDescriptor;
}
}

private TestDescriptor descriptorByUniqueId(String uniqueId) {
for (TestDescriptor descriptor : testDescriptors) {
if (descriptor.getUniqueId().equals(uniqueId)) {
return descriptor;
}
}
return null;
}


private static void throwCannotResolveMethodException(Method method) {
throw new IllegalArgumentException(String.format("Method '%s' is not a test method.", method.getName()));
}
Expand Down

0 comments on commit 3f9923b

Please sign in to comment.