@Test
void testClean() throws IOException {

    final String repoDir = FileUtil.getCanonicalPath(Files.createTempDirectory("stroom").resolve("repo2"));
    StroomZipRepository stroomZipRepository = new StroomZipRepository(repoDir, null, false, 10000, 0, false);
    StroomZipOutputStreamImpl out1;
    try (final StroomZipOutputStreamImpl out = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream()) {
        StroomZipOutputStreamUtil.addSimpleEntry(out, new StroomZipEntry(null, "file", StroomZipFileType.Data),
                "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET));
        assertThat(Files.isRegularFile(out.getFile())).isFalse();
        out1 = out;
    }
    assertThat(Files.isRegularFile(out1.getFile())).isTrue();
    final StroomZipOutputStreamImpl out2 = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream();
    StroomZipOutputStreamUtil.addSimpleEntry(out2, new StroomZipEntry(null, "file", StroomZipFileType.Data),
            "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET));
    assertThat(Files.isRegularFile(out2.getFile())).isFalse();
    assertThat(Files.isRegularFile(out2.getLockFile())).isTrue();
    // Leave open
    stroomZipRepository = new StroomZipRepository(repoDir, null, false, 1000, 0, false);
    assertThat(Files.isRegularFile(out1.getFile())).as("Expecting pucker file to be left").isTrue();
    assertThat(Files.isRegularFile(out2.getLockFile())).as("Expecting lock file to not be deleted").isTrue();
    final StroomZipOutputStreamImpl out3 = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream();
    StroomZipOutputStreamUtil.addSimpleEntry(out3, new StroomZipEntry(null, "file", StroomZipFileType.Data),
            "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET));
    final Path lockFile3 = out3.getLockFile();
    assertThat(Files.isRegularFile(lockFile3)).isTrue();
    stroomZipRepository.clean(true);
    assertThat(Files.isRegularFile(lockFile3)).isTrue();
    try {
        Files.setLastModifiedTime(lockFile3, FileTime.fromMillis(System.currentTimeMillis() - (48 * 60 * 60 * 1000)));
    } catch (final RuntimeException e) {
        fail("Unable to set LastModified");
    }
    stroomZipRepository.clean(true);
    assertThat(Files.isRegularFile(lockFile3)).as("Expecting old lock file to be deleted").isFalse();
}