org.junit.platform.engine.EngineDiscoveryRequest Java Examples

The following examples show how to use org.junit.platform.engine.EngineDiscoveryRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyCustomEngine.java    From mastering-junit5 with Apache License 2.0 5 votes vote down vote up
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest,
        UniqueId uniqueId) {
    // Discover test(s) and return a TestDescriptor object
    TestDescriptor testDescriptor = new EngineDescriptor(uniqueId,
            "My test");
    return testDescriptor;
}
 
Example #2
Source File: MyCustomEngine.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest,
        UniqueId uniqueId) {
    // Discover test(s) and return a TestDescriptor object
    TestDescriptor testDescriptor = new EngineDescriptor(uniqueId,
            "My test");
    return testDescriptor;
}
 
Example #3
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
    ArchUnitEngineDescriptor result = new ArchUnitEngineDescriptor(uniqueId);

    resolveRequestedClasspathRoot(discoveryRequest, uniqueId, result);
    resolveRequestedPackages(discoveryRequest, uniqueId, result);
    resolveRequestedClasses(discoveryRequest, uniqueId, result);
    resolveRequestedMethods(discoveryRequest, uniqueId, result);
    resolveRequestedFields(discoveryRequest, uniqueId, result);
    resolveRequestedUniqueIds(discoveryRequest, uniqueId, result);

    return result;
}
 
Example #4
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private void resolveRequestedClasspathRoot(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    Stream<JavaClass> classes = discoveryRequest.getSelectorsByType(ClasspathRootSelector.class).stream()
            .flatMap(this::getContainedClasses);
    filterCandidatesAndLoadClasses(classes, discoveryRequest)
            .forEach(clazz -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, clazz), cache.get()));
}
 
Example #5
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private void resolveRequestedPackages(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    String[] packages = discoveryRequest.getSelectorsByType(PackageSelector.class).stream()
            .map(PackageSelector::getPackageName)
            .toArray(String[]::new);
    Stream<JavaClass> classes = getContainedClasses(packages);

    filterCandidatesAndLoadClasses(classes, discoveryRequest)
            .forEach(clazz -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, clazz), cache.get()));
}
 
Example #6
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private void resolveRequestedClasses(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    discoveryRequest.getSelectorsByType(ClassSelector.class).stream()
            .map(ClassSelector::getJavaClass)
            .filter(this::isArchUnitTestCandidate)
            .forEach(clazz -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, clazz), cache.get()));
}
 
Example #7
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private Predicate<JavaClass> isAllowedBy(EngineDiscoveryRequest discoveryRequest) {
    List<Predicate<String>> filters = Stream
            .concat(discoveryRequest.getFiltersByType(ClassNameFilter.class).stream(),
                    discoveryRequest.getFiltersByType(PackageNameFilter.class).stream())
            .map(Filter::toPredicate)
            .collect(toList());

    return javaClass -> filters.stream().allMatch(p -> p.test(javaClass.getName()));
}
 
Example #8
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private Stream<Class<?>> filterCandidatesAndLoadClasses(Stream<JavaClass> classes, EngineDiscoveryRequest discoveryRequest) {
    return classes
            .filter(isAllowedBy(discoveryRequest))
            .filter(this::isArchUnitTestCandidate)
            .flatMap(this::safelyReflect);
}
 
Example #9
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private void resolveRequestedMethods(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    discoveryRequest.getSelectorsByType(MethodSelector.class).stream()
            .filter(s -> s.getJavaMethod().isAnnotationPresent(ArchTest.class))
            .forEach(selector -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, selector.getJavaClass(), selector.getJavaMethod()), cache.get()));
}
 
Example #10
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private void resolveRequestedFields(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    discoveryRequest.getSelectorsByType(FieldSelector.class).stream()
            .filter(s -> s.getJavaField().isAnnotationPresent(ArchTest.class))
            .forEach(selector -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, selector.getJavaClass(), selector.getJavaField()), cache.get()));
}
 
Example #11
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private void resolveRequestedUniqueIds(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    discoveryRequest.getSelectorsByType(UniqueIdSelector.class).stream()
            .filter(selector -> selector.getUniqueId().getEngineId().equals(Optional.of(getId())))
            .forEach(selector -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, selector.getUniqueId()), cache.get()));
}