Fixing FileSystem reference techniques for OSX testing on Java 8
This commit is contained in:
parent
2de8eb936d
commit
c4eb2da79c
|
@ -72,6 +72,10 @@ public class PathResource extends Resource
|
|||
if (Files.exists(path))
|
||||
{
|
||||
Path real = abs.toRealPath(FOLLOW_LINKS);
|
||||
// We don't use (!Files.isSameFile(abs,real)) here as this
|
||||
// results in invalid alias detection on systems like OSX.
|
||||
// Where a real file "foo" can be referenced via Path "FOO",
|
||||
// this results in Files.isSameFile(Path("foo"), Path("FOO")) == true
|
||||
if (!abs.equals(real))
|
||||
return real;
|
||||
}
|
||||
|
|
|
@ -50,8 +50,12 @@ public class ScannerTest
|
|||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
_directory = MavenTestingUtils.getTargetTestingDir(ScannerTest.class.getSimpleName());
|
||||
FS.ensureEmpty(_directory);
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir(ScannerTest.class.getSimpleName());
|
||||
FS.ensureEmpty(testDir);
|
||||
|
||||
// Use full path, pointing to a real directory (for FileSystems that are case-insensitive, like Windows and OSX to use)
|
||||
// This is only needed for the various comparisons below to make sense.
|
||||
_directory = testDir.toPath().toRealPath().toFile();
|
||||
|
||||
_scanner = new Scanner();
|
||||
_scanner.addScanDir(_directory);
|
||||
|
|
|
@ -22,8 +22,8 @@ import static org.hamcrest.Matchers.*;
|
|||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -34,7 +34,6 @@ import java.net.URI;
|
|||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.DirectoryIteratorException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystemException;
|
||||
|
@ -188,13 +187,6 @@ public class FileSystemResourceTest
|
|||
};
|
||||
}
|
||||
|
||||
private URI createEmptyFile(String name) throws IOException
|
||||
{
|
||||
File file = testdir.getFile(name);
|
||||
file.createNewFile();
|
||||
return file.toURI();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNonAbsoluteURI() throws Exception
|
||||
{
|
||||
|
@ -229,11 +221,12 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testAddPath() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
File subdir = new File(dir,"sub");
|
||||
FS.ensureDirExists(subdir);
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
|
||||
Path subdir = dir.resolve("sub");
|
||||
FS.ensureDirExists(subdir.toFile());
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource sub = base.addPath("sub");
|
||||
assertThat("sub/.isDirectory",sub.isDirectory(),is(true));
|
||||
|
@ -246,14 +239,14 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testAddRootPath() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
File subdir = new File(dir,"sub");
|
||||
FS.ensureDirExists(subdir);
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Path subdir = dir.resolve("sub");
|
||||
Files.createDirectories(subdir);
|
||||
|
||||
String readableRootDir = findRootDir(dir.toPath().getFileSystem());
|
||||
String readableRootDir = findRootDir(dir.getFileSystem());
|
||||
assumeThat("Readable Root Dir found",readableRootDir,notNullValue());
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource sub = base.addPath("sub");
|
||||
assertThat("sub",sub.isDirectory(),is(true));
|
||||
|
@ -286,9 +279,12 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testIsContainedIn() throws Exception
|
||||
{
|
||||
createEmptyFile("foo");
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
Path foo = dir.resolve("foo");
|
||||
Files.createFile(foo);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo");
|
||||
assertThat("is contained in",res.isContainedIn(base),is(false));
|
||||
|
@ -298,13 +294,15 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testIsDirectory() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
createEmptyFile("foo");
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
Path foo = dir.resolve("foo");
|
||||
Files.createFile(foo);
|
||||
|
||||
File subdir = new File(dir,"sub");
|
||||
FS.ensureDirExists(subdir);
|
||||
Path subdir = dir.resolve("sub");
|
||||
Files.createDirectories(subdir);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo");
|
||||
assertThat("foo.isDirectory",res.isDirectory(),is(false));
|
||||
|
@ -317,12 +315,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testLastModified() throws Exception
|
||||
{
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
|
||||
long expected = file.lastModified();
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo");
|
||||
assertThat("foo.lastModified",res.lastModified()/1000*1000,is(expected));
|
||||
|
@ -332,7 +331,9 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testLastModified_NotExists() throws Exception
|
||||
{
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo");
|
||||
assertThat("foo.lastModified",res.lastModified(),is(0L));
|
||||
|
@ -342,17 +343,20 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testLength() throws Exception
|
||||
{
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path file = dir.resolve("foo");
|
||||
|
||||
try (StringReader reader = new StringReader("foo"); FileWriter writer = new FileWriter(file))
|
||||
try (StringReader reader = new StringReader("foo");
|
||||
BufferedWriter writer = Files.newBufferedWriter(file))
|
||||
{
|
||||
IO.copy(reader,writer);
|
||||
}
|
||||
|
||||
long expected = file.length();
|
||||
long expected = Files.size(file);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo");
|
||||
assertThat("foo.length",res.length(),is(expected));
|
||||
|
@ -362,7 +366,10 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testLength_NotExists() throws Exception
|
||||
{
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo");
|
||||
assertThat("foo.length",res.length(),is(0L));
|
||||
|
@ -372,10 +379,12 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testDelete() throws Exception
|
||||
{
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
Path file = dir.resolve("foo");
|
||||
Files.createFile(file);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// Is it there?
|
||||
Resource res = base.addPath("foo");
|
||||
|
@ -390,7 +399,10 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testDelete_NotExists() throws Exception
|
||||
{
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// Is it there?
|
||||
Resource res = base.addPath("foo");
|
||||
|
@ -405,9 +417,12 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testName() throws Exception
|
||||
{
|
||||
String expected = testdir.getDir().getAbsolutePath();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
String expected = dir.toAbsolutePath().toString();
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
assertThat("base.name",base.getName(),is(expected));
|
||||
}
|
||||
|
@ -416,17 +431,19 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testInputStream() throws Exception
|
||||
{
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path file = dir.resolve("foo");
|
||||
String content = "Foo is here";
|
||||
|
||||
try (StringReader reader = new StringReader(content); FileWriter writer = new FileWriter(file))
|
||||
try (StringReader reader = new StringReader(content);
|
||||
BufferedWriter writer = Files.newBufferedWriter(file))
|
||||
{
|
||||
IO.copy(reader,writer);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource foo = base.addPath("foo");
|
||||
try (InputStream stream = foo.getInputStream(); InputStreamReader reader = new InputStreamReader(stream); StringWriter writer = new StringWriter())
|
||||
|
@ -440,17 +457,19 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testReadableByteChannel() throws Exception
|
||||
{
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path file = dir.resolve("foo");
|
||||
String content = "Foo is here";
|
||||
|
||||
try (StringReader reader = new StringReader(content); FileWriter writer = new FileWriter(file))
|
||||
try (StringReader reader = new StringReader(content);
|
||||
BufferedWriter writer = Files.newBufferedWriter(file))
|
||||
{
|
||||
IO.copy(reader,writer);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource foo = base.addPath("foo");
|
||||
try (ReadableByteChannel channel = foo.getReadableByteChannel())
|
||||
|
@ -467,27 +486,34 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testGetURI() throws Exception
|
||||
{
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
URI expected = file.toURI();
|
||||
Path file = dir.resolve("foo");
|
||||
Files.createFile(file);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
URI expected = file.toUri();
|
||||
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource foo = base.addPath("foo");
|
||||
assertThat("getURI",foo.getURI(),is(expected));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testGetURL() throws Exception
|
||||
{
|
||||
File file = testdir.getFile("foo");
|
||||
file.createNewFile();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
URL expected = file.toURI().toURL();
|
||||
Path file = dir.resolve("foo");
|
||||
Files.createFile(file);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
URL expected = file.toUri().toURL();
|
||||
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource foo = base.addPath("foo");
|
||||
assertThat("getURL",foo.getURL(),is(expected));
|
||||
|
@ -497,11 +523,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testList() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
FS.touch(new File(dir, "foo"));
|
||||
FS.touch(new File(dir, "bar"));
|
||||
FS.ensureDirExists(new File(dir, "tick"));
|
||||
FS.ensureDirExists(new File(dir, "tock"));
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Files.createFile(dir.resolve("foo"));
|
||||
Files.createFile(dir.resolve("bar"));
|
||||
Files.createDirectories(dir.resolve("tick"));
|
||||
Files.createDirectories(dir.resolve("tock"));
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("foo");
|
||||
|
@ -509,7 +537,7 @@ public class FileSystemResourceTest
|
|||
expected.add("tick/");
|
||||
expected.add("tock/");
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
String list[] = base.list();
|
||||
List<String> actual = Arrays.asList(list);
|
||||
|
@ -522,10 +550,10 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testSymlink() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
|
||||
Path foo = new File(dir, "foo").toPath();
|
||||
Path bar = new File(dir, "bar").toPath();
|
||||
Path foo = dir.resolve("foo");
|
||||
Path bar = dir.resolve("bar");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -539,7 +567,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource resFoo = base.addPath("foo");
|
||||
Resource resBar = base.addPath("bar");
|
||||
|
@ -562,10 +590,11 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testNonExistantSymlink() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path foo = new File(dir, "foo").toPath();
|
||||
Path bar = new File(dir, "bar").toPath();
|
||||
Path foo = dir.resolve("foo");
|
||||
Path bar = dir.resolve("bar");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -578,7 +607,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// FileResource does not pass this test!
|
||||
assumeFalse(base instanceof FileResource);
|
||||
|
@ -600,16 +629,16 @@ public class FileSystemResourceTest
|
|||
assertThat("file.alias", newResource(resBar.getFile()), isAliasFor(resFoo));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCaseInsensitiveAlias() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path path = new File(dir, "file").toPath();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
Path path = dir.resolve("file");
|
||||
Files.createFile(path);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// Reference to actual resource that exists
|
||||
Resource resource = base.addPath("file");
|
||||
|
@ -641,11 +670,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testCase8dot3Alias() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path path = new File(dir, "TextFile.Long.txt").toPath();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("TextFile.Long.txt");
|
||||
Files.createFile(path);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// Long filename
|
||||
Resource resource = base.addPath("TextFile.Long.txt");
|
||||
|
@ -676,11 +707,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testNTFSFileStreamAlias() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path path = new File(dir, "testfile").toPath();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("testfile");
|
||||
Files.createFile(path);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource resource = base.addPath("testfile");
|
||||
|
||||
|
@ -717,11 +750,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testNTFSFileDataStreamAlias() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path path = new File(dir, "testfile").toPath();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("testfile");
|
||||
Files.createFile(path);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource resource = base.addPath("testfile");
|
||||
|
||||
|
@ -760,11 +795,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testNTFSFileEncodedDataStreamAlias() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path path = new File(dir, "testfile").toPath();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("testfile");
|
||||
Files.createFile(path);
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource resource = base.addPath("testfile");
|
||||
|
||||
|
@ -795,12 +832,12 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testSemicolon() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo;").toPath();
|
||||
Path foo = dir.resolve("foo;");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -810,22 +847,23 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo;");
|
||||
assertThat("Alias: " + res,res.getAlias(),nullValue());
|
||||
assertThat("Alias: " + res,res,hasNoAlias());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleQuote() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo' bar").toPath();
|
||||
Path foo = dir.resolve("foo' bar");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -835,7 +873,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo' bar");
|
||||
assertThat("Alias: " + res,res.getAlias(),nullValue());
|
||||
|
@ -845,12 +883,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testSingleBackTick() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo` bar").toPath();
|
||||
Path foo = dir.resolve("foo` bar");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -860,7 +899,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// FileResource does not pass this test!
|
||||
assumeFalse(base instanceof FileResource);
|
||||
|
@ -873,12 +912,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testBrackets() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo[1]").toPath();
|
||||
Path foo = dir.resolve("foo[1]");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -888,7 +928,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
Resource res = base.addPath("foo[1]");
|
||||
assertThat("Alias: " + res,res.getAlias(),nullValue());
|
||||
|
@ -898,12 +938,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testBraces() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo.{bar}.txt").toPath();
|
||||
Path foo = dir.resolve("foo.{bar}.txt");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -913,7 +954,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// FileResource does not pass this test!
|
||||
assumeFalse(base instanceof FileResource);
|
||||
|
@ -926,12 +967,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testCaret() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo^3.txt").toPath();
|
||||
Path foo = dir.resolve("foo^3.txt");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -941,7 +983,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// FileResource does not pass this test!
|
||||
assumeFalse(base instanceof FileResource);
|
||||
|
@ -954,12 +996,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testPipe() throws Exception
|
||||
{
|
||||
File dir = testdir.getDir();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to create file
|
||||
Path foo = new File(dir, "foo|bar.txt").toPath();
|
||||
Path foo = dir.resolve("foo|bar.txt");
|
||||
Files.createFile(foo);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -969,7 +1012,7 @@ public class FileSystemResourceTest
|
|||
assumeNoException(e);
|
||||
}
|
||||
|
||||
try (Resource base = newResource(testdir.getDir()))
|
||||
try (Resource base = newResource(dir.toFile()))
|
||||
{
|
||||
// FileResource does not pass this test!
|
||||
assumeFalse(base instanceof FileResource);
|
||||
|
@ -986,7 +1029,11 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testExist_Normal() throws Exception
|
||||
{
|
||||
createEmptyFile("a.jsp");
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("a.jsp");
|
||||
Files.createFile(path);
|
||||
|
||||
URI ref = testdir.getDir().toURI().resolve("a.jsp");
|
||||
try (Resource fileres = newResource(ref))
|
||||
|
@ -998,18 +1045,28 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testSingleQuoteInFileName() throws Exception
|
||||
{
|
||||
createEmptyFile("foo's.txt");
|
||||
createEmptyFile("f o's.txt");
|
||||
|
||||
URI refQuoted = testdir.getDir().toURI().resolve("foo's.txt");
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path fooA = dir.resolve("foo's.txt");
|
||||
Path fooB = dir.resolve("f o's.txt");
|
||||
|
||||
Files.createFile(fooA);
|
||||
Files.createFile(fooB);
|
||||
|
||||
URI refQuoted = dir.resolve("foo's.txt").toUri();
|
||||
|
||||
try (Resource fileres = newResource(refQuoted))
|
||||
{
|
||||
// FileResource on OSX does not pass this test!
|
||||
// on OSX "foo's.txt" with FileResource becomes "foo%27s.txt" incorrectly.
|
||||
assumeFalse( (fileres instanceof FileResource) && (OS.IS_OSX) );
|
||||
|
||||
assertThat("Exists: " + refQuoted,fileres.exists(),is(true));
|
||||
assertThat("Alias: " + refQuoted,fileres,hasNoAlias());
|
||||
}
|
||||
|
||||
URI refEncoded = testdir.getDir().toURI().resolve("foo%27s.txt");
|
||||
URI refEncoded = dir.toUri().resolve("foo%27s.txt");
|
||||
|
||||
try (Resource fileres = newResource(refEncoded))
|
||||
{
|
||||
|
@ -1017,7 +1074,7 @@ public class FileSystemResourceTest
|
|||
assertThat("Alias: " + refEncoded,fileres,hasNoAlias());
|
||||
}
|
||||
|
||||
URI refQuoteSpace = testdir.getDir().toURI().resolve("f%20o's.txt");
|
||||
URI refQuoteSpace = dir.toUri().resolve("f%20o's.txt");
|
||||
|
||||
try (Resource fileres = newResource(refQuoteSpace))
|
||||
{
|
||||
|
@ -1025,7 +1082,7 @@ public class FileSystemResourceTest
|
|||
assertThat("Alias: " + refQuoteSpace,fileres,hasNoAlias());
|
||||
}
|
||||
|
||||
URI refEncodedSpace = testdir.getDir().toURI().resolve("f%20o%27s.txt");
|
||||
URI refEncodedSpace = dir.toUri().resolve("f%20o%27s.txt");
|
||||
|
||||
try (Resource fileres = newResource(refEncodedSpace))
|
||||
{
|
||||
|
@ -1033,8 +1090,8 @@ public class FileSystemResourceTest
|
|||
assertThat("Alias: " + refEncodedSpace,fileres,hasNoAlias());
|
||||
}
|
||||
|
||||
URI refA = testdir.getDir().toURI().resolve("foo's.txt");
|
||||
URI refB = testdir.getDir().toURI().resolve("foo%27s.txt");
|
||||
URI refA = dir.toUri().resolve("foo's.txt");
|
||||
URI refB = dir.toUri().resolve("foo%27s.txt");
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("URI[a].equals(URI[b])").append(System.lineSeparator());
|
||||
|
@ -1054,7 +1111,11 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testExist_BadURINull() throws Exception
|
||||
{
|
||||
createEmptyFile("a.jsp");
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("a.jsp");
|
||||
Files.createFile(path);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -1076,7 +1137,11 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testExist_BadURINullX() throws Exception
|
||||
{
|
||||
createEmptyFile("a.jsp");
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path path = dir.resolve("a.jsp");
|
||||
Files.createFile(path);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -1098,8 +1163,13 @@ public class FileSystemResourceTest
|
|||
@Test
|
||||
public void testEncoding() throws Exception
|
||||
{
|
||||
File specials = testdir.getFile("a file with,spe#ials");
|
||||
try(Resource res= newResource(specials))
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Files.createDirectories(dir);
|
||||
|
||||
Path specials = dir.resolve("a file with,spe#ials");
|
||||
Files.createFile(specials);
|
||||
|
||||
try(Resource res = newResource(specials.toFile()))
|
||||
{
|
||||
assertThat("Specials URL", res.getURI().toASCIIString(), containsString("a%20file%20with,spe%23ials"));
|
||||
assertThat("Specials Filename", res.getFile().toString(), containsString("a file with,spe#ials"));
|
||||
|
@ -1108,20 +1178,25 @@ public class FileSystemResourceTest
|
|||
assertThat("File should have been deleted.",res.exists(),is(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUtf8Dir() throws Exception
|
||||
{
|
||||
File dir=new File(testdir.getDir(),"bãm");
|
||||
dir.mkdir();
|
||||
File file = new File(dir,"file.txt");
|
||||
file.createNewFile();
|
||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
||||
Path utf8Dir = dir.resolve("bãm");
|
||||
Files.createDirectories(utf8Dir);
|
||||
|
||||
Resource base = newResource(dir);
|
||||
assertNull(base.getAlias());
|
||||
Path file = utf8Dir.resolve("file.txt");
|
||||
Files.createFile(file);
|
||||
|
||||
Resource r = base.addPath("file.txt");
|
||||
assertNull(r.getAlias());
|
||||
try (Resource base = newResource(utf8Dir.toFile()))
|
||||
{
|
||||
assertThat("Exists: " + utf8Dir,base.exists(),is(true));
|
||||
assertThat("Alias: " + utf8Dir,base,hasNoAlias());
|
||||
|
||||
Resource r = base.addPath("file.txt");
|
||||
assertThat("Exists: " + r,r.exists(),is(true));
|
||||
assertThat("Alias: " + r,r,hasNoAlias());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue