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;
}
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;
}
}
@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);
}
}