Search in sources :

Example 11 with SimpleFileFinder

use of com.synopsys.integration.common.util.finder.SimpleFileFinder in project synopsys-detect by blackducksoftware.

the class SimpleFileFinderTest method testFindWithPredicate.

@Test
public void testFindWithPredicate() throws IOException {
    File initialDirectory = initialDirectoryPath.toFile();
    File subDir1 = new File(initialDirectory, "sub1");
    subDir1.mkdirs();
    File subDirChild1 = new File(subDir1, "child");
    subDirChild1.createNewFile();
    File subDir2 = new File(initialDirectory, "sub2");
    subDir2.mkdirs();
    File subDirChild2 = new File(subDir2, "child");
    subDirChild2.createNewFile();
    SimpleFileFinder fileFinder = new SimpleFileFinder();
    Predicate<File> filter = file -> file.getName().startsWith("sub");
    List<File> foundFiles = fileFinder.findFiles(initialDirectoryPath.toFile(), filter, false, 10);
    assertEquals(2, foundFiles.size());
    assertFalse(foundFiles.contains(subDirChild2));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) File(java.io.File) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) WINDOWS(org.junit.jupiter.api.condition.OS.WINDOWS) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)11 File (java.io.File)10 Test (org.junit.jupiter.api.Test)6 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)4 EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)3 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)2 ExtractionEnvironmentProvider (com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider)2 DetectDirectoryFileFilter (com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter)2 DetectExcludedDirectoryFilter (com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter)2 DirectoryManager (com.synopsys.integration.detect.workflow.file.DirectoryManager)2 StatusEventPublisher (com.synopsys.integration.detect.workflow.status.StatusEventPublisher)2 DetectorEvaluationOptions (com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions)2 DetectorFinder (com.synopsys.integration.detector.finder.DetectorFinder)2 DetectorFinderOptions (com.synopsys.integration.detector.finder.DetectorFinderOptions)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Predicate (java.util.function.Predicate)2