From: SimonBrandhof Date: Tue, 9 Apr 2013 13:11:30 +0000 (+0200) Subject: Fix test on Windows X-Git-Tag: 2.5-rc1~155 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cc1fcfa7ef85d9da399f77058faa9f6dc8d42760;p=sonar-scanner-cli.git Fix test on Windows --- diff --git a/sonar-runner-batch/src/test/java/org/sonar/runner/batch/FilePatternTest.java b/sonar-runner-batch/src/test/java/org/sonar/runner/batch/FilePatternTest.java index d1cea9e..d6e1aa6 100644 --- a/sonar-runner-batch/src/test/java/org/sonar/runner/batch/FilePatternTest.java +++ b/sonar-runner-batch/src/test/java/org/sonar/runner/batch/FilePatternTest.java @@ -19,10 +19,12 @@ */ 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()); + } }