From cf1c8d76184de334921362e9abd7dd64d56e5f16 Mon Sep 17 00:00:00 2001 From: Michal Duda Date: Thu, 22 Nov 2018 18:09:44 +0100 Subject: SONAR-11507 WS /batch/project new file structure --- .../input/MultiModuleProjectRepositoryTest.java | 68 ++++++++++++++++++++++ .../input/SingleProjectRepositoryTest.java | 64 ++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepositoryTest.java create mode 100644 sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/SingleProjectRepositoryTest.java (limited to 'sonar-scanner-protocol/src/test') diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepositoryTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepositoryTest.java new file mode 100644 index 00000000000..61aea5c2ec7 --- /dev/null +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepositoryTest.java @@ -0,0 +1,68 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.scanner.protocol.input; + +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MultiModuleProjectRepositoryTest { + + private MultiModuleProjectRepository repository; + + @Before + public void setUp() { + repository = new MultiModuleProjectRepository(); + } + + @Test + public void add_file_data_to_nodule() { + FileData fileData1 = new FileData("123", "456"); + FileData fileData2 = new FileData("153", "6432"); + FileData fileData3 = new FileData("987", "6343"); + + repository.addFileDataToModule("Module1", "/Abc.java", fileData1); + repository.addFileDataToModule("Module1", "/Xyz.java", fileData2); + repository.addFileDataToModule("Module2", "/Def.java", fileData3); + + assertThat(repository.repositoriesByModule()).hasSize(2); + assertThat(repository.fileData("Module1", "/Xyz.java")).isEqualTo(fileData2); + assertThat(repository.fileData("Module2", "/Def.java")).isEqualTo(fileData3); + } + + @Test + public void add_file_does_not_add_the_file_without_path() { + FileData fileData = new FileData("123", "456"); + + repository.addFileDataToModule("module1", null, fileData); + + assertThat(repository.repositoriesByModule()).hasSize(0); + } + + @Test + public void add_file_does_not_add_the_file_without_revision_and_hash() { + FileData fileData = new FileData(null, null); + + repository.addFileDataToModule("module2", "/Abc.java", fileData); + + assertThat(repository.repositoriesByModule()).hasSize(0); + } +} diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/SingleProjectRepositoryTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/SingleProjectRepositoryTest.java new file mode 100644 index 00000000000..c16c0fc8799 --- /dev/null +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/input/SingleProjectRepositoryTest.java @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.scanner.protocol.input; + +import com.google.common.collect.Maps; +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SingleProjectRepositoryTest { + private SingleProjectRepository repository; + + @Before + public void setUp() { + repository = new SingleProjectRepository(); + } + + @Test + public void add_file_data() { + FileData fileData = new FileData("123", "456"); + + repository.addFileData("/Abc.java", fileData); + + assertThat(repository.fileData()).hasSize(1); + assertThat(repository.fileData()).contains(Maps.immutableEntry("/Abc.java", fileData)); + assertThat(repository.fileDataByPath("/Abc.java")).isEqualTo(fileData); + } + + @Test + public void add_file_data_doesnt_add_the_file_without_path() { + FileData fileData = new FileData("123", "456"); + + repository.addFileData(null, fileData); + + assertThat(repository.fileData()).hasSize(0); + } + + @Test + public void add_file_data_doesnt_add_the_file_without_revision_and_hash() { + FileData fileData = new FileData(null, null); + + repository.addFileData("/Abc.java", fileData); + + assertThat(repository.fileData()).hasSize(0); + } +} -- cgit v1.2.3