@Override
    public void revert(final Path file) throws BackgroundException {
        // To restore a version all that needs to be done is to move a version the special restore folder at /remote.php/dav/versions/USER/restore
        try {
            session.getClient().move(URIEncoder.encode(file.getAbsolute()),
                    URIEncoder.encode(String.format("%s/restore/target",
                            new NextcloudHomeFeature(session.getHost()).find(NextcloudHomeFeature.Context.versions).getAbsolute()))
            );
        }
        catch(SardineException e) {
            throw new DAVExceptionMappingService().map("Cannot revert file", e, file);
        }
        catch(IOException e) {
            throw new HttpExceptionMappingService().map(e, file);
        }
    }
@Test
    public void testRevert() throws Exception {
        final Path directory = new DAVDirectoryFeature(session, new NextcloudAttributesFinderFeature(session)).mkdir(new Path(new DefaultHomeFinderService(session).find(),
                new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
        final Path test = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final TransferStatus status = new TransferStatus();
        final NextcloudWriteFeature writer = new NextcloudWriteFeature(session);
        final byte[] initialContent = RandomUtils.nextBytes(32769);
        {
            new StreamCopier(status, status).transfer(new ByteArrayInputStream(initialContent), writer.write(test, status.withLength(initialContent.length), new DisabledConnectionCallback()));
        }
        final NextcloudVersioningFeature feature = new NextcloudVersioningFeature(session);
        assertEquals(0, feature.list(test.withAttributes(new NextcloudAttributesFinderFeature(session).find(test)), new DisabledListProgressListener()).size());
        final PathAttributes initialAttributes = new NextcloudAttributesFinderFeature(session).find(test);
        final byte[] contentUpdate = RandomUtils.nextBytes(16258);
        {
            new StreamCopier(status, status).transfer(new ByteArrayInputStream(contentUpdate), writer.write(test, status.withLength(contentUpdate.length).exists(true), new DisabledConnectionCallback()));
            final AttributedList<Path> versions = feature.list(test.withAttributes(new NextcloudAttributesFinderFeature(session).find(test)), new DisabledListProgressListener());
            assertEquals(1, versions.size());
        }
        {
            final byte[] contentLatest = RandomUtils.nextBytes(13247);
            new StreamCopier(status, status).transfer(new ByteArrayInputStream(contentLatest), writer.write(test, status.withLength(contentLatest.length).exists(true), new DisabledConnectionCallback()));
        }
        final AttributedList<Path> versions = feature.list(test.withAttributes(new NextcloudAttributesFinderFeature(session).find(test)), new DisabledListProgressListener());
        assertEquals(2, versions.size());
        final Path initialVersion = versions.get(1);
        {
            assertEquals(initialAttributes.getSize(), initialVersion.attributes().getSize());
            assertEquals(initialAttributes.getModificationDate(), initialVersion.attributes().getModificationDate());
            assertNotNull(initialVersion.attributes().getVersionId());
            assertNotEquals(initialAttributes, new NextcloudAttributesFinderFeature(session).find(test));
            assertEquals(initialVersion.attributes(), new NextcloudAttributesFinderFeature(session).find(initialVersion));
            {
                final InputStream reader = new NextcloudReadFeature(session).read(initialVersion, new TransferStatus(), new DisabledLoginCallback());
                assertArrayEquals(initialContent, IOUtils.readFully(reader, initialContent.length));
                reader.close();
            }
            final Path updatedVersion = versions.get(0);
            assertEquals(contentUpdate.length, new NextcloudAttributesFinderFeature(session).find(updatedVersion).getSize());
            {
                final InputStream reader = new NextcloudReadFeature(session).read(updatedVersion, new TransferStatus(), new DisabledLoginCallback());
                assertArrayEquals(contentUpdate, IOUtils.readFully(reader, contentUpdate.length));
                reader.close();
            }
        }
        feature.revert(initialVersion);
        assertEquals(initialVersion.attributes().getModificationDate(), new NextcloudAttributesFinderFeature(session).find(test).getModificationDate());
        new DAVDeleteFeature(session).delete(Arrays.asList(test, directory), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }