VaultDocumentStorage { public void persistDocument(final DocumentEntity documentEntity, final byte[] documentContents) { final VaultLocation vaultLocation = vaultLocationFactory.getLocation(documentEntity); persistDocument(documentEntity, documentContents, vaultLocation); }  void persistDocument(final DocumentEntity documentEntity, final byte[] documentContents); void persistDocument(final DocumentEntity documentEntity, final byte[] documentContents,
            final VaultLocation vaultLocation);  }
@Test void testPersistDocumentUncompressed() { final DocumentEntity documentEntity = DocumentEntity.builder() .compression(DocumentCompression.NONE) .build(); final VaultLocation vaultLocation = mock(VaultLocation.class); underTest.persistDocument(documentEntity, CONTENT, vaultLocation); verify(vaultLocation).upload(CONTENT); verify(compressionServiceProvider, never()).getCompressionService(any()); }
@Test void testPersistDocumentCompressed() { final DocumentEntity documentEntity = DocumentEntity.builder() .compression(DocumentCompression.GZIP) .build(); final CompressionService compressionService = mock(CompressionService.class); when(compressionServiceProvider.getCompressionService(DocumentCompression.GZIP)) .thenReturn(compressionService); when(compressionService.compress(CONTENT)) .thenReturn(COMPRESSED_CONTENT); final VaultLocation vaultLocation = mock(VaultLocation.class); underTest.persistDocument(documentEntity, CONTENT, vaultLocation); verify(vaultLocation, never()).upload(CONTENT); verify(vaultLocation).upload(COMPRESSED_CONTENT); verify(compressionServiceProvider).getCompressionService(DocumentCompression.GZIP); verify(compressionService).compress(CONTENT); }
@Test void testPersistDocumentWhenVaultLocationIsNotYetKnow() { final DocumentEntity documentEntity = DocumentEntity.builder() .compression(DocumentCompression.NONE) .build(); final VaultLocation vaultLocation = mock(VaultLocation.class); when(vaultLocationFactory.getLocation(documentEntity)) .thenReturn(vaultLocation); underTest.persistDocument(documentEntity, CONTENT); verify(vaultLocation).upload(CONTENT); }