From fe04abd31d68ad0af3bce36685bda82bc6bfcaa1 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 9 May 2016 04:29:17 +0000 Subject: [PATCH] fix BasteTestCellComment#attemptToSave2CommentsWithSameCoordinates to work with different behaviors of HSSFWorkbook and XSSFWorkbook git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742871 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/usermodel/BaseTestCellComment.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java index e7db17c47..844c95f82 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java @@ -357,19 +357,25 @@ public abstract class BaseTestCellComment { } @Test - public void attemptToSave2CommentsWithSameCoordinates(){ + public void attemptToSave2CommentsWithSameCoordinates() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); Sheet sh = wb.createSheet(); CreationHelper factory = wb.getCreationHelper(); Drawing patriarch = sh.createDrawingPatriarch(); patriarch.createCellComment(factory.createClientAnchor()); - patriarch.createCellComment(factory.createClientAnchor()); - try{ + try { + patriarch.createCellComment(factory.createClientAnchor()); _testDataProvider.writeOutAndReadBack(wb); - fail("Expected IllegalStateException(found multiple cell comments for cell $A$1"); - } catch (IllegalStateException e){ + fail("Should not be able to create a corrupted workbook with multiple cell comments in one cell"); + } catch (IllegalStateException e) { + // HSSFWorkbooks fail when writing out workbook assertEquals("found multiple cell comments for cell $A$1", e.getMessage()); + } catch (IllegalArgumentException e) { + // XSSFWorkbooks fail when creating and setting the cell address of the comment + assertEquals("Multiple cell comments in one cell are not allowed, cell: A1", e.getMessage()); + } finally { + wb.close(); } } }