From 7a9467d8b887764b4bb76be1ba53cabc6f8bbefa Mon Sep 17 00:00:00 2001 From: Elijah Zupancic Date: Mon, 16 Nov 2015 16:48:51 -0800 Subject: [PATCH 1/2] Fixes #8. --- .../github/fge/filesystem/path/GenericPath.java | 4 ++++ .../fge/filesystem/path/GenericPathTest.java | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/fge/filesystem/path/GenericPath.java b/src/main/java/com/github/fge/filesystem/path/GenericPath.java index ff7fb60..06815da 100644 --- a/src/main/java/com/github/fge/filesystem/path/GenericPath.java +++ b/src/main/java/com/github/fge/filesystem/path/GenericPath.java @@ -129,6 +129,10 @@ public int getNameCount() @Override public Path getName(final int index) { + if (elements.root != null && elements.root.isEmpty() && elements.names.length == 0) { + return new GenericPath(fs, factory, PathElements.EMPTY); + } + final String name; //noinspection ProhibitedExceptionCaught diff --git a/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java b/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java index 7e1519d..d488bcd 100644 --- a/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java +++ b/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java @@ -120,6 +120,18 @@ public void getFileNameWithNameElementsDoesNotReturnNull() assertPath(path.getFileName()).isNotNull(); } + /* The typical behavior of a Unix path is to return a path with an + * empty root and no names when element 0 is requested from a path + * with an empty root and no names. + */ + @Test + public void getEmptyFileNameReturnsEmptyFirstName() { + final PathElements elements = new PathElements("", new String[] {}); + final Path path = new GenericPath(fs, factory, elements); + + path.getName(0).toString().equals(""); + } + /* * This test this part of the Path's .relativize() method: * @@ -240,4 +252,4 @@ public void toUriPathReturnsCorrectURI(final String s, final String path, assertThat(p.toUri().toString()).as("generated URI is correct") .isEqualTo(expected); } -} \ No newline at end of file +} From acd697382af732596db6b1d96c988a4b45181845 Mon Sep 17 00:00:00 2001 From: Elijah Zupancic Date: Tue, 17 Nov 2015 09:32:31 -0800 Subject: [PATCH 2/2] Added missing assert. --- .../java/com/github/fge/filesystem/path/GenericPathTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java b/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java index d488bcd..44e6e29 100644 --- a/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java +++ b/src/test/java/com/github/fge/filesystem/path/GenericPathTest.java @@ -23,6 +23,7 @@ import com.github.fge.filesystem.driver.FileSystemDriver; import com.github.fge.filesystem.fs.GenericFileSystem; import com.github.fge.filesystem.provider.FileSystemRepository; +import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -129,7 +130,8 @@ public void getEmptyFileNameReturnsEmptyFirstName() { final PathElements elements = new PathElements("", new String[] {}); final Path path = new GenericPath(fs, factory, elements); - path.getName(0).toString().equals(""); + Assert.assertEquals(path.getName(0).toString(), "", + "First name element on empty path didn't equal an empty String"); } /*