*/
package org.sonar.core.issue;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
+import com.google.common.collect.HashMultiset;
+import com.google.common.collect.Multiset;
import org.sonar.api.issue.Issue;
public class IssuesBySeverity {
- private Multimap<String, Issue> issuesBySeverity = ArrayListMultimap.create();
+ private final Multiset<String> issuesBySeverity;
public IssuesBySeverity() {
- this.issuesBySeverity = ArrayListMultimap.create();
+ issuesBySeverity = HashMultiset.create();
}
public void add(Issue issue) {
- issuesBySeverity.put(issue.severity(), issue);
+ issuesBySeverity.add(issue.severity());
}
public int issues(String severity) {
- return issuesBySeverity.get(severity).size();
+ return issuesBySeverity.count(severity);
}
public int size() {
- return issuesBySeverity.values().size();
+ return issuesBySeverity.size();
}
public boolean isEmpty() {
- return issuesBySeverity.values().isEmpty();
+ return issuesBySeverity.isEmpty();
}
}
public class IssuesBySeverityTest {
+ IssuesBySeverity sut;
+
@Test
- public void add_issue(){
- IssuesBySeverity issuesBySeverity = new IssuesBySeverity();
- issuesBySeverity.add(new DefaultIssue().setSeverity("MINOR"));
- assertThat(issuesBySeverity.size()).isEqualTo(1);
+ public void add_issue() {
+ sut = new IssuesBySeverity();
+
+ sut.add(new DefaultIssue().setSeverity("MINOR"));
+
+ assertThat(sut.isEmpty()).isFalse();
+ assertThat(sut.size()).isEqualTo(1);
}
@Test
- public void get_issues_by_severity(){
- IssuesBySeverity issuesBySeverity = new IssuesBySeverity();
- issuesBySeverity.add(new DefaultIssue().setSeverity("MINOR"));
- issuesBySeverity.add(new DefaultIssue().setSeverity("MINOR"));
- issuesBySeverity.add(new DefaultIssue().setSeverity("MAJOR"));
- assertThat(issuesBySeverity.issues("MINOR")).isEqualTo(2);
- assertThat(issuesBySeverity.issues("MAJOR")).isEqualTo(1);
+ public void get_issues_by_severity() {
+ sut = new IssuesBySeverity();
+
+ sut.add(new DefaultIssue().setSeverity("MINOR"));
+ sut.add(new DefaultIssue().setSeverity("MINOR"));
+ sut.add(new DefaultIssue().setSeverity("MAJOR"));
+
+ assertThat(sut.issues("MINOR")).isEqualTo(2);
+ assertThat(sut.issues("MAJOR")).isEqualTo(1);
}
@Test
- public void get_zero_issues_on_empty_severity(){
- IssuesBySeverity issuesBySeverity = new IssuesBySeverity();
- issuesBySeverity.add(new DefaultIssue().setSeverity("MAJOR"));
- assertThat(issuesBySeverity.issues("MINOR")).isEqualTo(0);
+ public void get_zero_issues_on_empty_severity() {
+ sut = new IssuesBySeverity();
+
+ sut.add(new DefaultIssue().setSeverity("MAJOR"));
+
+ assertThat(sut.issues("MINOR")).isEqualTo(0);
+ }
+
+ @Test
+ public void is_empty() throws Exception {
+ sut = new IssuesBySeverity();
+
+ assertThat(sut.isEmpty()).isTrue();
}
}