Skip to content

Commit

Permalink
Extract more methods to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Dec 31, 2024
1 parent 6db5a0d commit 529da15
Showing 1 changed file with 59 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public SuiteLauncherDiscoveryRequestBuilder applyConfigurationParametersFromSuit
* <li>{@link SelectModules}</li>
* <li>{@link SelectUris}</li>
* <li>{@link SelectPackages}</li>
* <li>{@link Select}</li>
* </ul>
*
* @param suiteClass the class to apply the discovery selectors and filter
Expand All @@ -349,71 +350,84 @@ public SuiteLauncherDiscoveryRequestBuilder applyConfigurationParametersFromSuit
public SuiteLauncherDiscoveryRequestBuilder applySelectorsAndFiltersFromSuite(Class<?> suiteClass) {
Preconditions.notNull(suiteClass, "Suite class must not be null");

// Annotations in alphabetical order (except @SelectClasses)
// @formatter:off
findAnnotationValues(suiteClass, ExcludeClassNamePatterns.class, ExcludeClassNamePatterns::value)
.flatMap(SuiteLauncherDiscoveryRequestBuilder::trimmed)
.map(ClassNameFilter::excludeClassNamePatterns)
addExcludeFilters(suiteClass);
// Process @SelectClasses and @SelectMethod before @IncludeClassNamePatterns, since the names
// of selected classes get automatically added to the include filter.
addClassAndMethodSelectors(suiteClass);
addIncludeFilters(suiteClass);
addOtherSelectors(suiteClass);
return this;
}

private void addExcludeFilters(Class<?> suiteClass) {
findAnnotationValues(suiteClass, ExcludeClassNamePatterns.class, ExcludeClassNamePatterns::value) //
.flatMap(SuiteLauncherDiscoveryRequestBuilder::trimmed) //
.map(ClassNameFilter::excludeClassNamePatterns) //
.ifPresent(this::filters);
findAnnotationValues(suiteClass, ExcludeEngines.class, ExcludeEngines::value)
.map(EngineFilter::excludeEngines)
findAnnotationValues(suiteClass, ExcludeEngines.class, ExcludeEngines::value) //
.map(EngineFilter::excludeEngines) //
.ifPresent(this::filters);
findAnnotationValues(suiteClass, ExcludePackages.class, ExcludePackages::value)
.map(PackageNameFilter::excludePackageNames)
findAnnotationValues(suiteClass, ExcludePackages.class, ExcludePackages::value) //
.map(PackageNameFilter::excludePackageNames) //
.ifPresent(this::filters);
findAnnotationValues(suiteClass, ExcludeTags.class, ExcludeTags::value)
.map(TagFilter::excludeTags)
findAnnotationValues(suiteClass, ExcludeTags.class, ExcludeTags::value) //
.map(TagFilter::excludeTags) //
.ifPresent(this::filters);
// Process @SelectClasses before @IncludeClassNamePatterns, since the names
// of selected classes get automatically added to the include filter.
findAnnotation(suiteClass, SelectClasses.class)
.map(annotation -> selectClasses(suiteClass, annotation))
}

private void addClassAndMethodSelectors(Class<?> suiteClass) {
findAnnotation(suiteClass, SelectClasses.class) //
.map(annotation -> selectClasses(suiteClass, annotation)) //
.ifPresent(this::selectors);
findRepeatableAnnotations(suiteClass, SelectMethod.class)
.stream()
.map(annotation -> selectMethod(suiteClass, annotation))
findRepeatableAnnotations(suiteClass, SelectMethod.class) //
.stream() //
.map(annotation -> selectMethod(suiteClass, annotation)) //
.forEach(this::selectors);
findAnnotationValues(suiteClass, IncludeClassNamePatterns.class, IncludeClassNamePatterns::value)
.flatMap(SuiteLauncherDiscoveryRequestBuilder::trimmed)
.map(this::createIncludeClassNameFilter)
}

