import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleType;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
-public class NewIssuesStatisticsTest {
+class NewIssuesStatisticsTest {
private final Random random = new Random();
private RuleType randomRuleTypeExceptHotspot = RuleType.values()[random.nextInt(RuleType.values().length - 1)];
private NewIssuesStatistics underTest = new NewIssuesStatistics(Issue::isNew);
@Test
- public void add_issues_with_correct_global_statistics() {
+ void add_issues_with_correct_global_statistics() {
DefaultIssue issue = new DefaultIssue()
.setAssigneeUuid("maynard")
.setComponentUuid("file-uuid")
}
@Test
- public void add_counts_issues_on_current_analysis_globally_and_per_assignee() {
+ void add_counts_issues_on_current_analysis_globally_and_per_assignee() {
String assignee = randomAlphanumeric(10);
IntStream.range(0, 10)
.mapToObj(i -> new DefaultIssue().setAssigneeUuid(assignee).setNew(true))
}
@Test
- public void add_counts_issues_off_current_analysis_globally_and_per_assignee() {
+ void add_counts_issues_off_current_analysis_globally_and_per_assignee() {
String assignee = randomAlphanumeric(10);
IntStream.range(0, 10)
.mapToObj(i -> new DefaultIssue().setAssigneeUuid(assignee).setNew(false))
}
@Test
- public void add_counts_issue_per_component_on_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_component_on_current_analysis_globally_and_per_assignee() {
List<String> componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
String assignee = randomAlphanumeric(10);
componentUuids.stream()
.forEach(underTest::add);
DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT);
- DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT);
+ DistributedMetricStatsInt assigneeDistribution =
+ underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT);
Stream.of(globalDistribution, assigneeDistribution)
.forEach(distribution -> componentUuids.forEach(componentUuid -> assertStats(distribution, componentUuid, 1, 1)));
}
@Test
- public void add_counts_issue_per_component_off_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_component_off_current_analysis_globally_and_per_assignee() {
List<String> componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
String assignee = randomAlphanumeric(10);
componentUuids.stream()
}
@Test
- public void add_does_not_count_component_if_null_neither_globally_nor_per_assignee() {
+ void add_does_not_count_component_if_null_neither_globally_nor_per_assignee() {
String assignee = randomAlphanumeric(10);
underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setComponentUuid(null).setAssigneeUuid(assignee).setNew(new Random().nextBoolean()));
DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT);
- DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT);
+ DistributedMetricStatsInt assigneeDistribution =
+ underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT);
Stream.of(globalDistribution, assigneeDistribution)
.forEach(distribution -> {
assertThat(distribution.getTotal()).isZero();
}
@Test
- public void add_counts_issue_per_ruleKey_on_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_ruleKey_on_current_analysis_globally_and_per_assignee() {
String repository = randomAlphanumeric(3);
List<String> ruleKeys = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
String assignee = randomAlphanumeric(10);
}
@Test
- public void add_counts_issue_per_ruleKey_off_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_ruleKey_off_current_analysis_globally_and_per_assignee() {
String repository = randomAlphanumeric(3);
List<String> ruleKeys = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
String assignee = randomAlphanumeric(10);
.forEach(underTest::add);
DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE);
- DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE);
+ DistributedMetricStatsInt assigneeDistribution =
+ underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE);
Stream.of(globalDistribution, assigneeDistribution)
.forEach(distribution -> ruleKeys.forEach(ruleKey -> assertStats(distribution, RuleKey.of(repository, ruleKey).toString(), 0, 1)));
}
@Test
- public void add_does_not_count_ruleKey_if_null_neither_globally_nor_per_assignee() {
+ void add_does_not_count_ruleKey_if_null_neither_globally_nor_per_assignee() {
String assignee = randomAlphanumeric(10);
underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setRuleKey(null).setAssigneeUuid(assignee).setNew(new Random().nextBoolean()));
DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE);
- DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE);
+ DistributedMetricStatsInt assigneeDistribution =
+ underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE);
Stream.of(globalDistribution, assigneeDistribution)
.forEach(distribution -> {
assertThat(distribution.getTotal()).isZero();
}
@Test
- public void add_counts_issue_per_assignee_on_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_assignee_on_current_analysis_globally_and_per_assignee() {
List<String> assignees = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
assignees.stream()
.map(assignee -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setAssigneeUuid(assignee).setNew(true))
}
@Test
- public void add_counts_issue_per_assignee_off_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_assignee_off_current_analysis_globally_and_per_assignee() {
List<String> assignees = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
assignees.stream()
.map(assignee -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setAssigneeUuid(assignee).setNew(false))
}
@Test
- public void add_does_not_assignee_if_empty_neither_globally_nor_per_assignee() {
+ void add_does_not_assignee_if_empty_neither_globally_nor_per_assignee() {
underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setAssigneeUuid(null).setNew(new Random().nextBoolean()));
DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE);
}
@Test
- public void add_counts_issue_per_tags_on_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_tags_on_current_analysis_globally_and_per_assignee() {
List<String> tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
String assignee = randomAlphanumeric(10);
underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(tags).setAssigneeUuid(assignee).setNew(true));
}
@Test
- public void add_counts_issue_per_tags_off_current_analysis_globally_and_per_assignee() {
+ void add_counts_issue_per_tags_off_current_analysis_globally_and_per_assignee() {
List<String> tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).toList();
String assignee = randomAlphanumeric(10);
underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(tags).setAssigneeUuid(assignee).setNew(false));
}
@Test
- public void add_does_not_count_tags_if_empty_neither_globally_nor_per_assignee() {
+ void add_does_not_count_tags_if_empty_neither_globally_nor_per_assignee() {
String assignee = randomAlphanumeric(10);
underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setTags(Collections.emptyList()).setAssigneeUuid(assignee).setNew(new Random().nextBoolean()));
}
@Test
- public void do_not_have_issues_when_no_issue_added() {
+ void do_not_have_issues_when_no_issue_added() {
assertThat(underTest.globalStatistics().hasIssues()).isFalse();
}
@Test
- public void verify_toString() {
+ void verify_toString() {
String componentUuid = randomAlphanumeric(2);
String tag = randomAlphanumeric(3);
String assignee = randomAlphanumeric(4);