--- /dev/null
+/*
+ * 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();
+ }
+
+}
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"));
}
}