2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.plugins.core.issue;
22 import org.junit.Test;
23 import org.sonar.api.batch.DecoratorContext;
24 import org.sonar.api.component.ResourcePerspectives;
25 import org.sonar.api.issue.Issuable;
26 import org.sonar.api.issue.Issue;
27 import org.sonar.api.measures.CoreMetrics;
28 import org.sonar.api.resources.File;
29 import org.sonar.api.resources.Project;
30 import org.sonar.api.rule.RuleKey;
31 import org.sonar.core.issue.DefaultIssue;
32 import org.sonar.java.api.JavaClass;
34 import java.util.Arrays;
36 import static org.fest.assertions.Assertions.assertThat;
37 import static org.mockito.Mockito.*;
39 public class CountFalsePositivesDecoratorTest {
41 ResourcePerspectives perspectives = mock(ResourcePerspectives.class);
42 CountFalsePositivesDecorator decorator = new CountFalsePositivesDecorator(perspectives);
45 public void should_count_false_positives() {
46 DefaultIssue falsePositive = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
47 .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_OPEN);
48 DefaultIssue open = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
49 .setResolution(null).setStatus(Issue.STATUS_OPEN);
51 File file = new File("foo.c");
52 Issuable issuable = mock(Issuable.class);
53 when(perspectives.as(Issuable.class, file)).thenReturn(issuable);
54 when(issuable.issues()).thenReturn(Arrays.<Issue>asList(falsePositive, open));
56 DecoratorContext context = mock(DecoratorContext.class);
57 decorator.decorate(file, context);
59 verify(context).saveMeasure(CoreMetrics.FALSE_POSITIVE_ISSUES, 1.0);
63 public void should_declare_metadata() {
64 assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isTrue();
65 assertThat(decorator.generatesFalsePositiveMeasure()).isEqualTo(CoreMetrics.FALSE_POSITIVE_ISSUES);
66 assertThat(decorator.toString()).isEqualTo("CountFalsePositivesDecorator");
70 public void should_ignore_classes_and_methods() {
71 JavaClass javaClass = JavaClass.create("Foo.java");
72 when(perspectives.as(Issuable.class, javaClass)).thenReturn(null);
74 DecoratorContext context = mock(DecoratorContext.class);
75 decorator.decorate(javaClass, context);
77 verifyZeroInteractions(context);