/* * Copyright (c) 2019, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Remove JAR files used by test as part of clean-up
*/
@AfterClass publicvoid tearDown() throws Exception {
Files.deleteIfExists(jarFile);
Files.deleteIfExists(emptyJarFile);
}
/** * Validate that you can specify a DirectoryStream filter using the ZIP File * System and that the returned Iterator correctly indicates whether the * filter has been matched
*/
@Test(dataProvider = "filterTestValues") publicvoid test0000(String glob, boolean expectedResult, String errMsg) throws Exception {
/** * Validate that you can specify a glob using the ZIP File System and that the * returned Iterator correctly indicates whether the glob pattern has been matched
*/
@Test(dataProvider = "filterTestValues") publicvoid test0001(String glob, boolean expectedResult, String errMsg) throws Exception {
/** * Validate a PatternSyntaxException is thrown when specifying an invalid * glob pattern with the ZIP File system
*/
@Test publicvoid test0002() throws Exception {
/** * Validate that the correct type of paths are returned when creating a * DirectoryStream
*/
@Test(dataProvider = "startPaths") publicvoid test0003(String startPath, String expectedPath) throws IOException { try (FileSystem zipfs =
ZIPFS_PROVIDER.newFileSystem(Paths.get("basic.jar"), UNZIPFS_MAP);
DirectoryStream<Path> stream =
Files.newDirectoryStream(zipfs.getPath(startPath))) {
for (Path entry : stream) {
assertTrue(entry.toString().equals(expectedPath),
String.format("Error: Expected path %s not found when"
+ " starting at %s%n", expectedPath, entry));
}
}
}
/** * Validate a NotDirectoryException is thrown when specifying a file for the * starting path for creating a DirectoryStream with the ZIP File System
*/
@Test publicvoid test0004() throws Exception {
/** * Validate an IllegalStateException is thrown when accessing the Iterator * more than once with the ZIP File System
*/
@Test publicvoid test0005() throws Exception {
/** * Validate an IllegalStateException is thrown when accessing the Iterator * after the DirectoryStream has been closed with the ZIP File System
*/
@Test publicvoid test0006() throws Exception {
// ZipDirectoryStream.iterator() throws ClosedDirectoryStream when // obtaining an Iterator when the DirectoryStream is closed
assertThrows(ClosedDirectoryStreamException.class, () -> ds.iterator());
}
}
/** * Validate an UnsupportedOperationException is thrown when invoking an * Iterator operation that is not supported with the ZIP File System
*/
@Test publicvoid test0007() throws Exception {
/** * Validate an NoSuchElementException is thrown when invoking an * Iterator.next() on a closed DirectoryStream with the ZIP File System
*/
@Test publicvoid test0008() throws Exception {
/** * Validate Iterator.hasNext() returns false when the directory is empty with * the ZIP File System
*/
@Test publicvoid test0009() throws Exception { try (FileSystem zipfs =
ZIPFS_PROVIDER.newFileSystem(emptyJarFile, UNZIPFS_MAP);
DirectoryStream<Path> ds =
Files.newDirectoryStream(zipfs.getPath("emptyDir"))) {
assertFalse(ds.iterator().hasNext(), "Error: directory was not empty!");
}
}
/** * Validate Iterator.hasNext() returns false when the DirectoryStream is closed * with the ZIP File System
*/
@Test publicvoid test0010() throws Exception {
try (FileSystem zipfs =
ZIPFS_PROVIDER.newFileSystem(Paths.get("basic.jar"), UNZIPFS_MAP);
DirectoryStream<Path> ds =
Files.newDirectoryStream(zipfs.getPath("/"))) {
Iterator<Path> i = ds.iterator();
ds.close();
assertFalse(i.hasNext(), "Error: false should be returned as DirectoryStream is closed!");
}
}
/** * Validate that an IOException thrown by a filter is returned as the cause * via a DirectoryIteratorException
*/
@Test publicvoid test0011() throws Exception {
} catch (DirectoryIteratorException x) {
IOException cause = x.getCause(); if (!(cause instanceof ZipException)) thrownew RuntimeException("Expected IOException not propagated");
}
}
/** * Glob values to use to validate filtering
*/
@DataProvider(name = "filterTestValues") publicstatic Object[][] filterValues() {
String expectedMsg = "Error: Matching entries were expected but not found!!!";
String notExpectedMsg = "Error: No matching entries expected but were found!!!"; returnnew Object[][]{
/** * Starting Path for the DirectoryStream and the expected path to be returned * when traversing the stream
*/
@DataProvider(name = "startPaths") publicstatic Object[][] Name() { returnnew Object[][]{
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.