3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.api.batch.sensor.issue.internal;
22 import org.apache.commons.lang.StringUtils;
23 import org.junit.Test;
24 import org.sonar.api.batch.fs.InputFile;
25 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.assertj.core.api.Assertions.assertThatThrownBy;
30 public class DefaultIssueLocationTest {
32 private InputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php")
33 .initMetadata("Foo\nBar\n")
37 public void should_build() {
38 assertThat(new DefaultIssueLocation()
40 .message("pipo bimbo")
42 ).isEqualTo("pipo bimbo");
46 public void not_allowed_to_call_on_twice() {
47 assertThatThrownBy(() -> new DefaultIssueLocation()
50 .message("Wrong way!"))
51 .isInstanceOf(IllegalStateException.class)
52 .hasMessage("on() already called");
56 public void prevent_too_long_messages() {
57 assertThat(new DefaultIssueLocation()
59 .message(StringUtils.repeat("a", 4000)).message()).hasSize(4000);
61 assertThat(new DefaultIssueLocation()
63 .message(StringUtils.repeat("a", 4001)).message()).hasSize(4000);
67 public void prevent_null_character_in_message_text() {
68 assertThatThrownBy(() -> new DefaultIssueLocation()
69 .message("pipo " + '\u0000' + " bimbo"))
70 .isInstanceOf(IllegalArgumentException.class)
71 .hasMessageContaining("Character \\u0000 is not supported in issue message");
75 public void prevent_null_character_in_message_text_when_builder_has_been_initialized() {
76 assertThatThrownBy(() -> new DefaultIssueLocation()
78 .message("pipo " + '\u0000' + " bimbo"))
79 .isInstanceOf(IllegalArgumentException.class)
80 .hasMessageStartingWith("Character \\u0000 is not supported in issue message")
81 .hasMessageEndingWith(", on component: src/Foo.php");