]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 abbreviate issue descriptions
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 22 Apr 2013 07:13:50 +0000 (09:13 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 22 Apr 2013 07:13:50 +0000 (09:13 +0200)
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java

index 8e0103f08b6d735e8c22ab48b40a14d26d6476b9..6a7971cb59d2af67076461bcb47b64d7928658de 100644 (file)
@@ -23,6 +23,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.issue.Issue;
@@ -122,11 +123,7 @@ public class DefaultIssue implements Issue, Serializable {
   }
 
   public DefaultIssue setDescription(@Nullable String s) {
-    if (s != null) {
-      Preconditions.checkArgument(s.length() < Issue.DESCRIPTION_MAX_SIZE,
-        "Description must not be longer than " + Issue.DESCRIPTION_MAX_SIZE + " characters (got " + s.length() + ")");
-    }
-    this.description = s;
+    this.description = StringUtils.abbreviate(s, DESCRIPTION_MAX_SIZE);
     return this;
   }
 
index deb8837da883467e25aada136c0aef147a39898f..ea9683ca24c8053df1c1c3034ac0cabed34afd26 100644 (file)
@@ -71,12 +71,8 @@ public class DefaultIssueTest {
   }
 
   @Test
-  public void size_of_description_should_be_limited() {
-    try {
-      issue.setDescription(StringUtils.repeat("a", 5000));
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertThat(e).hasMessage("Description must not be longer than 4000 characters (got 5000)");
-    }
+  public void size_of_description_should_be_abbreviated_if_too_long() {
+    issue.setDescription(StringUtils.repeat("a", 5000));
+    assertThat(issue.description()).hasSize(4000);
   }
 }