]> source.dussan.org Git - sonarqube.git/commitdiff
Fix tests on Windows
authorJulien HENRY <henryju@yahoo.fr>
Mon, 12 Mar 2018 18:15:42 +0000 (19:15 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 13 Mar 2018 10:04:15 +0000 (11:04 +0100)
server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java

index e4d018741593496dc5ee783852df5110821be9a4..16fb18bbe74ab572be2362aba6725207327970f9 100644 (file)
@@ -210,18 +210,23 @@ public class EsSettingsTest {
 
   @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
index 93063842ce9b6a645f7a4798b743aca9817218d2..51e531e3686ec5c9dfe299cd51602e40f7ca86b8 100644 (file)
@@ -58,7 +58,7 @@ public class TestInputFileBuilderTest {
     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");
 
   }
 
index fdbadd774be6c13cb986ca0742eef964cc7f03d2..f6cff7aca4666e2b2434734870a27f0f60b4aa12 100644 (file)
@@ -19,6 +19,7 @@
  */
 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;
@@ -145,7 +146,7 @@ public class DefaultCpdTokensTest {
       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]]");
     }
index 2c3310fe3202b31e6bfe03716c262cfb4c6cf271..245702a02529ebb0ce46662f34e56bfd2ad6ac31 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.scanner;
 
+import java.io.File;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -95,13 +96,13 @@ public class DefaultFileLinesContextTest {
 
   @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);
   }
 
index e5d2d734b5d863ba988fef94404e14fbb5211b8d..045b89701d4153c0b41cba5e786c5928c5c596c4 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.api.utils.System2;
 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;
 
@@ -130,6 +131,7 @@ public class GlobalTempFolderProviderTest {
 
   @Test
   public void homeIsSymbolicLink() throws IOException {
+    assumeTrue(!System2.INSTANCE.isOsWindows());
     File realSonarHome = temp.newFolder();
     File symlink = temp.newFolder();
     symlink.delete();
index 3901a8e91377d1fcfcf0d4af1eebbd628565cc8b..919881ecd6eff3516d9a6cf5d58e0e0e624f101c 100644 (file)
@@ -46,6 +46,7 @@ import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assume.assumeTrue;
 
 public class FileSystemMediumTest {
 
@@ -311,7 +312,7 @@ 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();
@@ -343,7 +344,7 @@ public class FileSystemMediumTest {
         .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");
   }
@@ -614,35 +615,33 @@ public class FileSystemMediumTest {
   // 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
@@ -740,7 +739,8 @@ public class FileSystemMediumTest {
       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
index ff938ba808e3f283030511b9c5b39f5bfe3f5a10..eda36629c96a8d51cf4ab63c8287fe80218f84cc 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.scanner.report;
 
 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;
@@ -57,7 +56,9 @@ import org.sonar.scanner.scan.branch.BranchType;
 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
@@ -573,11 +574,11 @@ public class ComponentsPublisherTest {
 
     // 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");
@@ -585,26 +586,27 @@ public class ComponentsPublisherTest {
 
     // 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");
   }
 }
index 11541a7bb5eac1c5e9a9edd2b8e2dabdf323b71e..09f6740a9bb40e011d2e334cd4f3c252b7bf96ca 100644 (file)
@@ -45,7 +45,7 @@ public class DefaultBlameOutputTest {
     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")));
@@ -56,7 +56,7 @@ public class DefaultBlameOutputTest {
     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")));
@@ -67,7 +67,7 @@ public class DefaultBlameOutputTest {
     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")));