### Question:
S3Helper { public void restoreFileVersion(String bucket, String path, String version) { AmazonS3 client = getDefaultS3Client(); if (fileSizeExceedsLimit(client, bucket, path, version)) { throw new DataStorageException(String.format("Restoring file '%s' version '%s' was aborted because " + "file size exceeds the limit of %s bytes", path, version, COPYING_FILE_SIZE_LIMIT)); } moveS3Object(client, bucket, new MoveObjectRequest(path, version, path)); }  AmazonS3 getDefaultS3Client(); String createS3Bucket(final String name); ActionStatus postCreationProcessing(final String name,
                                               final String policy,
                                               final List<String> allowedCidrs,
                                               final List<CORSRule> corsRules,
                                               final AwsRegion region,
                                               final boolean shared,
                                               String kmsDataEncryptionKeyId,
                                               final Map<String, String> tags); void deleteS3Bucket(String name); void applyStoragePolicy(String bucketName, StoragePolicy policy); void restoreFileVersion(String bucket, String path, String version); DataStorageListing getItems(String bucket, String path, Boolean showVersion,
            Integer pageSize, String marker, String prefix); DataStorageDownloadFileUrl generateDownloadURL(String bucket, String path,
                                                          String version, ContentDisposition contentDisposition); DataStorageDownloadFileUrl generateDataStorageItemUploadUrl(String bucket, String path, String owner); DataStorageFile createFile(String bucket, String path, byte[] contents, String owner); DataStorageFile createFile(String bucket, String path, InputStream dataStream, String owner); DataStorageFolder createFolder(String bucket, String path); void deleteFile(String bucket, String path, String version, Boolean totally); void deleteFolder(String bucket, String path, Boolean totally); DataStorageFile moveFile(String bucket, String oldPath, String newPath); DataStorageFolder moveFolder(String bucket, String rawOldPath, String rawNewPath); boolean checkBucket(String bucket); PathDescription getDataSize(final S3bucketDataStorage dataStorage, final String path,
                                       final PathDescription pathDescription); Map<String, String> updateObjectTags(AbstractDataStorage dataStorage, String path, Map<String, String> tags,
                                 String version); Map<String, String> listObjectTags(AbstractDataStorage dataStorage, String path, String version); Map<String, String> deleteObjectTags(AbstractDataStorage dataStorage, String path, Set<String> tagKeys,
                                                String version); DataStorageItemContent getFileContent(AbstractDataStorage dataStorage, String path, String version,
            Long maxDownloadSize); DataStorageStreamingContent getFileStream(AbstractDataStorage dataStorage, String path, String version);  }### Answer:
@Test public void testRestoreFileVersionShouldThrowIfFileSizeExceedsTheLimit() { final ObjectMetadata fileMetadata = new ObjectMetadata(); fileMetadata.setContentLength(EXCEEDED_OBJECT_SIZE); when(amazonS3.getObjectMetadata(any())).thenReturn(fileMetadata); assertThrows(e -> e instanceof DataStorageException && e.getMessage().contains(SIZE_EXCEEDS_EXCEPTION_MESSAGE), () -> helper.restoreFileVersion(BUCKET, OLD_PATH, VERSION)); }
@Test public void testRestoreFileShouldCopyFileAndThenDeleteTheOriginalFile() { final ObjectMetadata fileMetadata = new ObjectMetadata(); when(amazonS3.getObjectMetadata(any())).thenReturn(fileMetadata); helper.restoreFileVersion(BUCKET, OLD_PATH, VERSION); verify(amazonS3).copyObject(argThat(hasSourceAndDestination(OLD_PATH, OLD_PATH))); final Map<String, String> pathVersionMap = new HashMap<>(); pathVersionMap.put(OLD_PATH, VERSION); verify(amazonS3).deleteObjects(argThat(hasPathsAndVersions(pathVersionMap))); }