3 * Copyright (C) 2009-2024 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.scanner.repository.language;
22 import org.junit.Test;
23 import org.sonar.api.resources.Language;
24 import org.sonar.api.resources.Languages;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.assertj.core.api.Assertions.tuple;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
31 public class DefaultLanguagesRepositoryTest {
32 private final Languages languages = mock(Languages.class);
33 private final DefaultLanguagesRepository underTest = new DefaultLanguagesRepository(languages);
36 public void returns_all_languages() {
37 when(languages.all()).thenReturn(new Language[] {new TestLanguage("k1", true), new TestLanguage("k2", false)});
38 assertThat(underTest.all())
39 .extracting("key", "name", "fileSuffixes", "publishAllFiles")
41 tuple("k1", "name k1", new String[] {"k1"}, true),
42 tuple("k2", "name k2", new String[] {"k2"}, false)
47 public void publishAllFiles_by_default() {
48 when(languages.all()).thenReturn(new Language[] {new TestLanguage2("k1"), new TestLanguage2("k2")});
49 assertThat(underTest.all())
50 .extracting("key", "name", "fileSuffixes", "publishAllFiles")
52 tuple("k1", "name k1", new String[] {"k1"}, true),
53 tuple("k2", "name k2", new String[] {"k2"}, true)
58 public void get_find_language_by_key() {
59 when(languages.get("k1")).thenReturn(new TestLanguage2("k1"));
60 assertThat(underTest.get("k1"))
61 .extracting("key", "name", "fileSuffixes", "publishAllFiles")
62 .containsOnly("k1", "name k1", new String[] {"k1"}, true);
65 private static class TestLanguage implements Language {
66 private final String key;
67 private final boolean publishAllFiles;
69 public TestLanguage(String key, boolean publishAllFiles) {
71 this.publishAllFiles = publishAllFiles;
75 public String getKey() {
80 public String getName() {
85 public String[] getFileSuffixes() {
86 return new String[] {key};
90 public boolean publishAllFiles() {
91 return publishAllFiles;
95 private static class TestLanguage2 implements Language {
96 private final String key;
98 public TestLanguage2(String key) {
103 public String getKey() {
108 public String getName() {
109 return "name " + key;
113 public String[] getFileSuffixes() {
114 return new String[] {key};