]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Fix test on Windows
authorSimonBrandhof <simon.brandhof@gmail.com>
Tue, 9 Apr 2013 13:11:30 +0000 (15:11 +0200)
committerSimonBrandhof <simon.brandhof@gmail.com>
Tue, 9 Apr 2013 13:11:30 +0000 (15:11 +0200)
sonar-runner-batch/src/test/java/org/sonar/runner/batch/FilePatternTest.java

index d1cea9e4be97f2e300cfd3a968a03afb33fffb40..d6e1aa60b942d3d5e2f186cdb896580e2a5d68ba 100644 (file)
  */
 package org.sonar.runner.batch;
 
+import org.apache.commons.io.FilenameUtils;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -30,12 +32,14 @@ import static org.fest.assertions.Assertions.assertThat;
 public class FilePatternTest {
 
   File basedir, rootFile, subFile;
+  String basePath;
 
   @Before
   public void init() throws Exception {
     rootFile = new File(getClass().getResource("/org/sonar/runner/batch/FilePatternTest/root.txt").toURI());
     subFile = new File(getClass().getResource("/org/sonar/runner/batch/FilePatternTest/subdir/subfile.txt").toURI());
     basedir = rootFile.getParentFile();
+    basePath = path(basedir);
   }
 
   @Test
@@ -56,12 +60,12 @@ public class FilePatternTest {
 
   @Test
   public void should_list_files_by_absolute_path() throws Exception {
-    assertOnly(new FilePattern().listFiles(basedir, basedir.getCanonicalPath() + "/*.txt"), rootFile);
-    assertOnly(new FilePattern().listFiles(basedir, basedir.getCanonicalPath() + "/**/subdir/*"), subFile);
-    assertOnly(new FilePattern().listFiles(basedir, rootFile.getCanonicalPath()), rootFile);
-    assertOnly(new FilePattern().listFiles(basedir, basedir.getCanonicalPath() + "/*/subfile.txt"), subFile);
-    assertThat(new FilePattern().listFiles(basedir, basedir.getCanonicalPath() + "/**/*.txt")).containsOnly(subFile, rootFile);
-    assertThat(new FilePattern().listFiles(basedir, basedir.getCanonicalPath() + "/ElseWhere/**/*.txt")).isEmpty();
+    assertOnly(new FilePattern().listFiles(basedir, basePath + "/*.txt"), rootFile);
+    assertOnly(new FilePattern().listFiles(basedir, basePath + "/**/subdir/*"), subFile);
+    assertOnly(new FilePattern().listFiles(basedir, path(rootFile)), rootFile);
+    assertOnly(new FilePattern().listFiles(basedir, path(basedir) + "/*/subfile.txt"), subFile);
+    assertThat(new FilePattern().listFiles(basedir, path(basedir) + "/**/*.txt")).containsOnly(subFile, rootFile);
+    assertThat(new FilePattern().listFiles(basedir, path(basedir) + "/ElseWhere/**/*.txt")).isEmpty();
     assertThat(new FilePattern().listFiles(basedir, "/ElseWhere/**/*.txt")).isEmpty();
   }
 
@@ -69,4 +73,8 @@ public class FilePatternTest {
     assertThat(files).hasSize(1);
     assertThat(files.iterator().next().getCanonicalPath()).isEqualTo(file.getCanonicalPath());
   }
+
+  private String path(File f) throws IOException {
+    return FilenameUtils.separatorsToUnix(f.getCanonicalPath());
+  }
 }