-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #158
- Loading branch information
Showing
3 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/com/github/marschall/memoryfilesystem/PathTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.marschall.memoryfilesystem; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class PathTests { | ||
|
||
@RegisterExtension | ||
final FileSystemExtension extension = new FileSystemExtension(); | ||
|
||
@Test | ||
void subPath() throws IOException { | ||
try (FileSystem fileSystem = this.extension.getFileSystem()) { | ||
Path absolutePath = fileSystem.getPath("/parent/child.txt"); | ||
assertEquals(fileSystem.getPath("parent/child.txt"), absolutePath.subpath(0, 2)); | ||
assertEquals(fileSystem.getPath("parent"), absolutePath.subpath(0, 1)); | ||
assertEquals(fileSystem.getPath("child.txt"), absolutePath.subpath(1, 2)); | ||
|
||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> absolutePath.subpath(1, 1)); | ||
assertEquals("beginIndex must be smaller than 1 but was 1", e.getMessage()); | ||
|
||
e = assertThrows(IllegalArgumentException.class, () -> absolutePath.subpath(-1, 1)); | ||
assertEquals("beginIndex must not be negative but was -1", e.getMessage()); | ||
|
||
e = assertThrows(IllegalArgumentException.class, () -> absolutePath.subpath(0, 3)); | ||
assertEquals("endIndex must be smaller than or equal to 2 but was 3", e.getMessage()); | ||
|
||
e = assertThrows(IllegalArgumentException.class, () -> absolutePath.subpath(2, 1)); | ||
assertEquals("beginIndex must be smaller than 2 but was 2", e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} |