diff options
author | Eric Giffon <eric.giffon@sonarsource.com> | 2023-12-28 16:11:34 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-12-29 20:02:26 +0000 |
commit | 7c69511f06b2d103f649e33c06534630a6561f4e (patch) | |
tree | e4da705ea114049809a01bb2dbd6a2c199440553 /server/sonar-server-common/src/test/java | |
parent | c930996a60de1ec40addb5f43f0f98d54fb86deb (diff) | |
download | sonarqube-7c69511f06b2d103f649e33c06534630a6561f4e.tar.gz sonarqube-7c69511f06b2d103f649e33c06534630a6561f4e.zip |
SONAR-21373 Remove type and debt from email notifications
Diffstat (limited to 'server/sonar-server-common/src/test/java')
3 files changed, 120 insertions, 233 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index b214a787d5c..bdc93a772cd 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -23,34 +23,26 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.sonar.api.config.EmailSettings; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.notifications.Notification; import org.sonar.api.platform.Server; -import org.sonar.server.l18n.I18nRule; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.EFFORT; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ISSUE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class MyNewIssuesEmailTemplateTest { - @Rule - public I18nRule i18n = new I18nRule() - .put("issue.type.BUG", "Bug") - .put("issue.type.CODE_SMELL", "Code Smell") - .put("issue.type.VULNERABILITY", "Vulnerability"); private MapSettings settings = new MapSettings(); private Server server = mock(Server.class); - private MyNewIssuesEmailTemplate underTest = new MyNewIssuesEmailTemplate(new EmailSettings(settings.asConfig(), server), i18n); + private MyNewIssuesEmailTemplate underTest = new MyNewIssuesEmailTemplate(new EmailSettings(settings.asConfig(), server)); @Before public void setUp() { @@ -74,27 +66,24 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()).startsWith( - "Project: Struts\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + - "\n" + - " Rules\n" + - " Rule the Universe (Clojure): 42\n" + - " Rule the World (Java): 5\n" + - "\n" + - " Tags\n" + - " oscar: 3\n" + - " cesar: 10\n" + - "\n" + - " Most impacted files\n" + - " /path/to/file: 3\n" + - " /path/to/directory: 7\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + + 32 new issues + + Rules + Rule the Universe (Clojure): 42 + Rule the World (Java): 5 + + Tags + oscar: 3 + cesar: 10 + + Most impacted files + /path/to/file: 3 + /path/to/directory: 7 + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"""); } @Test @@ -133,16 +122,13 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "Version: 52.0\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + Version: 52.0 + + 32 new issues + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"""); } @Test @@ -154,17 +140,14 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "Branch: feature1\n" + - "Version: 52.0\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + Branch: feature1 + Version: 52.0 + + 32 new issues + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"""); } @Test @@ -176,7 +159,7 @@ public class MyNewIssuesEmailTemplateTest { assertThat(message.getSubject()) .isEqualTo("You have 1 new issue on project Struts"); assertThat(message.getMessage()) - .contains("1 new issue (new debt: 1d3h)\n"); + .contains("1 new issue\n"); } @Test @@ -187,22 +170,19 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "Branch: feature1\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + Branch: feature1 + + 32 new issues + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"""); } @Test public void do_not_add_footer_when_properties_missing() { Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE) - .setFieldValue(RULE_TYPE + ".count", "32") + .setFieldValue(ISSUE + ".count", "32") .setFieldValue("projectName", "Struts"); EmailMessage message = underTest.format(notification); @@ -215,11 +195,7 @@ public class MyNewIssuesEmailTemplateTest { .setFieldValue("projectKey", "org.apache:struts") .setFieldValue("projectDate", "2010-05-18T14:50:45+0000") .setFieldValue("assignee", "lo.gin") - .setFieldValue(EFFORT + ".count", "1d3h") - .setFieldValue(RULE_TYPE + ".count", String.valueOf(count)) - .setFieldValue(RULE_TYPE + ".BUG.count", "1") - .setFieldValue(RULE_TYPE + ".VULNERABILITY.count", "3") - .setFieldValue(RULE_TYPE + ".CODE_SMELL.count", "0"); + .setFieldValue(ISSUE + ".count", String.valueOf(count)); } private void addTags(Notification notification) { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index 81fbf64b716..c1f4d6d0c00 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -23,35 +23,27 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.sonar.api.config.EmailSettings; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.notifications.Notification; import org.sonar.api.platform.Server; -import org.sonar.server.l18n.I18nRule; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ASSIGNEE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.EFFORT; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ISSUE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class NewIssuesEmailTemplateTest { - @Rule - public I18nRule i18n = new I18nRule() - .put("issue.type.BUG", "Bug") - .put("issue.type.CODE_SMELL", "Code Smell") - .put("issue.type.VULNERABILITY", "Vulnerability"); private MapSettings settings = new MapSettings(); private Server server = mock(Server.class); - private NewIssuesEmailTemplate template = new NewIssuesEmailTemplate(new EmailSettings(settings.asConfig(), server), i18n); + private NewIssuesEmailTemplate template = new NewIssuesEmailTemplate(new EmailSettings(settings.asConfig(), server)); @Before public void setUp() { @@ -80,7 +72,7 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); - assertThat(message.getSubject()).isEqualTo("Struts: 32 new issues (new debt: 1d3h)"); + assertThat(message.getSubject()).isEqualTo("Struts: 32 new issues"); } @Test @@ -90,7 +82,7 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); - assertThat(message.getSubject()).isEqualTo("Struts (feature1): 32 new issues (new debt: 1d3h)"); + assertThat(message.getSubject()).isEqualTo("Struts (feature1): 32 new issues"); } @Test @@ -105,32 +97,29 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "Version: 42.1.1\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + - "\n" + - " Assignees\n" + - " robin.williams: 5\n" + - " al.pacino: 7\n" + - "\n" + - " Rules\n" + - " Rule the Universe (Clojure): 42\n" + - " Rule the World (Java): 5\n" + - "\n" + - " Tags\n" + - " oscar: 3\n" + - " cesar: 10\n" + - "\n" + - " Most impacted files\n" + - " /path/to/file: 3\n" + - " /path/to/directory: 7\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + Version: 42.1.1 + + 32 new issues + + Assignees + robin.williams: 5 + al.pacino: 7 + + Rules + Rule the Universe (Clojure): 42 + Rule the World (Java): 5 + + Tags + oscar: 3 + cesar: 10 + + Most impacted files + /path/to/file: 3 + /path/to/directory: 7 + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-18"""); } @Test @@ -140,15 +129,12 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + + 32 new issues + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-18"""); } @Test @@ -158,9 +144,9 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); assertThat(message.getSubject()) - .isEqualTo("Struts: 1 new issue (new debt: 1d3h)"); + .isEqualTo("Struts: 1 new issue"); assertThat(message.getMessage()) - .contains("1 new issue (new debt: 1d3h)\n"); + .contains("1 new issue\n"); } @Test @@ -171,16 +157,13 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "Branch: feature1\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-1"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + Branch: feature1 + + 32 new issues + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-18"""); } @Test @@ -192,23 +175,20 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertThat(message.getMessage()) - .startsWith("Project: Struts\n" + - "Branch: feature1\n" + - "Version: 42.1.1\n" + - "\n" + - "32 new issues (new debt: 1d3h)\n" + - "\n" + - " Type\n" + - " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + - "\n" + - "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-1"); + assertThat(message.getMessage()).startsWith(""" + Project: Struts + Branch: feature1 + Version: 42.1.1 + + 32 new issues + + More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-18"""); } @Test public void do_not_add_footer_when_properties_missing() { Notification notification = new Notification(NewIssuesNotification.TYPE) - .setFieldValue(RULE_TYPE + ".count", "32") + .setFieldValue(ISSUE + ".count", "32") .setFieldValue("projectName", "Struts"); EmailMessage message = template.format(notification); @@ -221,11 +201,7 @@ public class NewIssuesEmailTemplateTest { .setFieldValue("projectName", "Struts") .setFieldValue("projectKey", "org.apache:struts") .setFieldValue("projectDate", "2010-05-18T14:50:45+0000") - .setFieldValue(EFFORT + ".count", "1d3h") - .setFieldValue(RULE_TYPE + ".count", String.valueOf(count)) - .setFieldValue(RULE_TYPE + ".BUG.count", "1") - .setFieldValue(RULE_TYPE + ".CODE_SMELL.count", "3") - .setFieldValue(RULE_TYPE + ".VULNERABILITY.count", "10"); + .setFieldValue(ISSUE + ".count", String.valueOf(count)); } private void addAssignees(Notification notification) { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java index 2dfa88bf164..3b2e3734c1e 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java @@ -21,7 +21,6 @@ package org.sonar.server.issue.notification; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -40,7 +39,6 @@ import org.sonar.server.issue.notification.NewIssuesStatistics.Metric; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; public class NewIssuesStatisticsTest { @@ -49,21 +47,11 @@ public class NewIssuesStatisticsTest { private NewIssuesStatistics underTest = new NewIssuesStatistics(Issue::isNew); @Test - public void add_fails_with_NPE_if_RuleType_is_null() { - String assignee = randomAlphanumeric(10); - DefaultIssue issue = new DefaultIssue().setType(null).setAssigneeUuid(assignee).setNew(new Random().nextBoolean()); - - assertThatThrownBy(() -> underTest.add(issue)) - .isInstanceOf(NullPointerException.class); - } - - @Test public void add_issues_with_correct_global_statistics() { DefaultIssue issue = new DefaultIssue() .setAssigneeUuid("maynard") .setComponentUuid("file-uuid") .setNew(true) - .setType(RuleType.BUG) .setRuleKey(RuleKey.of("SonarQube", "rule-the-world")) .setTags(Lists.newArrayList("bug", "owasp")) .setEffort(Duration.create(5L)); @@ -78,42 +66,44 @@ public class NewIssuesStatisticsTest { assertThat(countDistributionTotal(Metric.ASSIGNEE, "wrong.login")).isNull(); assertThat(countDistributionTotal(Metric.COMPONENT, "file-uuid")).isEqualTo(3); assertThat(countDistributionTotal(Metric.COMPONENT, "wrong-uuid")).isNull(); - assertThat(countDistributionTotal(Metric.RULE_TYPE, RuleType.BUG.name())).isEqualTo(3); - assertThat(countDistributionTotal(Metric.RULE_TYPE, RuleType.CODE_SMELL.name())).isNull(); assertThat(countDistributionTotal(Metric.TAG, "owasp")).isEqualTo(3); assertThat(countDistributionTotal(Metric.TAG, "wrong-tag")).isNull(); assertThat(countDistributionTotal(Metric.RULE, "SonarQube:rule-the-world")).isEqualTo(3); assertThat(countDistributionTotal(Metric.RULE, "SonarQube:has-a-fake-rule")).isNull(); - assertThat(underTest.globalStatistics().effort().getTotal()).isEqualTo(15L); + assertThat(underTest.globalStatistics().getIssueCount().getTotal()).isEqualTo(3); assertThat(underTest.globalStatistics().hasIssues()).isTrue(); assertThat(underTest.hasIssues()).isTrue(); assertThat(underTest.getAssigneesStatistics().get("maynard").hasIssues()).isTrue(); } @Test - public void add_counts_issue_per_RuleType_on_current_analysis_globally_and_per_assignee() { + public void add_counts_issues_on_current_analysis_globally_and_per_assignee() { String assignee = randomAlphanumeric(10); - Arrays.stream(RuleType.values()) - .map(ruleType -> new DefaultIssue().setType(ruleType).setAssigneeUuid(assignee).setNew(true)) + IntStream.range(0, 10) + .mapToObj(i -> new DefaultIssue().setAssigneeUuid(assignee).setNew(true)) .forEach(underTest::add); - DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE_TYPE); - DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE_TYPE); - Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 1, 1))); + MetricStatsInt globalIssueCount = underTest.globalStatistics().getIssueCount(); + MetricStatsInt assigneeIssueCount = underTest.getAssigneesStatistics().get(assignee).getIssueCount(); + assertThat(globalIssueCount.getOnCurrentAnalysis()).isEqualTo(10); + assertThat(globalIssueCount.getTotal()).isEqualTo(10); + assertThat(assigneeIssueCount.getOnCurrentAnalysis()).isEqualTo(10); + assertThat(assigneeIssueCount.getTotal()).isEqualTo(10); } @Test - public void add_counts_issue_per_RuleType_off_current_analysis_globally_and_per_assignee() { + public void add_counts_issues_off_current_analysis_globally_and_per_assignee() { String assignee = randomAlphanumeric(10); - Arrays.stream(RuleType.values()) - .map(ruleType -> new DefaultIssue().setType(ruleType).setAssigneeUuid(assignee).setNew(false)) + IntStream.range(0, 10) + .mapToObj(i -> new DefaultIssue().setAssigneeUuid(assignee).setNew(false)) .forEach(underTest::add); - DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE_TYPE); - DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE_TYPE); - Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 0, 1))); + MetricStatsInt globalIssueCount = underTest.globalStatistics().getIssueCount(); + MetricStatsInt assigneeIssueCount = underTest.getAssigneesStatistics().get(assignee).getIssueCount(); + assertThat(globalIssueCount.getOnCurrentAnalysis()).isZero(); + assertThat(globalIssueCount.getTotal()).isEqualTo(10); + assertThat(assigneeIssueCount.getOnCurrentAnalysis()).isZero(); + assertThat(assigneeIssueCount.getTotal()).isEqualTo(10); } @Test @@ -309,57 +299,6 @@ public class NewIssuesStatisticsTest { } @Test - public void add_sums_effort_on_current_analysis_globally_and_per_assignee() { - Random random = new Random(); - List<Integer> efforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10_000 * i).toList(); - int expected = efforts.stream().mapToInt(s -> s).sum(); - String assignee = randomAlphanumeric(10); - efforts.stream() - .map(effort -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setEffort(Duration.create(effort)).setAssigneeUuid(assignee).setNew(true)) - .forEach(underTest::add); - - MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); - MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); - Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> { - assertThat(distribution.getOnCurrentAnalysis()).isEqualTo(expected); - assertThat(distribution.getOffCurrentAnalysis()).isZero(); - assertThat(distribution.getTotal()).isEqualTo(expected); - }); - } - - @Test - public void add_sums_effort_off_current_analysis_globally_and_per_assignee() { - Random random = new Random(); - List<Integer> efforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10_000 * i).toList(); - int expected = efforts.stream().mapToInt(s -> s).sum(); - String assignee = randomAlphanumeric(10); - efforts.stream() - .map(effort -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setEffort(Duration.create(effort)).setAssigneeUuid(assignee).setNew(false)) - .forEach(underTest::add); - - MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); - MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); - Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> { - assertThat(distribution.getOnCurrentAnalysis()).isZero(); - assertThat(distribution.getOffCurrentAnalysis()).isEqualTo(expected); - assertThat(distribution.getTotal()).isEqualTo(expected); - }); - } - - @Test - public void add_does_not_sum_effort_if_null_neither_globally_nor_per_assignee() { - String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setEffort(null).setAssigneeUuid(assignee).setNew(new Random().nextBoolean())); - - MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); - MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); - Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> assertThat(distribution.getTotal()).isZero()); - } - - @Test public void do_not_have_issues_when_no_issue_added() { assertThat(underTest.globalStatistics().hasIssues()).isFalse(); } @@ -379,12 +318,10 @@ public class NewIssuesStatisticsTest { .setRuleKey(ruleKey) .setEffort(Duration.create(effort))); - assertThat(underTest.toString()) - .isEqualTo("NewIssuesStatistics{" + + assertThat(underTest) + .hasToString("NewIssuesStatistics{" + "assigneesStatistics={" + assignee + "=" + "Stats{distributions={" + - "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + - "statsPerLabel={" + randomRuleTypeExceptHotspot.name() + "=MetricStatsInt{on=1, off=0}}}, " + "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + "statsPerLabel={" + tag + "=MetricStatsInt{on=1, off=0}}}, " + "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + @@ -393,10 +330,8 @@ public class NewIssuesStatisticsTest { "statsPerLabel={" + assignee + "=MetricStatsInt{on=1, off=0}}}, " + "RULE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{on=1, off=0}}}}, " + - "effortStats=MetricStatsLong{on=" + effort + ", off=0}}}, " + + "issueCount=MetricStatsInt{on=1, off=0}}}, " + "globalStatistics=Stats{distributions={" + - "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + - "statsPerLabel={" + randomRuleTypeExceptHotspot.name() + "=MetricStatsInt{on=1, off=0}}}, " + "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + "statsPerLabel={" + tag + "=MetricStatsInt{on=1, off=0}}}, " + "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + @@ -405,7 +340,7 @@ public class NewIssuesStatisticsTest { "statsPerLabel={" + assignee + "=MetricStatsInt{on=1, off=0}}}, " + "RULE=DistributedMetricStatsInt{globalStats=MetricStatsInt{on=1, off=0}, " + "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{on=1, off=0}}}}, " + - "effortStats=MetricStatsLong{on=" + effort + ", off=0}}}"); + "issueCount=MetricStatsInt{on=1, off=0}}}"); } @CheckForNull |