diff options
-rw-r--r-- | sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java | 10 | ||||
-rw-r--r-- | sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java | 10 |
2 files changed, 15 insertions, 5 deletions
diff --git a/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java b/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java index a8ce8ed8c17..425b26af8be 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java +++ b/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java @@ -73,11 +73,15 @@ public class CheckMessage implements Message { @Override public String toString() { - return new ToStringBuilder(this).append("source", sourceCode).append("check", codeCheck).append("msg", defaultMessage).append("line", - line).toString(); + return new ToStringBuilder(this).append("source", sourceCode).append("check", codeCheck).append("msg", defaultMessage) + .append("line", line).toString(); } public String formatDefaultMessage() { - return MessageFormat.format(defaultMessage, messageArguments); + if (messageArguments.length == 0) { + return defaultMessage; + } else { + return MessageFormat.format(defaultMessage, messageArguments); + } } } diff --git a/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java b/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java index d2f59c2ef79..1f7e5734918 100644 --- a/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java +++ b/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java @@ -19,11 +19,11 @@ */ package org.sonar.squid.api; -import org.junit.Test; - import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import org.junit.Test; + public class CheckMessageTest { @Test @@ -32,4 +32,10 @@ public class CheckMessageTest { assertThat(message.formatDefaultMessage(), is("Value is 3, expected value is 7.")); } + @Test + public void testNotFormatMessageWithoutParameters() { + CheckMessage message = new CheckMessage(null, "public void main(){."); // This message can't be used as a pattern by the MessageFormat + // class + assertThat(message.formatDefaultMessage(), is("public void main(){.")); + } } |