@Test
public void testClean() throws IOException {

    final String repoDir = TestUtil.getCurrentTestPath().toAbsolutePath().toString() + File.separator + "repo2";
    StroomZipRepository stroomZipRepository = new StroomZipRepository(repoDir, null, false, 10000);
    final StroomZipOutputStreamImpl out1 = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream();
    StroomZipOutputStreamUtil.addSimpleEntry(out1, new StroomZipEntry(null, "file", StroomZipFileType.Data),
            "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET));
    Assert.assertFalse(Files.isRegularFile(out1.getFile()));
    out1.close();
    Assert.assertTrue(Files.isRegularFile(out1.getFile()));
    final StroomZipOutputStreamImpl out2 = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream();
    StroomZipOutputStreamUtil.addSimpleEntry(out2, new StroomZipEntry(null, "file", StroomZipFileType.Data),
            "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET));
    Assert.assertFalse(Files.isRegularFile(out2.getFile()));
    Assert.assertTrue(Files.isRegularFile(out2.getLockFile()));
    // Leave open
    stroomZipRepository = new StroomZipRepository(repoDir, null, false, 1000);
    Assert.assertTrue("Expecting pucker file to be left", Files.isRegularFile(out1.getFile()));
    Assert.assertTrue("Expecting lock file to not be deleted", Files.isRegularFile(out2.getLockFile()));
    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();
    Assert.assertTrue(Files.isRegularFile(lockFile3));
    stroomZipRepository.clean();
    Assert.assertTrue(Files.isRegularFile(lockFile3));
    try {
        Files.setLastModifiedTime(lockFile3, FileTime.fromMillis(System.currentTimeMillis() - (48 * 60 * 60 * 1000)));
    } catch (final Exception e) {
        Assert.fail("Unable to set LastModified");
    }
    stroomZipRepository.clean();
    Assert.assertFalse("Expecting old lock file to be deleted", Files.isRegularFile(lockFile3));
}