Skip to content
Closed
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
88 changes: 0 additions & 88 deletions test/jdk/java/nio/file/Path/Misc.java

This file was deleted.

64 changes: 61 additions & 3 deletions test/jdk/java/nio/file/Path/PathOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@
*/

/* @test
* @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876 8262742
* 8298478
* @bug 4313887 6838333 6925932 7006126 7029979 8037945 8072495 8140449
* 8254876 8262742 8298478
* @summary Unit test for java.nio.file.Path path operations
* @library .. /test/lib
* @build jdk.test.lib.Platform
* @run main PathOps
*/

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;

import jdk.test.lib.Platform;

public class PathOps {

static final java.io.PrintStream out = System.out;
Expand Down Expand Up @@ -239,6 +245,34 @@ PathOps normalize(String expected) {
return this;
}

PathOps equals(String other) {
out.format("test equals %s\n", other);
checkPath();

Path that = Path.of(other);
check(that, path.toString());
check(path.hashCode() == that.hashCode(), true);

return this;
}

PathOps notEquals(Object other) {
out.format("test not equals %s\n", other);
checkPath();
check(path.equals(other), false);

return this;
}

PathOps toFile() {
out.println("check toFile");
checkPath();
File file = path.toFile();
check(file.toString(), path.toString());
check(file.toPath().equals(path), true);
return this;
}

PathOps string(String expected) {
out.println("check string representation");
checkPath();
Expand Down Expand Up @@ -1444,6 +1478,18 @@ static void doWindowsTests() {
.parent(null)
.name(null);

// equals
test("this")
.equals("this")
.notEquals(Path.of("that"))
.notEquals(null)
.notEquals(new Object())
.equals(Path.of("This"));

// toFile
test("C:\\foo\\bar\\gus")
.toFile();

// invalid
test(":\\foo")
.invalid();
Expand Down Expand Up @@ -2121,6 +2167,18 @@ static void doUnixTests() {
test("/foo/bar/gus/../..")
.normalize("/foo");

// equals
test("this")
.equals("this")
.notEquals(Path.of("that"))
.notEquals(null)
.notEquals(new Object())
.notEquals(Path.of("This"));

// toFile
test("/foo/bar/gus")
.toFile();

// invalid
test("foo\u0000bar")
.invalid();
Expand Down Expand Up @@ -2198,7 +2256,7 @@ public static void main(String[] args) {

// operating system specific
String osname = System.getProperty("os.name");
if (osname.startsWith("Windows")) {
if (Platform.isWindows()) {
doWindowsTests();
} else {
doUnixTests();
Expand Down