@Test public void shouldAcceptIssueIfFullyMatched() { String rule = "rule"; String path = "org/sonar/api/Issue.java"; String componentKey = "org.sonar.api.Issue"; RuleKey ruleKey = mock(RuleKey.class); when(ruleKey.toString()).thenReturn(rule); when(issue.ruleKey()).thenReturn(ruleKey); when(issue.componentKey()).thenReturn(componentKey); IssuePattern matching = mock(IssuePattern.class); WildcardPattern rulePattern = mock(WildcardPattern.class); when(matching.getRulePattern()).thenReturn(rulePattern); when(rulePattern.match(rule)).thenReturn(true); WildcardPattern pathPattern = mock(WildcardPattern.class); when(matching.getResourcePattern()).thenReturn(pathPattern); when(pathPattern.match(path)).thenReturn(true); when(exclusionPatternInitializer.getMulticriteriaPatterns()) .thenReturn(ImmutableList.of(matching)); when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(path); assertThat(ignoreFilter.accept(issue, chain)).isTrue(); verifyZeroInteractions(chain); }
@Test public void shouldPassToChainIfRuleDoesNotMatch() { String rule = "rule"; RuleKey ruleKey = mock(RuleKey.class); when(ruleKey.toString()).thenReturn(rule); when(issue.ruleKey()).thenReturn(ruleKey); IssuePattern matching = mock(IssuePattern.class); WildcardPattern rulePattern = mock(WildcardPattern.class); when(matching.getRulePattern()).thenReturn(rulePattern); when(rulePattern.match(rule)).thenReturn(false); when(exclusionPatternInitializer.getMulticriteriaPatterns()) .thenReturn(ImmutableList.of(matching)); assertThat(ignoreFilter.accept(issue, chain)).isTrue(); verify(chain).accept(issue); }
@Override public boolean matchFilePattern(String antPattern) { String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, "."); WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, "."); return matcher.match(getKey()); }
public boolean accept(File paramFile) { String absolutePath = paramFile.getAbsolutePath(); final String path = absolutePath; return pattern.match(convertSlash(path)); }