From e9d0e9cc120ddd773292dab0d7bbe01d411908b2 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Wed, 14 Oct 2015 19:27:20 +0000 Subject: [PATCH] Update test to not depend on an existing build-directory git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1708682 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/TestHSSFWorkbook.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index fec2a230a..f40ce344f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -1200,32 +1200,36 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { @Test public void testRewriteFileBug58480() throws Exception { - final File file = new File( - "build/HSSFWorkbookTest-testWriteScenario.xls"); + final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls"); - // create new workbook - { - final Workbook workbook = new HSSFWorkbook(); - final Sheet sheet = workbook.createSheet("foo"); - final Row row = sheet.createRow(1); - row.createCell(1).setCellValue("bar"); - - writeAndCloseWorkbook(workbook, file); - } - - // edit the workbook - { - NPOIFSFileSystem fs = new NPOIFSFileSystem(file, false); - try { - DirectoryNode root = fs.getRoot(); - final Workbook workbook = new HSSFWorkbook(root, true); - final Sheet sheet = workbook.getSheet("foo"); - sheet.getRow(1).createCell(2).setCellValue("baz"); + try { + // create new workbook + { + final Workbook workbook = new HSSFWorkbook(); + final Sheet sheet = workbook.createSheet("foo"); + final Row row = sheet.createRow(1); + row.createCell(1).setCellValue("bar"); writeAndCloseWorkbook(workbook, file); - } finally { - fs.close(); } + + // edit the workbook + { + NPOIFSFileSystem fs = new NPOIFSFileSystem(file, false); + try { + DirectoryNode root = fs.getRoot(); + final Workbook workbook = new HSSFWorkbook(root, true); + final Sheet sheet = workbook.getSheet("foo"); + sheet.getRow(1).createCell(2).setCellValue("baz"); + + writeAndCloseWorkbook(workbook, file); + } finally { + fs.close(); + } + } + } finally { + assertTrue(file.exists()); + assertTrue(file.delete()); } }