@Override
    public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
        try {
            if(status.isExists()) {
                if(log.isWarnEnabled()) {
                    log.warn(String.format("Trash file %s to be replaced with %s", renamed, file));
                }
                delete.delete(Collections.singletonMap(renamed, status), connectionCallback, callback);
            }
            final String id = fileid.getFileId(file);
            File result = null;
            if(!StringUtils.equals(file.getName(), renamed.getName())) {
                // Rename title
                final File properties = new File();
                properties.setName(renamed.getName());
                properties.setMimeType(status.getMime());
                result = session.getClient().files().update(id, properties)
                        .setFields(DriveAttributesFinderFeature.DEFAULT_FIELDS)
                        .setSupportsAllDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable"))
                        .execute();
            }
            if(!new SimplePathPredicate(file.getParent()).test(renamed.getParent())) {
                // Retrieve the existing parents to remove
                final StringBuilder previousParents = new StringBuilder();
                final File reference = session.getClient().files().get(id)
                        .setFields("parents")
                        .setSupportsAllDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable"))
                        .execute();
                for(String parent : reference.getParents()) {
                    previousParents.append(parent).append(',');
                }
                // Move the file to the new folder
                result = session.getClient().files().update(id, null)
                    .setAddParents(fileid.getFileId(renamed.getParent()))
                    .setRemoveParents(previousParents.toString())
                    .setFields(DriveAttributesFinderFeature.DEFAULT_FIELDS)
                    .setSupportsAllDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable"))
                    .execute();
            }
            fileid.cache(file, null);
            fileid.cache(renamed, id);
            return renamed.withAttributes(new DriveAttributesFinderFeature(session, fileid).toAttributes(result));
        }
        catch(IOException e) {
            throw new DriveExceptionMappingService(fileid).map("Cannot rename {0}", e, file);
        }
    }
@Test
    public void testMoveFile() throws Exception {
        final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
        final Path test = new DriveTouchFeature(session, fileid).touch(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
        final String id = test.attributes().getFileId();
        final Path folder = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
        new DriveDirectoryFeature(session, fileid).mkdir(folder, new TransferStatus());
        final Path target = new DriveMoveFeature(session, fileid).move(test, new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
        assertEquals(id, target.attributes().getFileId());
        final Find find = new DefaultFindFeature(session);
        assertFalse(find.find(test));
        assertTrue(find.find(target));
        final PathAttributes targetAttr = new DriveAttributesFinderFeature(session, fileid).find(target);
        assertEquals(Comparison.equal, session.getHost().getProtocol().getFeature(ComparisonService.class).compare(Path.Type.file, target.attributes(), targetAttr));
        new DriveDeleteFeature(session, fileid).delete(Arrays.asList(target, folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }