use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class DefaultIssueCallbackTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
RuleKey ruleKey = RuleKey.of("repo", "key");
issue = new TrackedIssue();
issue.setKey("key");
issue.setAssignee("user");
issue.setRuleKey(ruleKey);
when(issueCache.all()).thenReturn(ImmutableList.of(issue));
ScannerInput.User.Builder userBuilder = ScannerInput.User.newBuilder();
userBuilder.setLogin("user");
userBuilder.setName("name");
when(userRepository.map(Collections.singleton("user"))).thenReturn(Collections.singletonMap("user", userBuilder.build()));
Rule r = mock(Rule.class);
when(r.name()).thenReturn("rule name");
when(rules.find(ruleKey)).thenReturn(r);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldPassToChainIfRuleDoesNotMatch.
@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);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesAndPathUnknown.
@Test
public void shouldRefuseIssueIfRuleMatchesAndPathUnknown() {
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(false);
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(null);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyZeroInteractions(chain);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesButNotPath.
@Test
public void shouldRefuseIssueIfRuleMatchesButNotPath() {
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(false);
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(path);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyZeroInteractions(chain);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class IssuePatternTest method create.
private FilterableIssue create(Rule rule, String component, Integer line) {
FilterableIssue mockIssue = mock(FilterableIssue.class);
RuleKey ruleKey = null;
if (rule != null) {
ruleKey = rule.ruleKey();
}
when(mockIssue.ruleKey()).thenReturn(ruleKey);
when(mockIssue.componentKey()).thenReturn(component);
when(mockIssue.line()).thenReturn(line);
return mockIssue;
}
Aggregations