From: Duarte Meneses Date: Wed, 12 Jul 2017 14:19:05 +0000 (+0200) Subject: Improve coverage X-Git-Tag: 6.5-RC1~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76ea4fe342319874dc4809342911fdec3ee46c16;p=sonarqube.git Improve coverage --- diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java new file mode 100644 index 00000000000..34fe36b38a0 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.api.batch.fs.internal; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.util.Collections; + +import org.junit.Test; +import org.sonar.api.batch.bootstrap.ProjectDefinition; + +public class DefaultInputModuleTest { + + @Test + public void testGetters() { + ProjectDefinition def = ProjectDefinition.create(); + def.setKey("projectKey"); + def.setName("projectName"); + def.setBaseDir(new File("baseDir")); + def.setVersion("version"); + def.setDescription("desc"); + def.setWorkDir(new File("workDir")); + def.setSources("file1"); + def.setTests("test1"); + DefaultInputModule module = new DefaultInputModule(def); + + assertThat(module.key()).isEqualTo("projectKey"); + assertThat(module.getName()).isEqualTo("projectName"); + assertThat(module.getOriginalName()).isEqualTo("projectName"); + assertThat(module.definition()).isEqualTo(def); + assertThat(module.getBranch()).isNull(); + assertThat(module.getBaseDir()).isEqualTo(new File("baseDir")); + assertThat(module.getKeyWithBranch()).isEqualTo("projectKey"); + assertThat(module.getVersion()).isEqualTo("version"); + assertThat(module.getOriginalVersion()).isEqualTo("version"); + assertThat(module.getDescription()).isEqualTo("desc"); + assertThat(module.getWorkDir()).isEqualTo(new File("workDir")); + assertThat(module.sources()).isEqualTo(Collections.singletonList("file1")); + assertThat(module.tests()).isEqualTo(Collections.singletonList("test1")); + + assertThat(module.properties()).hasSize(6); + + assertThat(module.isFile()).isFalse(); + } + +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java index 332206cf450..6f12bf92ccb 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java @@ -21,21 +21,47 @@ package org.sonar.api.batch.fs.internal; import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.junit.Test; +import org.sonar.api.batch.fs.InputFile.Status; +import org.sonar.api.batch.fs.InputFile.Type; public class TestInputFileBuilderTest { @Test public void setContent() throws IOException { - DefaultInputFile builder = TestInputFileBuilder.create("module", "invalidPath") + DefaultInputFile file = TestInputFileBuilder.create("module", "invalidPath") .setContents("my content") .setCharset(StandardCharsets.UTF_8) .build(); - assertThat(builder.contents()).isEqualTo("my content"); - assertThat(IOUtils.toString(builder.inputStream())).isEqualTo("my content"); + assertThat(file.contents()).isEqualTo("my content"); + assertThat(IOUtils.toString(file.inputStream())).isEqualTo("my content"); + } + + @Test + public void testGetters() { + DefaultInputFile file = TestInputFileBuilder.create("module", new File("baseDir"), new File("baseDir", "path")) + .setStatus(Status.SAME) + .setType(Type.MAIN) + .build(); + + assertThat(file.type()).isEqualTo(Type.MAIN); + assertThat(file.status()).isEqualTo(Status.SAME); + assertThat(file.publish()).isTrue(); + assertThat(file.type()).isEqualTo(Type.MAIN); + assertThat(file.relativePath()).isEqualTo("path"); + assertThat(file.absolutePath()).isEqualTo(new File("baseDir", "path").toString()); + + } + + @Test + public void testCreateInputModule() { + DefaultInputModule module = TestInputFileBuilder.newDefaultInputModule("key", new File("baseDir")); + assertThat(module.key()).isEqualTo("key"); + assertThat(module.getBaseDir()).isEqualTo(new File("baseDir")); } }