This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch FREEMARKER-188
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git


The following commit(s) were added to refs/heads/FREEMARKER-188 by this push:
     new 66c2d8b  FREEMARKER-188 Fix broken FileUtilsTest
66c2d8b is described below

commit 66c2d8bf56b2e39ce0e9f4cc7a917a6c61e5457c
Author: Siegfried Goeschl <[email protected]>
AuthorDate: Wed Sep 8 19:00:06 2021 +0200

    FREEMARKER-188 Fix broken FileUtilsTest
---
 .../freemarker/generator/util/FileUtilsTest.java   | 43 ++++++++++++++--------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git 
a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/util/FileUtilsTest.java
 
b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/util/FileUtilsTest.java
index 8b3a509..19f01c7 100644
--- 
a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/util/FileUtilsTest.java
+++ 
b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/util/FileUtilsTest.java
@@ -1,47 +1,58 @@
 package org.apache.freemarker.generator.util;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.freemarker.generator.base.util.FileUtils;
+import org.apache.freemarker.generator.base.util.OperatingSystem;
 import org.junit.Test;
 
 import java.io.File;
 
+import static 
org.apache.freemarker.generator.base.util.FileUtils.getRelativePath;
 import static org.junit.Assert.assertEquals;
 
 public class FileUtilsTest {
 
     @Test
     public void shouldGetRelativePathForSameDirectory() {
-        assertEquals("", FileUtils.getRelativePath(new File("/"), new 
File("/pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new File("."), new 
File("pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new File("."), new 
File("./pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new File("."), new 
File("./pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new 
File("../freemarker-generator-base"), new File("pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new 
File("../freemarker-generator-base"), new File("./pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new 
File("../freemarker-generator-base"), new 
File("../freemarker-generator-base/pom.xml")));
+        assertEquals("", getRelativePath(new File("/"), new File("/pom.xml")));
+        assertEquals("", getRelativePath(new File("."), new File("pom.xml")));
+        assertEquals("", getRelativePath(new File("."), new 
File("./pom.xml")));
+        assertEquals("", getRelativePath(new File("."), new 
File("./pom.xml")));
+        assertEquals("", getRelativePath(new 
File("../freemarker-generator-base"), new File("pom.xml")));
+        assertEquals("", getRelativePath(new 
File("../freemarker-generator-base"), new File("./pom.xml")));
+        assertEquals("", getRelativePath(new 
File("../freemarker-generator-base"), new 
File("../freemarker-generator-base/pom.xml")));
     }
 
     @Test
     public void shouldGetRelativePathForNestedDirectory() {
-        assertEquals("src/test/data/env", FileUtils.getRelativePath(new 
File("."), new File("src/test/data/env/nginx.env")));
-        assertEquals("src/test/data/env", FileUtils.getRelativePath(new 
File("."), new File("./src/test/data/env/nginx.env")));
+        assertEquals(fixSeparators("src/test/data/env"), getRelativePath(new 
File("."), new File("src/test/data/env/nginx.env")));
+        assertEquals(fixSeparators("src/test/data/env"), getRelativePath(new 
File("."), new File("./src/test/data/env/nginx.env")));
     }
 
     @Test
     public void shouldGetRelativePathForDisjunctDirectories() {
-        assertEquals("../test/data/env", FileUtils.getRelativePath(new 
File("./src/site"), new File("src/test/data/env/nginx.env")));
+        assertEquals(fixSeparators("../test/data/env"), getRelativePath(new 
File("./src/site"), new File("src/test/data/env/nginx.env")));
     }
 
     @Test
     public void shouldHandleInvalidArgumentsGracefully() {
-        assertEquals("", FileUtils.getRelativePath(new File("."), new 
File(".")));
-        assertEquals("", FileUtils.getRelativePath(new File("pom.xml"), new 
File("pom.xml")));
-        assertEquals("", FileUtils.getRelativePath(new File("."), new 
File("does-not-exist.xml")));
-        assertEquals("foo", FileUtils.getRelativePath(new File("."), new 
File("foo/does-not-exist.xml")));
-        assertEquals("foo", FileUtils.getRelativePath(new File("."), new 
File("foo/./does-not-exist.xml")));
+        assertEquals("", getRelativePath(new File("."), new File(".")));
+        assertEquals("", getRelativePath(new File("pom.xml"), new 
File("pom.xml")));
+        assertEquals("", getRelativePath(new File("."), new 
File("does-not-exist.xml")));
+        assertEquals("foo", getRelativePath(new File("."), new 
File("foo/does-not-exist.xml")));
+        assertEquals("foo", getRelativePath(new File("."), new 
File("foo/./does-not-exist.xml")));
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void shouldThrowIllegalArgumentExceptionForNonExistingDirectoy() {
-        FileUtils.getRelativePath(new File("does-not-exit"), new 
File("pom.xml"));
+        getRelativePath(new File("does-not-exit"), new File("pom.xml"));
+    }
+
+    private static String fixSeparators(String str) {
+        if (OperatingSystem.isWindows()) {
+            return FilenameUtils.separatorsToWindows(str);
+        } else {
+            return str;
+        }
     }
 }

Reply via email to