diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java index f14e09a..d5c7a95 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfiguration.java @@ -48,16 +48,11 @@ public class BuilderConfiguration { @Bean public Map> checkClasses(final PackageScanner packageScanner) { return Stream.of(RuleSource.values()) - .map(source -> entry(source, packageScanner.apply(source) - .collect(Collectors.toList()))) + .map(source -> entry(source, packageScanner.apply(source))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private static AbstractMap.SimpleEntry> entry( - final RuleSource key, - final List value - ) { + private static AbstractMap.SimpleEntry entry(final K key, final V value) { return new AbstractMap.SimpleEntry<>(key, value); } - } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java index 0628f4d..f193f1b 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScanner.java @@ -24,7 +24,8 @@ package net.kemitix.checkstyle.ruleset.builder; import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; import org.springframework.stereotype.Service; -import java.util.stream.Stream; +import java.util.List; +import java.util.stream.Collectors; /** * Default implementation of {@link PackageScanner}. @@ -35,12 +36,13 @@ import java.util.stream.Stream; public class DefaultPackageScanner implements PackageScanner { @Override - public final Stream apply(final RuleSource ruleSource) { + public final List apply(final RuleSource ruleSource) { final String basePackage = ruleSource.getBasePackage(); return new FastClasspathScanner(basePackage) .scan() .getNamesOfAllStandardClasses() .stream() - .filter(packageName -> packageName.startsWith(basePackage)); + .filter(packageName -> packageName.startsWith(basePackage)) + .collect(Collectors.toList()); } } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java index 7cc8c2b..02a59df 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/PackageScanner.java @@ -21,14 +21,14 @@ package net.kemitix.checkstyle.ruleset.builder; +import java.util.List; import java.util.function.Function; -import java.util.stream.Stream; /** * Scans a package for all classes. * * @author Paul Campbell (pcampbell@kemitix.net). */ -interface PackageScanner extends Function> { +interface PackageScanner extends Function> { } diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java index 63eb6c2..f9afaa8 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/BuilderConfigurationTest.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; +import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -20,29 +21,20 @@ import static org.mockito.Mockito.mock; */ public class BuilderConfigurationTest { - @Test - public void canGetClassPath() throws IOException { - //when - final BuilderConfiguration builderConfiguration = new BuilderConfiguration(); - final ClassPath classPath = builderConfiguration.classPath(builderConfiguration.getClass().getClassLoader()); - //then - assertThat(classPath).isNotNull(); - } - @Test public void canGetCheckClasses() { //given final PackageScanner packageScanner = mock(PackageScanner.class); final String checkstyleClass = "checkstyle class"; - given(packageScanner.apply(RuleSource.CHECKSTYLE)).willReturn(Stream.of(checkstyleClass)); + given(packageScanner.apply(RuleSource.CHECKSTYLE)).willReturn(singletonList(checkstyleClass)); final String sevntuClass = "sevntu class"; - given(packageScanner.apply(RuleSource.SEVNTU)).willReturn(Stream.of(sevntuClass)); + given(packageScanner.apply(RuleSource.SEVNTU)).willReturn(singletonList(sevntuClass)); //when final Map> checkClasses = new BuilderConfiguration().checkClasses(packageScanner); //then assertThat(checkClasses).containsOnlyKeys(RuleSource.values()); assertThat(checkClasses) - .containsEntry(RuleSource.CHECKSTYLE, Collections.singletonList(checkstyleClass)) - .containsEntry(RuleSource.SEVNTU, Collections.singletonList(sevntuClass)); + .containsEntry(RuleSource.CHECKSTYLE, singletonList(checkstyleClass)) + .containsEntry(RuleSource.SEVNTU, singletonList(sevntuClass)); } } diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java index 92ca00b..7b5a02e 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultPackageScannerTest.java @@ -2,6 +2,7 @@ package net.kemitix.checkstyle.ruleset.builder; import org.junit.Test; +import java.util.List; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -18,7 +19,7 @@ public class DefaultPackageScannerTest { @Test public void canScanCheckstylePackage() { //when - final Stream result = scanner.apply(RuleSource.CHECKSTYLE); + final List result = scanner.apply(RuleSource.CHECKSTYLE); //then assertThat(result).allMatch(cn -> cn.startsWith(RuleSource.CHECKSTYLE.getBasePackage())) .contains("com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck"); @@ -27,7 +28,7 @@ public class DefaultPackageScannerTest { @Test public void canScanSevntuPackage() { //when - final Stream result = scanner.apply(RuleSource.SEVNTU); + final List result = scanner.apply(RuleSource.SEVNTU); //then assertThat(result).allMatch(cn -> cn.startsWith(RuleSource.SEVNTU.getBasePackage())) .contains("com.github.sevntu.checkstyle.checks.design.NestedSwitchCheck");