|
| 1 | +/* |
| 2 | + * SonarQube Scanner for Gradle |
| 3 | + * Copyright (C) 2015-2025 SonarSource |
| 4 | + * mailto:info AT sonarsource DOT com |
| 5 | + * |
| 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. |
| 10 | + * |
| 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. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public |
| 17 | + * License along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 |
| 19 | + */ |
| 20 | +package org.sonarqube.gradle; |
| 21 | + |
| 22 | +import java.io.File; |
| 23 | +import java.util.Collection; |
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Map; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; |
| 30 | + |
| 31 | +class SonarUtilsTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + void append_props_to_without_previous_value() { |
| 35 | + Map<String, Object> properties = new HashMap<>(); |
| 36 | + SonarUtils.appendProps(properties, "my-key", List.of("a", "b", "c", "d")); |
| 37 | + assertThat((Collection<Object>) properties.get("my-key")).containsExactly("a", "b", "c", "d"); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void append_props_to_a_previous_file_value() { |
| 42 | + Map<String, Object> properties = new HashMap<>(); |
| 43 | + properties.put("my-key", new File("a")); |
| 44 | + SonarUtils.appendProps(properties, "my-key", List.of("b", "c", "d")); |
| 45 | + assertThat((Collection<Object>) properties.get("my-key")).containsExactly(new File("a"), "b", "c", "d"); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void append_props_to_a_previous_collection_value() { |
| 50 | + Map<String, Object> properties = new HashMap<>(); |
| 51 | + properties.put("my-key", List.of("a", "b")); |
| 52 | + SonarUtils.appendProps(properties, "my-key", List.of("c", "d")); |
| 53 | + assertThat((Collection<Object>) properties.get("my-key")).containsExactly("a", "b", "c", "d"); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments