예제 #1
0
  @Test
  public void cleanPathNoExceptionTest() throws InvalidPathException {
    // test clean path
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo/bar"));

    // test trailing slash
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo/bar/"));

    // test redundant slashes
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo//bar"));
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo//bar//"));
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo///////bar//////"));

    // test dots gets resolved
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo/./bar"));
    Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/foo/././bar"));
    Assert.assertEquals("/foo", PathUtils.cleanPath("/foo/bar/.."));
    Assert.assertEquals("/bar", PathUtils.cleanPath("/foo/../bar"));
    Assert.assertEquals("/", PathUtils.cleanPath("/foo/bar/../.."));

    // the following seems strange
    // TODO(jiri): Instead of returning null, throw InvalidPathException.
    Assert.assertNull(PathUtils.cleanPath("/foo/bar/../../.."));
  }
예제 #2
0
 @Test
 public void cleanPathExceptionTest() throws InvalidPathException {
   mException.expect(InvalidPathException.class);
   Assert.assertEquals("/foo/bar", PathUtils.cleanPath("/\\   foo / bar"));
 }