Search in sources :

Example 1 with IsTestClassWithTests

use of org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests in project graylog2-server by Graylog2.

the class ContainerMatrixClassSelectorResolver method resolve.

@Override
public Resolution resolve(UniqueIdSelector selector, Context context) {
    UniqueId uniqueId = selector.getUniqueId();
    UniqueId.Segment lastSegment = uniqueId.getLastSegment();
    if (ContainerMatrixTestClassDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String className = lastSegment.getValue();
        return ReflectionUtils.tryToLoadClass(className).toOptional().filter(isTestClassWithTests).map(testClass -> toResolution(context.addToParent(parent -> Optional.of(newClassTestDescriptor(parent, testClass))))).orElse(unresolved());
    }
    if (NestedClassTestDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String simpleClassName = lastSegment.getValue();
        return toResolution(context.addToParent(() -> selectUniqueId(uniqueId.removeLastSegment()), parent -> {
            if (parent instanceof ClassBasedTestDescriptor) {
                Class<?> parentTestClass = ((ClassBasedTestDescriptor) parent).getTestClass();
                return ReflectionUtils.findNestedClasses(parentTestClass, isNestedTestClass.and(where(Class::getSimpleName, isEqual(simpleClassName)))).stream().findFirst().flatMap(testClass -> Optional.of(newNestedClassTestDescriptor(parent, testClass)));
            }
            return Optional.empty();
        }));
    }
    return unresolved();
}
Also used : IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) IsTestClassWithTests(org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ReflectionUtils.findMethods(org.junit.platform.commons.util.ReflectionUtils.findMethods) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Collectors.toCollection(java.util.stream.Collectors.toCollection) IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass) MongodbServer(org.graylog.testing.containermatrix.MongodbServer) Resolution.unresolved(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.unresolved) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) Method(java.lang.reflect.Method) LinkedHashSet(java.util.LinkedHashSet) Lifecycle(org.graylog.testing.completebackend.Lifecycle) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) ContainerMatrixTestClassDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor) Predicate(java.util.function.Predicate) Set(java.util.Set) Predicate.isEqual(java.util.function.Predicate.isEqual) UniqueId(org.junit.platform.engine.UniqueId) ReflectionSupport.findNestedClasses(org.junit.platform.commons.support.ReflectionSupport.findNestedClasses) SearchVersion(org.graylog2.storage.SearchVersion) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) ContainerMatrixTestEngine(org.graylog.testing.containermatrix.ContainerMatrixTestEngine) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) NestedClassSelector(org.junit.platform.engine.discovery.NestedClassSelector) List(java.util.List) Stream(java.util.stream.Stream) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) SelectorResolver(org.junit.platform.engine.support.discovery.SelectorResolver) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) FunctionUtils.where(org.junit.platform.commons.util.FunctionUtils.where) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass)

Example 2 with IsTestClassWithTests

use of org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests in project junit5 by junit-team.

the class ClassSelectorResolver method resolve.

@Override
public Resolution resolve(UniqueIdSelector selector, Context context) {
    UniqueId uniqueId = selector.getUniqueId();
    UniqueId.Segment lastSegment = uniqueId.getLastSegment();
    if (ClassTestDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String className = lastSegment.getValue();
        return ReflectionUtils.tryToLoadClass(className).toOptional().filter(isTestClassWithTests).map(testClass -> toResolution(context.addToParent(parent -> Optional.of(newClassTestDescriptor(parent, testClass))))).orElse(unresolved());
    }
    if (NestedClassTestDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String simpleClassName = lastSegment.getValue();
        return toResolution(context.addToParent(() -> selectUniqueId(uniqueId.removeLastSegment()), parent -> {
            if (parent instanceof ClassBasedTestDescriptor) {
                Class<?> parentTestClass = ((ClassBasedTestDescriptor) parent).getTestClass();
                return ReflectionUtils.findNestedClasses(parentTestClass, isNestedTestClass.and(where(Class::getSimpleName, isEqual(simpleClassName)))).stream().findFirst().flatMap(testClass -> Optional.of(newNestedClassTestDescriptor(parent, testClass)));
            }
            return Optional.empty();
        }));
    }
    return unresolved();
}
Also used : IsTestClassWithTests(org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests) ReflectionUtils.findMethods(org.junit.platform.commons.util.ReflectionUtils.findMethods) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Collectors.toCollection(java.util.stream.Collectors.toCollection) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) Resolution.unresolved(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.unresolved) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) Method(java.lang.reflect.Method) IsTestClassWithTests.isTestOrTestFactoryOrTestTemplateMethod(org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.isTestOrTestFactoryOrTestTemplateMethod) LinkedHashSet(java.util.LinkedHashSet) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) Predicate(java.util.function.Predicate) Predicate.isEqual(java.util.function.Predicate.isEqual) Set(java.util.Set) ReflectionSupport.findNestedClasses(org.junit.platform.commons.support.ReflectionSupport.findNestedClasses) UniqueId(org.junit.platform.engine.UniqueId) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) NestedClassSelector(org.junit.platform.engine.discovery.NestedClassSelector) List(java.util.List) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Stream(java.util.stream.Stream) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) SelectorResolver(org.junit.platform.engine.support.discovery.SelectorResolver) FunctionUtils.where(org.junit.platform.commons.util.FunctionUtils.where) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass)

Aggregations

Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 Predicate.isEqual (java.util.function.Predicate.isEqual)2 Supplier (java.util.function.Supplier)2 Collectors.toCollection (java.util.stream.Collectors.toCollection)2 Stream (java.util.stream.Stream)2 JupiterConfiguration (org.junit.jupiter.engine.config.JupiterConfiguration)2 ClassBasedTestDescriptor (org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor)2 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)2 IsNestedTestClass (org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass)2 IsTestClassWithTests (org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests)2 ReflectionSupport.findNestedClasses (org.junit.platform.commons.support.ReflectionSupport.findNestedClasses)2 FunctionUtils.where (org.junit.platform.commons.util.FunctionUtils.where)2 ReflectionUtils (org.junit.platform.commons.util.ReflectionUtils)2 ReflectionUtils.findMethods (org.junit.platform.commons.util.ReflectionUtils.findMethods)2