@@ -67,6 +67,16 @@ static void checkWithin1GB(String space, long expected, long actual) {
6767 }
6868 }
6969
70+ static <V extends FileAttributeView > void testFileAttributes (Path file ,
71+ Class <V > viewClass ,
72+ String viewName ) throws IOException {
73+ FileStore store = Files .getFileStore (file );
74+ boolean supported = store .supportsFileAttributeView (viewClass );
75+ assertTrue (store .supportsFileAttributeView (viewName ) == supported );
76+ boolean haveView = Files .getFileAttributeView (file , viewClass ) != null ;
77+ assertTrue (haveView == supported );
78+ }
79+
7080 static void doTests (Path dir ) throws IOException {
7181 /**
7282 * Test: Directory should be on FileStore that is writable
@@ -97,21 +107,11 @@ static void doTests(Path dir) throws IOException {
97107 * Test: File and FileStore attributes
98108 */
99109 assertTrue (store1 .supportsFileAttributeView ("basic" ));
100- assertTrue (store1 .supportsFileAttributeView (BasicFileAttributeView .class ));
101- assertTrue (store1 .supportsFileAttributeView ("posix" ) ==
102- store1 .supportsFileAttributeView (PosixFileAttributeView .class ));
103- assertTrue (store1 .supportsFileAttributeView ("dos" ) ==
104- store1 .supportsFileAttributeView (DosFileAttributeView .class ));
105- assertTrue (store1 .supportsFileAttributeView ("acl" ) ==
106- store1 .supportsFileAttributeView (AclFileAttributeView .class ));
107- assertTrue (store1 .supportsFileAttributeView ("user" ) ==
108- store1 .supportsFileAttributeView (UserDefinedFileAttributeView .class ));
109-
110- // check if getFileAttributeView behaves as specified if the user defined view is unsupported
111- if (!store1 .supportsFileAttributeView (UserDefinedFileAttributeView .class ) &&
112- Files .getFileAttributeView (dir , UserDefinedFileAttributeView .class ) != null ) {
113- throw new RuntimeException ("UserDefinedFileAttributeView not supported, getFileAttributeView should return null" );
114- }
110+ testFileAttributes (dir , BasicFileAttributeView .class , "basic" );
111+ testFileAttributes (dir , PosixFileAttributeView .class , "posix" );
112+ testFileAttributes (dir , DosFileAttributeView .class , "dos" );
113+ testFileAttributes (dir , AclFileAttributeView .class , "acl" );
114+ testFileAttributes (dir , UserDefinedFileAttributeView .class , "user" );
115115
116116 /**
117117 * Test: Space atributes
0 commit comments