private void addIncludeFilters(Class<?> suiteClass) {
findAnnotationValues(suiteClass, IncludeClassNamePatterns.class, IncludeClassNamePatterns::value) //
.flatMap(SuiteLauncherDiscoveryRequestBuilder::trimmed) //
.map(this::createIncludeClassNameFilter) //
.ifPresent(filters -> {
this.includeClassNamePatternsUsed = true;
filters(filters);
});
findAnnotationValues(suiteClass, IncludeEngines.class, IncludeEngines::value)
.map(EngineFilter::includeEngines)
findAnnotationValues(suiteClass, IncludeEngines.class, IncludeEngines::value) //
.map(EngineFilter::includeEngines) //
.ifPresent(this::filters);
findAnnotationValues(suiteClass, IncludePackages.class, IncludePackages::value)
.map(PackageNameFilter::includePackageNames)
findAnnotationValues(suiteClass, IncludePackages.class, IncludePackages::value) //
.map(PackageNameFilter::includePackageNames) //
.ifPresent(this::filters);
findAnnotationValues(suiteClass, IncludeTags.class, IncludeTags::value)
.map(TagFilter::includeTags)
findAnnotationValues(suiteClass, IncludeTags.class, IncludeTags::value) //
.map(TagFilter::includeTags) //
.ifPresent(this::filters);
findRepeatableAnnotations(suiteClass, SelectClasspathResource.class)
.stream()
.map(annotation -> selectClasspathResource(annotation.value(), annotation.line(), annotation.column()))
}

private void addOtherSelectors(Class<?> suiteClass) {
findRepeatableAnnotations(suiteClass, SelectClasspathResource.class) //
.stream() //
.map(annotation -> selectClasspathResource(annotation.value(), annotation.line(), annotation.column())) //
.forEach(this::selectors);
findAnnotationValues(suiteClass, SelectDirectories.class, SelectDirectories::value)
.map(AdditionalDiscoverySelectors::selectDirectories)
findAnnotationValues(suiteClass, SelectDirectories.class, SelectDirectories::value) //
.map(AdditionalDiscoverySelectors::selectDirectories) //
.ifPresent(this::selectors);
findRepeatableAnnotations(suiteClass, SelectFile.class)
.stream()
.map(annotation -> selectFile(annotation.value(), annotation.line(), annotation.column()))
findRepeatableAnnotations(suiteClass, SelectFile.class) //
.stream() //
.map(annotation -> selectFile(annotation.value(), annotation.line(), annotation.column())) //
.forEach(this::selectors);
findAnnotationValues(suiteClass, SelectModules.class, SelectModules::value)
.map(AdditionalDiscoverySelectors::selectModules)
findAnnotationValues(suiteClass, SelectModules.class, SelectModules::value) //
.map(AdditionalDiscoverySelectors::selectModules) //
.ifPresent(this::selectors);
findAnnotationValues(suiteClass, SelectUris.class, SelectUris::value)
.map(AdditionalDiscoverySelectors::selectUris)
findAnnotationValues(suiteClass, SelectUris.class, SelectUris::value) //
.map(AdditionalDiscoverySelectors::selectUris) //
.ifPresent(this::selectors);
findAnnotationValues(suiteClass, SelectPackages.class, SelectPackages::value)
.map(AdditionalDiscoverySelectors::selectPackages)
findAnnotationValues(suiteClass, SelectPackages.class, SelectPackages::value) //
.map(AdditionalDiscoverySelectors::selectPackages) //
.ifPresent(this::selectors);
findAnnotationValues(suiteClass, Select.class, Select::value)
.map(AdditionalDiscoverySelectors::parseIdentifiers)
findAnnotationValues(suiteClass, Select.class, Select::value) //
.map(AdditionalDiscoverySelectors::parseIdentifiers) //
.ifPresent(this::selectors);
// @formatter:on
return this;
}

/**
Expand Down

0 comments on commit 529da15

Please sign in to comment.