@Test public void testStat() throws Exception { int nonce = 123; FileSystem fileSystem = mockFileSystem(); Path path = mockPath("/", fileSystem); Instant base = Instant.now(); Map<String, Object> attributes = mockAttributes(nonce, base); when(fileSystem.provider().readAttributes(eq(path), eq("unix:*"), any())).thenReturn(attributes); UnixFileStatImpl stat = new UnixFileStatImpl(); UnixFileStat result = stat.stat(path); assertThat(result).isSameAs(stat); assertThat(stat.getDev()).isEqualTo(nonce * 3L); assertThat(stat.getIno()).isEqualTo(nonce * 5L); assertThat(stat.getLinks()).isEqualTo(nonce * 7); assertThat(stat.getMode()).isEqualTo(nonce * 11); assertThat(stat.getUid()).isEqualTo(nonce * 13); assertThat(stat.getGid()).isEqualTo(nonce * 17); assertThat(stat.getRdev()).isEqualTo(nonce * 19L); assertThat(stat.getSize()).isEqualTo(nonce * 23L); assertThat(stat.getBlocks()).isEqualTo(stat.getSize() / 512 + 1); assertThat(stat.getAccessTime()).isEqualTo(FileTime.from(base.minus(29, ChronoUnit.DAYS)).toInstant()); assertThat(stat.getModificationTime()).isEqualTo(FileTime.from(base.minus(31, ChronoUnit.DAYS)).toInstant()); assertThat(stat.getInodeTime()).isEqualTo(FileTime.from(base.minus(37, ChronoUnit.DAYS)).toInstant()); }
@Override public UnixFileStat stat(Path path) throws IOException { Map<String, Object> map = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS); setDev((long) map.get("dev")); setIno((long) map.get("ino")); setLinks((int) map.get("nlink")); setMode((int) map.get("mode")); setUid((int) map.get("uid")); setGid((int) map.get("gid")); setRdev((long) map.get("rdev")); long size = (long) map.get("size"); setSize(size); setBlkSize(BLK_SIZE); setBlocks(size / 512 + 1); setAccessTime(getInstant(map, "lastAccessTime")); setModificationTime(getInstant(map, "lastModifiedTime")); setInodeTime(getInstant(map, "ctime")); return this; }
UnixFileStatImpl implements UnixFileStat, StatFiller { @Override public UnixFileStat stat(Path path) throws IOException { Map<String, Object> map = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS); setDev((long) map.get("dev")); setIno((long) map.get("ino")); setLinks((int) map.get("nlink")); setMode((int) map.get("mode")); setUid((int) map.get("uid")); setGid((int) map.get("gid")); setRdev((long) map.get("rdev")); long size = (long) map.get("size"); setSize(size); setBlkSize(BLK_SIZE); setBlocks(size / 512 + 1); setAccessTime(getInstant(map, "lastAccessTime")); setModificationTime(getInstant(map, "lastModifiedTime")); setInodeTime(getInstant(map, "ctime")); return this; } }
UnixFileStatImpl implements UnixFileStat, StatFiller { @Override public UnixFileStat stat(Path path) throws IOException { Map<String, Object> map = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS); setDev((long) map.get("dev")); setIno((long) map.get("ino")); setLinks((int) map.get("nlink")); setMode((int) map.get("mode")); setUid((int) map.get("uid")); setGid((int) map.get("gid")); setRdev((long) map.get("rdev")); long size = (long) map.get("size"); setSize(size); setBlkSize(BLK_SIZE); setBlocks(size / 512 + 1); setAccessTime(getInstant(map, "lastAccessTime")); setModificationTime(getInstant(map, "lastModifiedTime")); setInodeTime(getInstant(map, "ctime")); return this; } protected  UnixFileStatImpl(); }
UnixFileStatImpl implements UnixFileStat, StatFiller { @Override public UnixFileStat stat(Path path) throws IOException { Map<String, Object> map = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS); setDev((long) map.get("dev")); setIno((long) map.get("ino")); setLinks((int) map.get("nlink")); setMode((int) map.get("mode")); setUid((int) map.get("uid")); setGid((int) map.get("gid")); setRdev((long) map.get("rdev")); long size = (long) map.get("size"); setSize(size); setBlkSize(BLK_SIZE); setBlocks(size / 512 + 1); setAccessTime(getInstant(map, "lastAccessTime")); setModificationTime(getInstant(map, "lastModifiedTime")); setInodeTime(getInstant(map, "ctime")); return this; } protected  UnixFileStatImpl(); @Override long getDev(); @Override long getIno(); @Override int getLinks(); @Override int getMode(); @Override int getUid(); @Override int getGid(); @Override long getRdev(); @Override long getSize(); @Override int getBlkSize(); @Override long getBlocks(); @Override Instant getAccessTime(); @Override Instant getModificationTime(); @Override Instant getInodeTime(); @Override UnixFileStat stat(Path path); @Override UnixFileStat statWithSize(Path path, Function<FileInfo, Optional<Long>> sizeGetter, Supplier<Long> extraSizeGetter); }
UnixFileStatImpl implements UnixFileStat, StatFiller { @Override public UnixFileStat stat(Path path) throws IOException { Map<String, Object> map = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS); setDev((long) map.get("dev")); setIno((long) map.get("ino")); setLinks((int) map.get("nlink")); setMode((int) map.get("mode")); setUid((int) map.get("uid")); setGid((int) map.get("gid")); setRdev((long) map.get("rdev")); long size = (long) map.get("size"); setSize(size); setBlkSize(BLK_SIZE); setBlocks(size / 512 + 1); setAccessTime(getInstant(map, "lastAccessTime")); setModificationTime(getInstant(map, "lastModifiedTime")); setInodeTime(getInstant(map, "ctime")); return this; } protected  UnixFileStatImpl(); @Override long getDev(); @Override long getIno(); @Override int getLinks(); @Override int getMode(); @Override int getUid(); @Override int getGid(); @Override long getRdev(); @Override long getSize(); @Override int getBlkSize(); @Override long getBlocks(); @Override Instant getAccessTime(); @Override Instant getModificationTime(); @Override Instant getInodeTime(); @Override UnixFileStat stat(Path path); @Override UnixFileStat statWithSize(Path path, Function<FileInfo, Optional<Long>> sizeGetter, Supplier<Long> extraSizeGetter);  }