test: added simple-scenario test for DetectFinder
@@ -3,6 +3,7 @@ package com.synopsys.integration.detector.finder;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Assume;
import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
import java.io.File;
@@ -37,6 +38,36 @@ public class DetectorFinderTest {
initialDirectoryPath.toFile().delete();
}
+ @Test
+ @DisabledOnOs(WINDOWS) //TODO: See if we can fix on windows.
+ public void testSimple() throws IOException, DetectorFinderDirectoryListException {
+ Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);
+
+ final File initialDirectory = initialDirectoryPath.toFile();
+ final File subDir = new File(initialDirectory, "testSimple");
+ subDir.mkdirs();
+
+ final File subSubDir1 = new File(subDir, "subSubDir1");
+ subSubDir1.mkdir();
+
+ final File subSubDir2 = new File(subDir, "subSubDir2");
+ subSubDir2.mkdir();
+
+ final DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<>(0), new HashMap<>(0));
+ final Predicate<File> fileFilter = f -> { return true; };
+ final int maximumDepth = 10;
+ final DetectorFinderOptions options = new DetectorFinderOptions(fileFilter, maximumDepth);
+
+ final DetectorFinder finder = new DetectorFinder();
+ final Optional<DetectorEvaluationTree> tree = finder.findDetectors(initialDirectory, detectorRuleSet, options);
+
+ // make sure the symlink was omitted from results
+ final Set<DetectorEvaluationTree> subDirResults = tree.get().getChildren().iterator().next().getChildren();
+ assertEquals(2, subDirResults.size());
+ String subDirContentsName = subDirResults.iterator().next().getDirectory().getName();
+ assertTrue(subDirContentsName.startsWith("subSubDir"));
+ }
+
@Test
@DisabledOnOs(WINDOWS) //TODO: See if we can fix on windows.
public void testSymLinksNotFollowed() throws IOException, DetectorFinderDirectoryListException {
@@ -44,7 +75,7 @@ public class DetectorFinderTest {
// Create a subDir with a symlink that loops back to its parent
final File initialDirectory = initialDirectoryPath.toFile();
- final File subDir = new File(initialDirectory, "sub");
+ final File subDir = new File(initialDirectory, "testSymLinksNotFollowed");
subDir.mkdirs();
final File link = new File(subDir, "linkToInitial");
final Path linkPath = link.toPath();
@@ -53,7 +84,7 @@ public class DetectorFinderTest {
final File regularDir = new File(subDir, "regularDir");
regularDir.mkdir();
- final DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<DetectorRule>(0), new HashMap<DetectorRule, Set<DetectorRule>>(0));
+ final DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<>(0), new HashMap<>(0));
final Predicate<File> fileFilter = f -> { return true; };
final int maximumDepth = 10;
final DetectorFinderOptions options = new DetectorFinderOptions(fileFilter, maximumDepth);
