@Test
public void path_properties_are_values_from_EsFileSystem_argument() throws IOException {
+ File foo = temp.newFolder();
EsInstallation mockedEsInstallation = mock(EsInstallation.class);
- when(mockedEsInstallation.getHomeDirectory()).thenReturn(new File("/foo/home"));
- when(mockedEsInstallation.getConfDirectory()).thenReturn(new File("/foo/conf"));
- when(mockedEsInstallation.getLogDirectory()).thenReturn(new File("/foo/log"));
- when(mockedEsInstallation.getDataDirectory()).thenReturn(new File("/foo/data"));
+ File home = new File(foo, "home");
+ when(mockedEsInstallation.getHomeDirectory()).thenReturn(home);
+ File conf = new File(foo, "conf");
+ when(mockedEsInstallation.getConfDirectory()).thenReturn(conf);
+ File log = new File(foo, "log");
+ when(mockedEsInstallation.getLogDirectory()).thenReturn(log);
+ File data = new File(foo, "data");
+ when(mockedEsInstallation.getDataDirectory()).thenReturn(data);
EsSettings underTest = new EsSettings(minProps(new Random().nextBoolean()), mockedEsInstallation, System2.INSTANCE);
Map<String, String> generated = underTest.build();
- assertThat(generated.get("path.data")).isEqualTo("/foo/data");
- assertThat(generated.get("path.logs")).isEqualTo("/foo/log");
- assertThat(generated.get("path.conf")).isEqualTo("/foo/conf");
+ assertThat(generated.get("path.data")).isEqualTo(data.getPath());
+ assertThat(generated.get("path.logs")).isEqualTo(log.getPath());
+ assertThat(generated.get("path.conf")).isEqualTo(conf.getPath());
}
@Test
assertThat(file.isPublished()).isTrue();
assertThat(file.type()).isEqualTo(Type.MAIN);
assertThat(file.relativePath()).isEqualTo("path");
- assertThat(file.absolutePath()).isEqualTo(new File("baseDir", "path").toString());
+ assertThat(file.absolutePath()).isEqualTo("baseDir/path");
}
*/
package org.sonar.api.batch.sensor.cpd.internal;
+import java.io.File;
import org.junit.Test;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
fail("Expected exception");
} catch (Exception e) {
- assertThat(e).hasMessage("Tokens of file src/Foo.java should be provided in order.\n" +
+ assertThat(e).hasMessage("Tokens of file src" + File.separator + "Foo.java should be provided in order.\n" +
"Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]]\n" +
"Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]");
}
*/
package org.sonar.scanner;
+import java.io.File;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@Test
public void validateLineGreaterThanZero() {
- thrown.expectMessage("Line number should be positive for file src/foo.php.");
+ thrown.expectMessage("Line number should be positive for file src" + File.separator + "foo.php.");
fileLineMeasures.setIntValue(HITS_METRIC_KEY, 0, 2);
}
@Test
public void validateLineLowerThanLineCount() {
- thrown.expectMessage("Line 4 is out of range for file src/foo.php. File has 3 lines");
+ thrown.expectMessage("Line 4 is out of range for file src" + File.separator + "foo.php. File has 3 lines");
fileLineMeasures.setIntValue(HITS_METRIC_KEY, 4, 2);
}
import org.sonar.api.utils.TempFolder;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Test
public void homeIsSymbolicLink() throws IOException {
+ assumeTrue(!System2.INSTANCE.isOsWindows());
File realSonarHome = temp.newFolder();
File symlink = temp.newFolder();
symlink.delete();
import org.sonar.xoo.rule.XooRulesDefinition;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assume.assumeTrue;
public class FileSystemMediumTest {
.execute();
assertThat(logs.getAllAsString()).contains("1 file indexed");
- assertThat(logs.getAllAsString()).contains("'src/sample.unknown' indexed with language 'null'");
+ assertThat(logs.getAllAsString()).contains("'src" + File.separator + "sample.unknown' indexed with language 'null'");
assertThat(logs.getAllAsString()).contains("'src/sample.unknown' generated metadata");
DefaultInputFile inputFile = (DefaultInputFile) result.inputFile("src/sample.unknown");
assertThat(result.getReportComponent(inputFile.key())).isNotNull();
.build())
.execute();
- assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' indexed with language 'null'");
+ assertThat(logs.getAllAsString()).containsOnlyOnce("'src" + File.separator + "myfile.binary' indexed with language 'null'");
assertThat(logs.getAllAsString()).doesNotContain("'src/myfile.binary' generating issue exclusions");
assertThat(logs.getAllAsString()).containsOnlyOnce("'src/sample.xoo' generating issue exclusions");
}
// SONAR-5330
@Test
public void scanProjectWithSourceSymlink() {
- if (!System2.INSTANCE.isOsWindows()) {
- File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
- TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
- .execute();
+ assumeTrue(!System2.INSTANCE.isOsWindows());
+ File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .execute();
- assertThat(result.inputFiles()).hasSize(3);
- // check that symlink was not resolved to target
- assertThat(result.inputFiles()).extractingResultOf("path").toString().startsWith(projectDir.toString());
- }
+ assertThat(result.inputFiles()).hasSize(3);
+ // check that symlink was not resolved to target
+ assertThat(result.inputFiles()).extractingResultOf("path").toString().startsWith(projectDir.toString());
}
// SONAR-6719
@Test
public void scanProjectWithWrongCase() {
- if (System2.INSTANCE.isOsWindows()) {
- File projectDir = new File("src/test/resources/mediumtest/xoo/sample");
- TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
- .property("sonar.sources", "XOURCES")
- .property("sonar.tests", "TESTX")
- .execute();
+ assumeTrue(System2.INSTANCE.isOsWindows());
+ File projectDir = new File("src/test/resources/mediumtest/xoo/sample");
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.sources", "XOURCES")
+ .property("sonar.tests", "TESTX")
+ .execute();
- assertThat(result.inputFiles()).hasSize(3);
- assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly(
- "xources/hello/HelloJava.xoo",
- "xources/hello/helloscala.xoo",
- "testx/ClassOneTest.xoo");
- }
+ assertThat(result.inputFiles()).hasSize(3);
+ assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly(
+ "xources/hello/HelloJava.xoo",
+ "xources/hello/helloscala.xoo",
+ "testx/ClassOneTest.xoo");
}
@Test
assertThat(e)
.isInstanceOf(MessageException.class)
.hasMessage(
- "Language of file 'src/sample.xoo' can not be decided as the file matches patterns of both sonar.lang.patterns.xoo : **/*.xoo and sonar.lang.patterns.xoo2 : **/*.xoo");
+ "Language of file 'src" + File.separator
+ + "sample.xoo' can not be decided as the file matches patterns of both sonar.lang.patterns.xoo : **/*.xoo and sonar.lang.patterns.xoo2 : **/*.xoo");
}
// SONAR-9561
import java.io.File;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.*;
+import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.newDefaultInputDir;
+import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.newDefaultInputFile;
+import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.newDefaultInputModule;
public class ComponentsPublisherTest {
@Rule
// file in dir in root
assertThat(reader.readComponent(dir1_file.batchId()).getPath()).isEqualTo("dir1/Foo.java");
- assertThat(reader.readComponent(dir1_file.batchId()).getProjectRelativePath()).isEqualTo("dir1/Foo.java");
+ assertThat(reader.readComponent(dir1_file.batchId()).getProjectRelativePath()).isEqualTo("dir1" + File.separator + "Foo.java");
// dir in dir in root
assertThat(reader.readComponent(dir1_dir1.batchId()).getPath()).isEqualTo("dir1/dir1");
- assertThat(reader.readComponent(dir1_dir1.batchId()).getProjectRelativePath()).isEqualTo("dir1/dir1");
+ assertThat(reader.readComponent(dir1_dir1.batchId()).getProjectRelativePath()).isEqualTo("dir1" + File.separator + "dir1");
// module in root
assertThat(reader.readComponent(mod1.batchId()).getPath()).isEqualTo("mod1");
// dir in module in root
assertThat(reader.readComponent(mod1_dir2.batchId()).getPath()).isEqualTo("dir2");
- assertThat(reader.readComponent(mod1_dir2.batchId()).getProjectRelativePath()).isEqualTo("mod1/dir2");
+ assertThat(reader.readComponent(mod1_dir2.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "dir2");
// file in dir in module in root
assertThat(reader.readComponent(mod1_dir2_file.batchId()).getPath()).isEqualTo("dir2/Foo.java");
- assertThat(reader.readComponent(mod1_dir2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/dir2/Foo.java");
+ assertThat(reader.readComponent(mod1_dir2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "dir2" + File.separator + "Foo.java");
// module in module
assertThat(reader.readComponent(mod1_mod2.batchId()).getPath()).isEqualTo("mod2");
- assertThat(reader.readComponent(mod1_mod2.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2");
+ assertThat(reader.readComponent(mod1_mod2.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "mod2");
// file in module in module
assertThat(reader.readComponent(mod1_mod2_file.batchId()).getPath()).isEqualTo("Foo.java");
- assertThat(reader.readComponent(mod1_mod2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/Foo.java");
+ assertThat(reader.readComponent(mod1_mod2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "mod2" + File.separator + "Foo.java");
// dir in module in module
assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getPath()).isEqualTo("dir");
- assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir");
+ assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "mod2" + File.separator + "dir");
// file in dir in module in module
assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getPath()).isEqualTo("dir/Foo.java");
- assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir/Foo.java");
+ assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getProjectRelativePath())
+ .isEqualTo("mod1" + File.separator + "mod2" + File.separator + "dir" + File.separator + "Foo.java");
}
}
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").build();
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("It was not expected to blame file src/main/java/Foo.java");
+ thrown.expectMessage("It was not expected to blame file " + file);
new DefaultBlameOutput(null, Arrays.<InputFile>asList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()))
.blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Blame date is null for file src/main/java/Foo.java at line 1");
+ thrown.expectMessage("Blame date is null for file " + file + " at line 1");
new DefaultBlameOutput(null, Arrays.<InputFile>asList(file))
.blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Blame revision is blank for file src/main/java/Foo.java at line 1");
+ thrown.expectMessage("Blame revision is blank for file " + file + " at line 1");
new DefaultBlameOutput(null, Arrays.<InputFile>asList(file))
.blameResult(file, Arrays.asList(new BlameLine().date(new Date()).author("guy")));