Skip to content

Commit 92b237c

Browse files
committed
8315485: (fs) Move java/nio/file/Path/Misc.java tests into java/nio/file/Path/PathOps.java
Reviewed-by: lucy Backport-of: 8dfde28b289cbb53173f0ab759156088bbaf74f1
1 parent 618a7ba commit 92b237c

File tree

2 files changed

+61
-90
lines changed

2 files changed

+61
-90
lines changed

test/jdk/java/nio/file/Path/Misc.java

-88
This file was deleted.

test/jdk/java/nio/file/Path/PathOps.java

+61-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@
2222
*/
2323

2424
/* @test
25-
* @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 8254876 8298478
25+
* @bug 4313887 6838333 6925932 7006126 7029979 8037945 8072495 8140449
26+
* 8254876 8298478
2627
* @summary Unit test for java.nio.file.Path path operations
28+
* @library .. /test/lib
29+
* @build jdk.test.lib.Platform
30+
* @run main PathOps
2731
*/
2832

33+
import java.io.File;
2934
import java.nio.file.FileSystems;
3035
import java.nio.file.InvalidPathException;
3136
import java.nio.file.Path;
3237
import java.nio.file.Paths;
3338

39+
import jdk.test.lib.Platform;
40+
3441
public class PathOps {
3542

3643
static final java.io.PrintStream out = System.out;
@@ -217,6 +224,34 @@ PathOps normalize(String expected) {
217224
return this;
218225
}
219226

227+
PathOps equals(String other) {
228+
out.format("test equals %s\n", other);
229+
checkPath();
230+
231+
Path that = Path.of(other);
232+
check(that, path.toString());
233+
check(path.hashCode() == that.hashCode(), true);
234+
235+
return this;
236+
}
237+
238+
PathOps notEquals(Object other) {
239+
out.format("test not equals %s\n", other);
240+
checkPath();
241+
check(path.equals(other), false);
242+
243+
return this;
244+
}
245+
246+
PathOps toFile() {
247+
out.println("check toFile");
248+
checkPath();
249+
File file = path.toFile();
250+
check(file.toString(), path.toString());
251+
check(file.toPath().equals(path), true);
252+
return this;
253+
}
254+
220255
PathOps string(String expected) {
221256
out.println("check string representation");
222257
checkPath();
@@ -1393,6 +1428,18 @@ static void doWindowsTests() {
13931428
.parent(null)
13941429
.name(null);
13951430

1431+
// equals
1432+
test("this")
1433+
.equals("this")
1434+
.notEquals(Path.of("that"))
1435+
.notEquals(null)
1436+
.notEquals(new Object())
1437+
.equals(Path.of("This"));
1438+
1439+
// toFile
1440+
test("C:\\foo\\bar\\gus")
1441+
.toFile();
1442+
13961443
// invalid
13971444
test(":\\foo")
13981445
.invalid();
@@ -2045,6 +2092,18 @@ static void doUnixTests() {
20452092
test("/foo/bar/gus/../..")
20462093
.normalize("/foo");
20472094

2095+
// equals
2096+
test("this")
2097+
.equals("this")
2098+
.notEquals(Path.of("that"))
2099+
.notEquals(null)
2100+
.notEquals(new Object())
2101+
.notEquals(Path.of("This"));
2102+
2103+
// toFile
2104+
test("/foo/bar/gus")
2105+
.toFile();
2106+
20482107
// invalid
20492108
test("foo\u0000bar")
20502109
.invalid();
@@ -2122,7 +2181,7 @@ public static void main(String[] args) {
21222181

21232182
// operating system specific
21242183
String osname = System.getProperty("os.name");
2125-
if (osname.startsWith("Windows")) {
2184+
if (Platform.isWindows()) {
21262185
doWindowsTests();
21272186
} else {
21282187
doUnixTests();

0 commit comments

Comments
 (0)