when(path.getFileSystem()).thenReturn(mock(FileSystem.class)); when(path.getFileSystem().provider()).thenReturn(mock(FileSystemProvider.class)); when(path.getFileSystem().provider().readAttributes(path, BasicFileAttributes.class)) .thenReturn(attributes);
@Override public Map<String, Object> readAttributes(final Path path, final String attributes, final LinkOption... options) throws IOException { return delegate.readAttributes(path, attributes, options); }
@Override public <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) throws IOException { return delegate.readAttributes(path, type, options); }
@Override public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException { return delegate.readAttributes(resolveRelative(path), attributes, options); }
@Override public void checkAccess(Path path, Set<? extends AccessMode> modes, LinkOption... linkOptions) throws IOException { if (isFollowLinks(linkOptions)) { delegate.checkAccess(resolveRelative(path), modes.toArray(new AccessMode[modes.size()])); } else if (modes.isEmpty()) { delegate.readAttributes(path, "isRegularFile", LinkOption.NOFOLLOW_LINKS); } else { throw new UnsupportedOperationException("CheckAccess for NIO Provider is unsupported with non empty AccessMode and NOFOLLOW_LINKS."); } }
@Override public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException { Path r = unroot(path); if (log.isTraceEnabled()) { log.trace("readAttributes({})[{}] type={}", path, r, type.getSimpleName()); } FileSystemProvider p = provider(r); return p.readAttributes(r, type, options); }
@Override public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException { Path r = unroot(path); if (log.isTraceEnabled()) { log.trace("readAttributes({})[{}] type={}", path, r, type.getSimpleName()); } FileSystemProvider p = provider(r); return p.readAttributes(r, type, options); }
@Override public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException { Path r = unroot(path); FileSystemProvider p = provider(r); Map<String, Object> attrs = p.readAttributes(r, attributes, options); if (log.isTraceEnabled()) { log.trace("readAttributes({})[{}] {}: {}", path, r, attributes, attrs); } return attrs; }
@Override public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException { Path r = unroot(path); FileSystemProvider p = provider(r); Map<String, Object> attrs = p.readAttributes(r, attributes, options); if (log.isTraceEnabled()) { log.trace("readAttributes({})[{}] {}: {}", path, r, attributes, attrs); } return attrs; }
@Override public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException { BundleFileSystem fs = (BundleFileSystem) path.getFileSystem(); return origProvider(path).readAttributes(fs.unwrap(path), attributes, options); }
@Override public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException { BundleFileSystem fs = (BundleFileSystem) path.getFileSystem(); return origProvider(path) .readAttributes(fs.unwrap(path), type, options); }
@Test @Category( { Attributes.class, WorkingDirectoryInPlaygroundTree.class } ) public void testGetLastModifiedViaStringOfRelativePath() throws IOException { Path path = getFile(); assertThat( FS.provider().readAttributes( pathDefault().toAbsolutePath().relativize( path ), "basic:lastModifiedTime" ).get( "lastModifiedTime" ) ). isEqualTo( FS.provider().readAttributes( path, "basic:lastModifiedTime" ).get( "lastModifiedTime" ) ); }
@Override public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException { Path r = unroot(path); FileSystemProvider p = provider(r); Map<String, Object> attrs = p.readAttributes(r, attributes, options); return attrs; }
@Override public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException { Path r = unroot(path); FileSystemProvider p = provider(r); return p.readAttributes(r, type, options); }
@Test @Category( Attributes.class ) public void testReadAttributesOneUnknownAttributeThrows() throws IOException { assertThatThrownBy( () -> FS.provider().readAttributes( pathDefault(), "basic:lastModifiedTime,duda" ) ) .isInstanceOf( IllegalArgumentException.class ); }
@Test @Category( Attributes.class ) public void testUnsupportedAttributesThrows() throws IOException { assertThatThrownBy( () -> FS.provider().readAttributes( pathDefault(), UnsiAttris.class )).isInstanceOf( UnsupportedOperationException.class ); }
@Test @Category( Attributes.class ) public void testReadUnsupportedAttributeThrows() throws IOException { assertThatThrownBy( () -> FS.provider().readAttributes( pathDefault(), "thisissuchasillyattributesname:duda" )).isInstanceOf( UnsupportedOperationException.class ); }
@Test @Category( Attributes.class ) public void testReadAttributesUnknownAttributeThrows() throws IOException { assertThatThrownBy( () -> FS.provider().readAttributes( pathDefault(), "basic:duda" )).isInstanceOf( IllegalArgumentException.class ); }
@Test( expected = ClosedFileSystemException.class ) @Category( Closable.class ) public void testClosedFSReadAttributesString() throws IOException { getClosedFSProvider().readAttributes( getClosedFileA(), "*" ); }
@Test( expected = ClosedFileSystemException.class ) @Category( Closable.class ) public void testClosedFSReadAttributes() throws IOException { getClosedFSProvider().readAttributes( getClosedFileA(), BasicFileAttributes.class ); }