More reliable tests (on windows)

This commit is contained in:
Joakim Erdfelt 2022-10-13 09:52:31 -05:00
parent 8a216c2bb4
commit 83823d8a68
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 21 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.List;
@ -55,6 +56,7 @@ import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
@ -142,16 +144,27 @@ public class FileSystemResourceTest
}
@Test
public void testNonAbsoluteURI() throws Exception
public void testNonAbsoluteURI(WorkDir workDir) throws Exception
{
// Doesn't exist.
Resource resource = ResourceFactory.root().newResource(new URI("path/to/resource"));
assertThat(resource, notNullValue());
assertThat(resource.getURI().toString(), startsWith("file:"));
assertThat(resource.getURI().toString(), endsWith("/path/to/resource"));
assertFalse(resource.exists());
resource = ResourceFactory.root().newResource(new URI("/path/to/resource"));
assertThat(resource, notNullValue());
assertThat(resource.getURI().toString(), is("file:///path/to/resource"));
// Create a directory
Path testdir = workDir.getEmptyPathDir().resolve("path/to/resource");
Files.createDirectories(testdir);
Path pwd = Paths.get(System.getProperty("user.dir"));
Path relativePath = pwd.relativize(testdir);
// Get a path relative name using unix/uri "/" (not windows "\")
String relativeName = FS.separators(relativePath.toString());
assertThat("Should not have path navigation entries", relativeName, not(containsString("..")));
resource = ResourceFactory.root().newResource(new URI(relativeName));
assertThat("Relative newResource: " + relativeName, resource, notNullValue());
assertThat(resource.getURI().toString(), startsWith("file:"));
assertThat(resource.getURI().toString(), endsWith("/path/to/resource/"));
}
@Test
@ -647,7 +660,7 @@ public class FileSystemResourceTest
assertThat("resource.uri.targetURI", ResourceFactory.root().newResource(resource.getURI()), hasNoTargetURI());
assertThat("resource.file.targetURI", ResourceFactory.root().newResource(resource.getPath()), hasNoTargetURI());
// On some case insensitive file systems, lets see if an alternate
// On some case-insensitive file systems, lets see if an alternate
// case for the filename results in an alias reference
Resource alias = base.resolve("FILE");
if (alias.exists())