3 * Copyright (C) 2009-2021 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.api.batch.fs.internal.fs;
23 import java.io.IOException;
24 import java.nio.charset.StandardCharsets;
25 import org.apache.commons.io.IOUtils;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.TemporaryFolder;
29 import org.sonar.api.batch.fs.InputFile.Status;
30 import org.sonar.api.batch.fs.InputFile.Type;
31 import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
32 import org.sonar.api.batch.fs.internal.DefaultInputFile;
33 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
35 import static org.assertj.core.api.Assertions.assertThat;
37 public class TestInputFileBuilderTest {
40 public TemporaryFolder temp = new TemporaryFolder();
43 public void setContent() throws IOException {
44 DefaultInputFile file = TestInputFileBuilder.create("module", "invalidPath")
45 .setContents("my content")
46 .setCharset(StandardCharsets.UTF_8)
48 assertThat(file.contents()).isEqualTo("my content");
49 assertThat(IOUtils.toString(file.inputStream())).isEqualTo("my content");
53 public void testGetters() {
54 DefaultInputFile file = TestInputFileBuilder.create("module", new File("baseDir"), new File("baseDir", "path"))
55 .setStatus(Status.SAME)
59 assertThat(file.type()).isEqualTo(Type.MAIN);
60 assertThat(file.status()).isEqualTo(Status.SAME);
61 assertThat(file.isPublished()).isTrue();
62 assertThat(file.type()).isEqualTo(Type.MAIN);
63 assertThat(file.relativePath()).isEqualTo("path");
64 assertThat(file.absolutePath()).isEqualTo("baseDir/path");
69 public void testCreateInputModule() throws IOException {
70 File baseDir = temp.newFolder();
71 AbstractProjectOrModule module = TestInputFileBuilder.newDefaultInputModule("key", baseDir);
72 assertThat(module.key()).isEqualTo("key");
73 assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());