CryptoContainer { @WorkerThread public static CryptoContainer encrypt(ImmutableList<File> dataFiles, ImmutableList<Certificate> recipients, File file) throws CryptoException { try { CDOCBuilder builder = CDOCBuilder.defaultVersion(); for (File dataFile : dataFiles) { builder.withDataFile(dataFile); } for (Certificate recipient : recipients) { builder.withRecipient(recipient.x509Certificate()); } builder.buildToFile(file); return open(file); } catch (DataFileMissingException e) { throw new DataFilesEmptyException(); } catch (RecipientMissingException e) { throw new RecipientsEmptyException(); } catch (Exception e) { throw new CryptoException("Encryption failed", e); } }  abstract File file(); abstract ImmutableList<File> dataFiles(); abstract ImmutableList<Certificate> recipients(); abstract boolean decrypted(); CryptoContainer decrypt(DecryptToken decryptToken, Certificate authCertificate,
                                   String pin1, File dataFilesDirectory); @WorkerThread static CryptoContainer open(File file); @WorkerThread static CryptoContainer encrypt(ImmutableList<File> dataFiles,
                                          ImmutableList<Certificate> recipients, File file); static boolean isContainerFileName(String fileName); static String createContainerFileName(String fileName);  }
@Test public void encrypt_recipientsEmpty() throws Exception { exception.expect(RecipientsEmptyException.class); CryptoContainer.encrypt( ImmutableList.of(resource("example1.txt")), ImmutableList.of(), temporaryFolder.newFile("test1.cdoc")); }
@Test public void encrypt_dataFilesEmpty() throws Exception { exception.expect(DataFilesEmptyException.class); CryptoContainer.encrypt( ImmutableList.of(), ImmutableList.of(certificate("37101010021_rsa.cer")), temporaryFolder.newFile("test1.cdoc")); }