diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-12-04 09:17:19 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-12-07 17:58:32 +0100 |
commit | 269338c846f8c521a3c9767a77d1bdc6f2502272 (patch) | |
tree | 29b5139bc03b47cf9e90a5245f50a8d05c2b82c2 /sonar-core/src/test | |
parent | f55222d86df4f24636ee3d1ae6d7877a9e952bc6 (diff) | |
download | sonarqube-269338c846f8c521a3c9767a77d1bdc6f2502272.tar.gz sonarqube-269338c846f8c521a3c9767a77d1bdc6f2502272.zip |
SONAR-7098 Always feed issues authors
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java index 86f103885c0..021513342fd 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java @@ -21,7 +21,9 @@ package org.sonar.core.issue; import java.util.Date; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.sonar.api.issue.ActionPlan; import org.sonar.api.user.User; import org.sonar.api.utils.Duration; @@ -38,6 +40,9 @@ import static org.sonar.core.issue.IssueUpdater.UNUSED; public class IssueUpdaterTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + DefaultIssue issue = new DefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik"); @@ -99,6 +104,34 @@ public class IssueUpdaterTest { } @Test + public void set_new_assignee() throws Exception { + boolean updated = updater.setNewAssignee(issue, "simon", context); + assertThat(updated).isTrue(); + assertThat(issue.assignee()).isEqualTo("simon"); + assertThat(issue.mustSendNotifications()).isTrue(); + FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); + assertThat(diff.oldValue()).isEqualTo(UNUSED); + assertThat(diff.newValue()).isEqualTo("simon"); + } + + @Test + public void not_set_new_assignee_if_new_assignee_is_null() throws Exception { + boolean updated = updater.setNewAssignee(issue, null, context); + assertThat(updated).isFalse(); + assertThat(issue.currentChange()).isNull(); + assertThat(issue.mustSendNotifications()).isFalse(); + } + + @Test + public void fail_with_ISE_when_setting_new_assignee_on_already_assigned_issue() throws Exception { + issue.setAssignee("simon"); + + thrown.expect(IllegalStateException.class); + thrown.expectMessage("It's not possible to update the assignee with this method, please use assign()"); + updater.setNewAssignee(issue, "julien", context); + } + + @Test public void set_severity() { boolean updated = updater.setSeverity(issue, "BLOCKER", context); assertThat(updated).isTrue(); @@ -480,6 +513,34 @@ public class IssueUpdaterTest { } @Test + public void set_new_author() throws Exception { + boolean updated = updater.setNewAuthor(issue, "simon", context); + assertThat(updated).isTrue(); + + FieldDiffs.Diff diff = issue.currentChange().get("author"); + assertThat(diff.oldValue()).isNull(); + assertThat(diff.newValue()).isEqualTo("simon"); + assertThat(issue.mustSendNotifications()).isFalse(); + } + + @Test + public void not_set_new_author_if_new_author_is_null() throws Exception { + boolean updated = updater.setNewAuthor(issue, null, context); + assertThat(updated).isFalse(); + assertThat(issue.currentChange()).isNull(); + assertThat(issue.mustSendNotifications()).isFalse(); + } + + @Test + public void fail_with_ISE_when_setting_new_author_on_issue() throws Exception { + issue.setAuthorLogin("simon"); + + thrown.expect(IllegalStateException.class); + thrown.expectMessage("It's not possible to update the author with this method, please use setAuthorLogin()"); + updater.setNewAuthor(issue, "julien", context); + } + + @Test public void set_project() { boolean updated = updater.setProject(issue, "sample", context); assertThat(updated).isTrue(); |