Skip to content

Commit

Permalink
Additional tests for Path.isAbsolute()
Browse files Browse the repository at this point in the history
  • Loading branch information
fhueske committed Apr 7, 2015
1 parent 2f683af commit 23fe006
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
5 changes: 1 addition & 4 deletions flink-core/src/main/java/org/apache/flink/core/fs/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ public FileSystem getFileSystem() throws IOException {
*/
public boolean isAbsolute() {
final int start = hasWindowsDrive(uri.getPath(), true) ? 3 : 0;
if (uri.getPath().length() > start) {
return uri.getPath().startsWith(SEPARATOR, start);
}
return true;
return uri.getPath().startsWith(SEPARATOR, start);
}

/**
Expand Down
35 changes: 31 additions & 4 deletions flink-core/src/test/java/org/apache/flink/core/fs/PathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public void testPathFromString() {
p = new Path("file:/C:/my/windows/path");
assertEquals("/C:/my/windows/path", p.toUri().getPath());

p = new Path("C:");
assertEquals("/C:", p.toUri().getPath());

try {
new Path((String)null);
fail();
Expand All @@ -98,21 +95,51 @@ public void testPathFromString() {
@Test
public void testIsAbsolute() {

// UNIX

Path p = new Path("/my/abs/path");
assertTrue(p.isAbsolute());

p = new Path("/");
assertTrue(p.isAbsolute());

p = new Path("./my/rel/path");
assertFalse(p.isAbsolute());

p = new Path("my/rel/path");
assertFalse(p.isAbsolute());

// WINDOWS

p = new Path("C:/my/abs/windows/path");
assertTrue(p.isAbsolute());

p = new Path("file:/C:");
p = new Path("y:/my/abs/windows/path");
assertTrue(p.isAbsolute());

p = new Path("b:\\my\\abs\\windows\\path");
assertTrue(p.isAbsolute());

p = new Path("C:");
assertFalse(p.isAbsolute());

p = new Path("C:my\\relative\\path");
assertFalse(p.isAbsolute());

p = new Path("\\my\\dir");
assertTrue(p.isAbsolute());

p = new Path("\\");
assertTrue(p.isAbsolute());

p = new Path(".\\my\\relative\\path");
assertFalse(p.isAbsolute());

p = new Path("my\\relative\\path");
assertFalse(p.isAbsolute());

p = new Path("\\\\myServer\\myDir");
assertTrue(p.isAbsolute());
}

@Test
Expand Down

0 comments on commit 23fe006

Please sign in to comment.