use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.
the class ExclusionPatternCreatorTest method testProducesCorrectExclusions.
@ParameterizedTest
@MethodSource("inputPatternsToExclusionsProvider")
public void testProducesCorrectExclusions(List<String> providedPatterns, List<String> resultingExclusions) throws IOException {
File root = new File("root");
root.mkdir();
File sub1 = new File(root, "sub1");
sub1.mkdir();
File sub2 = new File(root, "sub2");
sub2.mkdir();
File sub1Sub1 = new File(sub1, "sub1Sub1");
sub1Sub1.mkdir();
File sub1Sub2 = new File(sub1, "sub1Sub2");
sub1Sub2.mkdir();
File sub2Sub1 = new File(sub2, "sub2Sub1");
sub2Sub1.mkdir();
DetectExcludedDirectoryFilter filter = new DetectExcludedDirectoryFilter(providedPatterns);
ExclusionPatternCreator exclusionPatternCreator = new ExclusionPatternCreator(new SimpleFileFinder(), file -> filter.isExcluded(file), root);
assertEqualCollections(resultingExclusions, exclusionPatternCreator.determineExclusionPatterns(false, 3, providedPatterns));
FileUtils.deleteDirectory(root);
}
use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.
the class DetectExcludedDirectoryFilterTest method testIsExcludedDirectories.
@Test
void testIsExcludedDirectories() {
Path sourcePath = new File("my/file/path").toPath();
List<String> excludedDirectories = Arrays.asList("root", "root2");
DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(excludedDirectories);
File root = new File(sourcePath.toFile(), "root");
File root2 = new File(sourcePath.toFile(), "root2");
File doNotExcludeDir = new File(root, "doNotExclude");
assertTrue(detectExcludedDirectoryFilter.isExcluded(root));
assertTrue(detectExcludedDirectoryFilter.isExcluded(root2));
assertFalse(detectExcludedDirectoryFilter.isExcluded(doNotExcludeDir));
}
use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.
the class DetectExcludedDirectoryFilterTest method testCatchErrorWhenSourcePathDoesNotShareRootWithInspectedFile.
@EnabledOnOs(WINDOWS)
@Test
void testCatchErrorWhenSourcePathDoesNotShareRootWithInspectedFile() {
Path sourcePath = new File("D:\\").toPath();
File testFile = new File("C:\\");
DetectExcludedDirectoryFilter detectExcludedDirectoryFilter = new DetectExcludedDirectoryFilter(Arrays.asList("test"));
assertFalse(detectExcludedDirectoryFilter.isExcluded(testFile));
}
use of com.synopsys.integration.detect.util.finder.DetectExcludedDirectoryFilter in project synopsys-detect by blackducksoftware.
the class DetectExcludedDirectoryFilterTest method testIsExcludedDirectoryPathPatterns.
@ParameterizedTest
@MethodSource("inputPatternsToExclusionsProvider")
void testIsExcludedDirectoryPathPatterns(String exclusionPattern, boolean sub1Excluded, boolean sub2Excluded, boolean sub1Sub1Excluded, boolean sub1Sub2Excluded, boolean sub2Sub1Excluded) {
Path sourcePath = new File("").toPath();
DetectExcludedDirectoryFilter filter = new DetectExcludedDirectoryFilter(Collections.singletonList(exclusionPattern));
File root = new File("root");
File sub1 = new File(root, "sub1");
File sub2 = new File(root, "sub2");
File sub1Sub1 = new File(sub1, "sub1Sub1");
File sub1Sub2 = new File(sub1, "sub1Sub2");
File sub2Sub1 = new File(sub2, "sub2Sub1");
assertEquals(sub1Excluded, filter.isExcluded(sub1));
assertEquals(sub2Excluded, filter.isExcluded(sub2));
assertEquals(sub1Sub1Excluded, filter.isExcluded(sub1Sub1));
assertEquals(sub1Sub2Excluded, filter.isExcluded(sub1Sub2));
assertEquals(sub2Sub1Excluded, filter.isExcluded(sub2Sub1));
}
Aggregations