Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/github/fge/filesystem/path/GenericPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,6 +121,19 @@ 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);

Assert.assertEquals(path.getName(0).toString(), "",
"First name element on empty path didn't equal an empty String");
}

/*
* This test this part of the Path's .relativize() method:
*
Expand Down Expand Up @@ -240,4 +254,4 @@ public void toUriPathReturnsCorrectURI(final String s, final String path,
assertThat(p.toUri().toString()).as("generated URI is correct")
.isEqualTo(expected);
}
}
}