@Test
public void should_count_false_positives() {
DefaultIssue falsePositive = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
- .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_OPEN);
- DefaultIssue open = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
- .setResolution(null).setStatus(Issue.STATUS_OPEN);
+ .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_RESOLVED);
+ DefaultIssue fixed = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
+ .setResolution(Issue.RESOLUTION_FIXED).setStatus(Issue.STATUS_RESOLVED);
File file = new File("foo.c");
Issuable issuable = mock(Issuable.class);
when(perspectives.as(Issuable.class, file)).thenReturn(issuable);
- when(issuable.issues()).thenReturn(Arrays.<Issue>asList(falsePositive, open));
+ when(issuable.resolvedIssues()).thenReturn(Arrays.<Issue>asList(falsePositive, fixed));
DecoratorContext context = mock(DecoratorContext.class);
decorator.decorate(file, context);
@Test
public void should_count_issues() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(issuable.unresolvedIssues()).thenReturn(createIssues());
+ when(issuable.issues()).thenReturn(createissues());
when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
@Test
public void should_not_count_issues_if_measure_already_exists() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(issuable.unresolvedIssues()).thenReturn(createIssues());
+ when(issuable.issues()).thenReturn(createissues());
when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
when(context.getMeasure(CoreMetrics.VIOLATIONS)).thenReturn(new Measure(CoreMetrics.VIOLATIONS, 3000.0));
when(context.getMeasure(CoreMetrics.MAJOR_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.MAJOR_VIOLATIONS, 500.0));
@Test
public void should_save_zero_on_projects() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(issuable.unresolvedIssues()).thenReturn(Lists.<Issue>newArrayList());
+ when(issuable.issues()).thenReturn(Lists.<Issue>newArrayList());
when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
@Test
public void should_save_zero_on_directories() {
when(resource.getScope()).thenReturn(Scopes.DIRECTORY);
- when(issuable.unresolvedIssues()).thenReturn(Lists.<Issue>newArrayList());
+ when(issuable.issues()).thenReturn(Lists.<Issue>newArrayList());
when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
@Test
public void should_count_issues_by_severity() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(issuable.unresolvedIssues()).thenReturn(createIssues());
+ when(issuable.issues()).thenReturn(createissues());
when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
issues.add(new DefaultIssue().setRuleKey(ruleA2.ruleKey()).setSeverity(RulePriority.MAJOR.name()));
- when(issuable.unresolvedIssues()).thenReturn(issues);
+ when(issuable.issues()).thenReturn(issues);
decorator.decorate(resource, context);
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.MINOR.name()));
- when(issuable.unresolvedIssues()).thenReturn(issues);
+ when(issuable.issues()).thenReturn(issues);
decorator.decorate(resource, context);
public void should_clear_cache_after_execution() {
Issue issue1 = new DefaultIssue().setRuleKey(RuleKey.of(ruleA1.getRepositoryKey(), ruleA1.getKey())).setSeverity(RulePriority.CRITICAL.name()).setCreationDate(rightNow);
Issue issue2 = new DefaultIssue().setRuleKey(RuleKey.of(ruleA2.getRepositoryKey(), ruleA2.getKey())).setSeverity(RulePriority.CRITICAL.name()).setCreationDate(rightNow);
- when(issuable.unresolvedIssues()).thenReturn(newArrayList(issue1)).thenReturn(newArrayList(issue2));
+ when(issuable.issues()).thenReturn(newArrayList(issue1)).thenReturn(newArrayList(issue2));
decorator.decorate(resource, context);
decorator.decorate(resource, context);
@Test
public void should_save_severity_new_issues() {
- when(issuable.unresolvedIssues()).thenReturn(createIssuesForNewMetrics());
+ when(issuable.issues()).thenReturn(createIssuesForNewMetrics());
decorator.decorate(resource, context);
@Test
public void should_save_rule_new_issues() {
- when(issuable.unresolvedIssues()).thenReturn(createIssuesForNewMetrics());
+ when(issuable.issues()).thenReturn(createIssuesForNewMetrics());
decorator.decorate(resource, context);
@Test
public void should_not_save_new_issues_if_measure_already_computed() {
when(context.getMeasure(CoreMetrics.NEW_VIOLATIONS)).thenReturn(new Measure());
- when(issuable.unresolvedIssues()).thenReturn(createIssuesForNewMetrics());
+ when(issuable.issues()).thenReturn(createIssuesForNewMetrics());
decorator.decorate(resource, context);
verify(context, never()).saveMeasure(argThat(new IsMetricMeasure(CoreMetrics.NEW_CRITICAL_VIOLATIONS)));
}
- List<Issue> createIssues() {
+ List<Issue> createissues() {
List<Issue> issues = newArrayList();
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(Severity.CRITICAL).setStatus(Issue.STATUS_OPEN));
issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(Severity.CRITICAL).setStatus(Issue.STATUS_REOPENED));
Component component = mock(Component.class);
@Test
- public void test_unresolvedIssues() throws Exception {
+ public void test_unresolved_issues() throws Exception {
when(component.key()).thenReturn("struts:org.apache.Action");
DefaultIssue resolved = new DefaultIssue().setResolution(Issue.RESOLUTION_FALSE_POSITIVE);
DefaultIssue unresolved = new DefaultIssue();
DefaultIssuable perspective = new DefaultIssuable(component, scanIssues, cache);
- List<Issue> issues = perspective.unresolvedIssues();
+ List<Issue> issues = perspective.issues();
assertThat(issues).containsOnly(unresolved);
}
@Test
- public void test_issues() throws Exception {
+ public void test_resolved_issues() throws Exception {
when(component.key()).thenReturn("struts:org.apache.Action");
DefaultIssue resolved = new DefaultIssue().setResolution(Issue.RESOLUTION_FALSE_POSITIVE);
DefaultIssue unresolved = new DefaultIssue();
DefaultIssuable perspective = new DefaultIssuable(component, scanIssues, cache);
- List<Issue> issues = perspective.issues();
- assertThat(issues).containsOnly(unresolved, resolved);
+ List<Issue> issues = perspective.resolvedIssues();
+ assertThat(issues).containsOnly(resolved);
}
}