]> source.dussan.org Git - sonarqube.git/commitdiff
Improve coverage
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 12 Jul 2017 14:19:05 +0000 (16:19 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Jul 2017 07:21:33 +0000 (09:21 +0200)
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java

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 (file)
index 0000000..34fe36b
--- /dev/null
@@ -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();
+  }
+
+}
index 332206cf45009e8f063aabee0f310d52e7697b66..6f12bf92ccbca1285014f318b5041655af7d879e 100644 (file)
@@ -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"));
   }
 }