@Override
    public PermissionOverwrite run(final Session<?> session) throws BackgroundException {
        final UnixPermission feature = session.getFeature(UnixPermission.class);
        if(log.isDebugEnabled()) {
            log.debug(String.format("Run with feature %s", feature));
        }
        final List<Permission> permissions = new ArrayList<>();
        for(Path next : files) {
            if(this.isCanceled()) {
                throw new ConnectionCanceledException();
            }
            permissions.add(feature.getUnixPermission(next));
        }

        final PermissionOverwrite overwrite = new PermissionOverwrite();
        final Supplier<Stream<Permission>> supplier = permissions::stream;

        overwrite.user.read = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.read));
        overwrite.user.write = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.write));
        overwrite.user.execute = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.execute));

        overwrite.group.read = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.read));
        overwrite.group.write = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.write));
        overwrite.group.execute = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.execute));

        overwrite.other.read = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.read));
        overwrite.other.write = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.write));
        overwrite.other.execute = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.execute));

        return overwrite;
    }
@Test
    public void testRun() throws Exception {
        final ReadPermissionWorker worker = new ReadPermissionWorker(
                Arrays.asList(
                        new Path("/a", EnumSet.of(Path.Type.file), new TestPermissionAttributes(Permission.Action.all, Permission.Action.all, Permission.Action.none)),
                        new Path("/b", EnumSet.of(Path.Type.file), new TestPermissionAttributes(Permission.Action.all, Permission.Action.read_write, Permission.Action.read)))) {
            @Override
            public void cleanup(final PermissionOverwrite result) {
                //
            }
        };

        PermissionOverwrite overwrite = worker.run(new NullSession(new Host(new TestProtocol())) {
            @Override
            @SuppressWarnings("unchecked")
            public <T> T _getFeature(final Class<T> type) {
                if(type == UnixPermission.class) {
                    return (T) new UnixPermission() {
                        @Override
                        public void setUnixOwner(final Path file, final String owner) {
                            throw new UnsupportedOperationException();
                        }

                        @Override
                        public void setUnixGroup(final Path file, final String group) {
                            throw new UnsupportedOperationException();
                        }

                        @Override
                        public Permission getUnixPermission(final Path file) {
                            return file.attributes().getPermission();
                        }

                        @Override
                        public void setUnixPermission(final Path file, final TransferStatus status) throws BackgroundException {
                            throw new UnsupportedOperationException();
                        }
                    };
                }
                return super._getFeature(type);
            }
        });

        /*
        +-----+-----+-----+
        | rwx | rwx | --- |
        | rwx | rw- | r-- |
        +=====+=====+=====+
        | rwx | rw? | ?-- |
        +-----+-----+-----+
         */

        assertEquals(Boolean.TRUE, overwrite.user.read);
        assertEquals(Boolean.TRUE, overwrite.user.write);
        assertEquals(Boolean.TRUE, overwrite.user.execute);

        assertEquals(Boolean.TRUE, overwrite.group.read);
        assertEquals(Boolean.TRUE, overwrite.group.write);
        assertNull(overwrite.group.execute);

        assertNull(overwrite.other.read);
        assertEquals(Boolean.FALSE, overwrite.other.write);
        assertEquals(Boolean.FALSE, overwrite.other.execute);

        assertEquals("Getting permission of a… (Multiple files) (2)", worker.getActivity());
    }