Add unit tests

This commit is contained in:
Reinhard Pointner 2017-02-27 13:46:27 +08:00
parent d6a8dfc00e
commit e902d999cd
2 changed files with 13 additions and 2 deletions

View File

@ -629,10 +629,11 @@ public final class FileUtilities {
}
public static String normalizePathSeparators(String path) {
// special handling for UNC paths
// special handling for UNC paths (e.g. \\server\share\path)
if (path.startsWith(UNC_PREFIX)) {
return UNC_PREFIX + replacePathSeparators(path.substring(UNC_PREFIX.length()), "/");
return UNC_PREFIX + normalizePathSeparators(path.substring(UNC_PREFIX.length()));
}
return replacePathSeparators(path, "/");
}

View File

@ -48,4 +48,14 @@ public class FileUtilitiesTest {
assertFalse(FileUtilities.isDerived(new File("10.z"), new File("1.mp4")));
}
@Test
public void normalizePathSeparators() {
assertEquals("C:/file.txt", FileUtilities.normalizePathSeparators("C:\\file.txt"));
assertEquals("/Volume/USB/file.txt", FileUtilities.normalizePathSeparators("/Volume\\USB/file.txt"));
assertEquals("\\\\server/share/data/file.txt", FileUtilities.normalizePathSeparators("\\\\server\\share\\data\\file.txt"));
assertEquals("\\\\server/share/data/file.txt", FileUtilities.normalizePathSeparators("\\\\server\\share\\data\\file.txt"));
assertEquals("/server/share/data/file.txt", FileUtilities.normalizePathSeparators("//server/share/data/file.txt"));
}
}