Close temp-file in test to not leak file-handles and fail deleting the file on Windows

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-10-15 06:54:26 +00:00
parent 37116e84e5
commit 90ef824079
1 changed files with 11 additions and 8 deletions

View File

@ -133,10 +133,15 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
assertEquals(1, tempFiles.size());
File tempFile = tempFiles.get(0);
assertTrue("tempFile exists?", tempFile.exists());
byte[] data = IOUtils.toByteArray(new FileInputStream(tempFile));
String text = new String(data, UTF_8);
assertFalse(text.contains(sheetName));
assertFalse(text.contains(cellValue));
InputStream stream = new FileInputStream(tempFile);
try {
byte[] data = IOUtils.toByteArray(stream);
String text = new String(data, UTF_8);
assertFalse(text.contains(sheetName));
assertFalse(text.contains(cellValue));
} finally {
stream.close();
}
workbook.dispose();
assertFalse("tempFile deleted after dispose?", tempFile.exists());
}
@ -173,7 +178,6 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
}
}
static class SheetDataWriterWithDecorator extends SheetDataWriter {
final static CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
SecretKeySpec skeySpec;
@ -206,7 +210,6 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
Cipher ciDec = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc, ivBytes, Cipher.DECRYPT_MODE, "PKCS5Padding");
return new CipherInputStream(fis, ciDec);
}
}
// a class to save and read an AES-encrypted workbook
@ -237,8 +240,8 @@ public final class TestSXSSFWorkbookWithCustomZipEntrySource {
}
void dispose() {
tempFile.delete();
assertTrue("Could not delete tempfile " + tempFile + ": " + tempFile.exists(),
!tempFile.exists() || tempFile.delete());
}
}
}