@Override
    public void trash(final Local file) throws LocalAccessDeniedException {
        synchronized(NSWorkspace.class) {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Move %s to Trash", file));
            }
            // Asynchronous operation. 0 if the operation is performed synchronously and succeeds, and a positive
            // integer if the operation is performed asynchronously and succeeds
            if(!workspace.performFileOperation(
                NSWorkspace.RecycleOperation,
                new NFDNormalizer().normalize(file.getParent().getAbsolute()).toString(), StringUtils.EMPTY,
                NSArray.arrayWithObject(new NFDNormalizer().normalize(file.getName()).toString()))) {
                throw new LocalAccessDeniedException(String.format("Failed to move %s to Trash", file.getName()));
            }
        }
    }
@Test
    public void testTrashOpenFile() throws Exception {
        final Trash trash = new WorkspaceTrashFeature();
        final SupportDirectoryFinder finder = new TemporarySupportDirectoryFinder();

        final Local temp = finder.find();
        final Local directory = LocalFactory.get(temp, UUID.randomUUID().toString());
        directory.mkdir();
        final Local sub = LocalFactory.get(directory, UUID.randomUUID().toString());
        sub.mkdir();
        final Local file = LocalFactory.get(sub, UUID.randomUUID().toString());
        final Touch touch = LocalTouchFactory.get();
        touch.touch(file);

        try (final OutputStream stream = file.getOutputStream(false)) {
            trash.trash(directory);
        }
    }