--- old/test/jdk/java/nio/file/Path/PathOps.java 2018-02-13 17:25:20.000000000 -0800 +++ new/test/jdk/java/nio/file/Path/PathOps.java 2018-02-13 17:25:20.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ */ /* @test - * @bug 4313887 6838333 6925932 7006126 8037945 8072495 8140449 + * @bug 4313887 6838333 6925932 7006126 8037945 8057113 8072495 8140449 * @summary Unit test for java.nio.file.Path path operations */ @@ -156,6 +156,35 @@ return this; } + PathOps ext(String... extensions) { + out.format("test hasExtension {%s", extensions[0]); + final int len = extensions.length; + for (int i = 1; i < len; i++) { + out.format(", %s", extensions[i]); + } + out.format("}%n"); + checkPath(); + check(path.hasExtension(extensions), true); + return this; + } + + PathOps notExt(String... extensions) { + if (extensions == null) { + out.format("test not hasExtension for empty parameter"); + extensions = new String[0]; + } else { + out.format("test not hasExtension {%s", extensions[0]); + final int len = extensions.length; + for (int i = 1; i < len; i++) { + out.format(", %s", extensions[i]); + } + out.format("}%n"); + } + checkPath(); + check(path.hasExtension(extensions), false); + return this; + } + PathOps makeAbsolute() { this.path = path.toAbsolutePath(); return this; @@ -413,6 +442,30 @@ .ends("") .notEnds("\\"); + // hasExtension + test("") + .notExt(null) + .notExt("", ".", "\\") + .notExt("mp3", "mp4"); + test(".") + .notExt(null) + .notExt("", ".", "\\") + .notExt("mp3", "mp4"); + test("./foo/") + .notExt(null) + .notExt("", ".", "\\") + .notExt("foo") + .notExt("mp3", "mp4"); + test("image.jpg") + .ext("jpg") + .ext("jpg", "JPG") + .ext("JPG", "jpg") + .ext("png", "PNG", "tiff", "JPG", "jpg") + .notExt(null) + .notExt("", ".", "\\") + .notExt(".jpg") + .notExt("bmp", "BMP"); + // elements test("C:\\a\\b\\c") .element(0, "a") @@ -1563,6 +1616,30 @@ .ends("") .notEnds("/"); + // hasExtension + test("") + .notExt(null) + .notExt("", ".", "/") + .notExt("mp3", "mp4"); + test(".") + .notExt(null) + .notExt("", ".", "/") + .notExt("mp3", "mp4"); + test("./foo/") + .notExt(null) + .notExt("", ".", "/") + .notExt("foo") + .notExt("mp3", "mp4"); + test("image.jpg") + .ext("jpg") + .ext("jpg", "JPG") + .ext("JPG", "jpg") + .ext("png", "PNG", "tiff", "JPG", "jpg") + .notExt(null) + .notExt("", ".", "/") + .notExt(".jpg") + .notExt("bmp", "BMP"); + // elements test("a/b/c") .element(0, "a") @@ -2074,6 +2151,11 @@ } catch (NullPointerException npe) { } + try { + path.hasExtension((String[])null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException npe) { + } } public static void main(String[] args) {