Paths { public static Path get(final String first, final String... more) throws IllegalArgumentException { checkNotNull("first", first); if (first.trim().length() == 0) { return FileSystems.getDefault().getPath(first); } URI uri = null; if (more == null || more.length == 0) { try { uri = new URI(first); } catch (URISyntaxException ex) { try { uri = URI.create(first); } catch (IllegalArgumentException e) { uri = null; } } } if (uri != null && uri.getScheme() != null) { return get(uri); } return FileSystems.getDefault().getPath(first, more); } private  Paths(); static Path get(final String first,
                           final String... more); static Path get(final URI uri);  }
@Test public void simpleGet() { final Path path = Paths.get("/path/to/file.txt"); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/file.txt"); }
@Test public void simplePartitionedGet() { final Path path = Paths.get("/path", "to", "file.txt"); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/file.txt"); assertThat(path).isEqualTo(Paths.get("/path/to/file.txt")); }
@Test public void simpleWindowsGet() { final Path path = Paths.get("c:\\path\\to\\file.txt"); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("c:\\path\\to\\file.txt"); }
@Test public void simplePartitionedWindowsGet() { final Path path = Paths.get("c:\\path", "to", "file.txt"); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("c:\\path" + "\\" + "to" + "\\" + "file.txt"); }
@Test public void simpleGetButUsingURIAsString() { final Path path = Paths.get("file: assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/file.txt"); assertThat(path).isEqualTo(Paths.get("/path/to/file.txt")); }
@Test public void simpleGetButUsingURIAsStringAndDefaultScheme() { final Path path = Paths.get("default: assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/file.txt"); assertThat(path).isEqualTo(Paths.get("/path/to/file.txt")); }
@Test public void simpleGetURI() { final Path path = Paths.get(URI.create("file: assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/file.txt"); assertThat(path).isEqualTo(Paths.get("/path/to/file.txt")); }
@Test public void simpleGetEmpty() { final Path path = Paths.get(""); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isFalse(); assertThat(path.toString()).isEqualTo(""); }
@Test(expected = IllegalArgumentException.class) public void simpleGetNull1() { Paths.get((String) null); }
@Test(expected = IllegalArgumentException.class) public void simpleGetNull2() { Paths.get((URI) null); }