changeset 7714:e5c621a1ca4f

Windows doesn't support PosixFilePermission for FilesLambdaTest.java
author Tristan Yan <tristan.yan@oracle.com>
date Fri, 22 Mar 2013 20:16:07 +0800
parents 7a27a3ca89f7
children 6411a88d1a48
files test/java/nio/Files/FilesLambdaTest.java
diffstat 1 files changed, 12 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/nio/Files/FilesLambdaTest.java	Wed Mar 20 23:22:37 2013 -0700
+++ b/test/java/nio/Files/FilesLambdaTest.java	Fri Mar 22 20:16:07 2013 +0800
@@ -37,18 +37,15 @@
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.LinkOption;
+import java.nio.file.NotDirectoryException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileAttribute;
-import java.nio.file.attribute.PosixFilePermission;
-import java.nio.file.attribute.PosixFilePermissions;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Random;
-import java.util.Set;
 import java.util.function.Consumer;
 import java.util.stream.CloseableStream;
 import java.util.stream.Collectors;
@@ -112,8 +109,6 @@
 
     private Path testFile;
     
-    private Path readOnlyDir;
-    
     private Path notExistPath;
 
     final Consumer<Path> writeReverseWithLink = path -> {
@@ -157,12 +152,6 @@
             throw new RuntimeException(ex);
         }
         
-        String CAN_NOT_READ = "can_not_read" ;
-        readOnlyDir = Paths.get(TEST_SRC, CAN_NOT_READ);
-        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("-wx-wx-wx");
-        FileAttribute<Set<PosixFilePermission>> fas = PosixFilePermissions.asFileAttribute(perms);
-        Files.createDirectory(readOnlyDir, fas);
-        
         String NOT_EXIST = "NOT_EXIST";
         notExistPath = Paths.get(TEST_SRC, NOT_EXIST);
     }
@@ -188,9 +177,6 @@
         if(testFile != null) {
             Files.delete(testFile);
         }
-        if(readOnlyDir != null) {
-            Files.delete(readOnlyDir);
-        }
     }
 
     @Test
@@ -231,7 +217,8 @@
             @Override
             public FileVisitResult postVisitDirectory(Path dir, IOException exc)
                 throws IOException{
-                if (walkFolder.relativize(dir).getNameCount() <= maxDepth) {
+                if (walkFolder.relativize(dir).getNameCount() <= maxDepth
+                        || walkFolder.equals(dir)) {
                     expectedMaxDepthDirList.add(dir);
                 }
                 expectedFullDirList.add(dir);
@@ -270,8 +257,7 @@
         String[] dir = folders[rand.nextInt(folders.length)];
         Path walkFolder = Paths.get(ROOT_NAME, dir);
         String walkFoderName = dir[dir.length - 1];
-        
-        System.out.println(walkFoderName);
+
         int walkFolderDepth = Integer.parseInt(walkFoderName.substring(walkFoderName.length() - 2));
         int maxDepth = rand.nextInt(11);
         CloseableStream<Path> stream 
@@ -299,11 +285,16 @@
     
     @Test(expectedExceptions = IOException.class)
     public void testListNoReadAccess() throws IOException{
-        Files.list(readOnlyDir);
+        Files.list(notExistPath);
     }
-        
+    
+    @Test(expectedExceptions = NotDirectoryException.class)
+    public void testListNotDirectory() throws IOException{
+        Files.list(testFile);
+    }
+
     @Test(expectedExceptions = IOException.class)
-    public void testFineNoExist() throws IOException{
+    public void testFindNoExist() throws IOException{
         Files.find(notExistPath, Integer.MAX_VALUE, (p, bfa) -> true);
     }