]> source.dussan.org Git - poi.git/commitdiff
merge TestComment into TestHSSFComment
authorJaven O'Neal <onealj@apache.org>
Mon, 9 May 2016 03:27:32 +0000 (03:27 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 9 May 2016 03:27:32 +0000 (03:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742865 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
src/testcases/org/apache/poi/hssf/usermodel/TestComment.java [deleted file]
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java

index 933e7f6377a0ac42f1b304d321669396a8bf8d1e..bcbddf05511e3bc5ac0ee3fadca4f07728473494 100644 (file)
@@ -38,7 +38,7 @@ import org.junit.runners.Suite;
     TestFormulas.class,
     TestHSSFCell.class,
     TestHSSFClientAnchor.class,
-    TestHSSFComment.class,
+    //TestHSSFComment.class, //converted to junit4
     TestHSSFConditionalFormatting.class,
     TestHSSFDataFormat.class,
     TestHSSFDataFormatter.class,
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
deleted file mode 100644 (file)
index 2613e8c..0000000
+++ /dev/null
@@ -1,308 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hssf.usermodel;\r
-\r
-import static org.junit.Assert.assertArrayEquals;\r
-\r
-import java.io.IOException;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.ddf.EscherSpRecord;\r
-import org.apache.poi.hssf.HSSFTestDataSamples;\r
-import org.apache.poi.hssf.model.CommentShape;\r
-import org.apache.poi.hssf.model.HSSFTestModelHelper;\r
-import org.apache.poi.hssf.record.CommonObjectDataSubRecord;\r
-import org.apache.poi.hssf.record.EscherAggregate;\r
-import org.apache.poi.hssf.record.NoteRecord;\r
-import org.apache.poi.hssf.record.ObjRecord;\r
-import org.apache.poi.hssf.record.TextObjectRecord;\r
-\r
-/**\r
- * @author Evgeniy Berlog\r
- * @date 26.06.12\r
- */\r
-@SuppressWarnings("deprecation")\r
-public class TestComment extends TestCase {\r
-\r
-       public void testResultEqualsToAbstractShape() throws IOException {\r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-\r
-        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-        HSSFRow row = sh.createRow(0);\r
-        HSSFCell cell = row.createCell(0);\r
-        cell.setCellComment(comment);\r
-\r
-        CommentShape commentShape = HSSFTestModelHelper.createCommentShape(1025, comment);\r
-\r
-        assertEquals(comment.getEscherContainer().getChildRecords().size(), 5);\r
-        assertEquals(commentShape.getSpContainer().getChildRecords().size(), 5);\r
-\r
-        //sp record\r
-        byte[] expected = commentShape.getSpContainer().getChild(0).serialize();\r
-        byte[] actual = comment.getEscherContainer().getChild(0).serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        assertArrayEquals(expected, actual);\r
-\r
-        expected = commentShape.getSpContainer().getChild(2).serialize();\r
-        actual = comment.getEscherContainer().getChild(2).serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        assertArrayEquals(expected, actual);\r
-\r
-        expected = commentShape.getSpContainer().getChild(3).serialize();\r
-        actual = comment.getEscherContainer().getChild(3).serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        assertArrayEquals(expected, actual);\r
-\r
-        expected = commentShape.getSpContainer().getChild(4).serialize();\r
-        actual = comment.getEscherContainer().getChild(4).serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        assertArrayEquals(expected, actual);\r
-\r
-        ObjRecord obj = comment.getObjRecord();\r
-        ObjRecord objShape = commentShape.getObjRecord();\r
-\r
-        expected = obj.serialize();\r
-        actual = objShape.serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        //assertArrayEquals(expected, actual);\r
-\r
-        TextObjectRecord tor = comment.getTextObjectRecord();\r
-        TextObjectRecord torShape = commentShape.getTextObjectRecord();\r
-\r
-        expected = tor.serialize();\r
-        actual = torShape.serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        assertArrayEquals(expected, actual);\r
-\r
-        NoteRecord note = comment.getNoteRecord();\r
-        NoteRecord noteShape = commentShape.getNoteRecord();\r
-\r
-        expected = note.serialize();\r
-        actual = noteShape.serialize();\r
-\r
-        assertEquals(expected.length, actual.length);\r
-        assertArrayEquals(expected, actual);\r
-\r
-        wb.close();\r
-    }\r
-\r
-    public void testAddToExistingFile() throws IOException {\r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-        int idx = wb.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_PNG);\r
-\r
-        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-        comment.setColumn(5);\r
-        comment.setString(new HSSFRichTextString("comment1"));\r
-        comment = patriarch.createCellComment(new HSSFClientAnchor(0,0,100,100,(short)0,0,(short)10,10));\r
-        comment.setRow(5);\r
-        comment.setString(new HSSFRichTextString("comment2"));\r
-        comment.setBackgroundImage(idx);\r
-        assertEquals(comment.getBackgroundImageId(), idx);\r
-\r
-        assertEquals(patriarch.getChildren().size(), 2);\r
-\r
-        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
-        sh = wbBack.getSheetAt(0);\r
-        patriarch = sh.getDrawingPatriarch();\r
-\r
-        comment = (HSSFComment) patriarch.getChildren().get(1);\r
-        assertEquals(comment.getBackgroundImageId(), idx);\r
-        comment.resetBackgroundImage();\r
-        assertEquals(comment.getBackgroundImageId(), 0);\r
-\r
-        assertEquals(patriarch.getChildren().size(), 2);\r
-        comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-        comment.setString(new HSSFRichTextString("comment3"));\r
-\r
-        assertEquals(patriarch.getChildren().size(), 3);\r
-        HSSFWorkbook wbBack2 = HSSFTestDataSamples.writeOutAndReadBack(wbBack);\r
-        sh = wbBack2.getSheetAt(0);\r
-        patriarch = sh.getDrawingPatriarch();\r
-        comment = (HSSFComment) patriarch.getChildren().get(1);\r
-        assertEquals(comment.getBackgroundImageId(), 0);\r
-        assertEquals(patriarch.getChildren().size(), 3);\r
-        assertEquals(((HSSFComment) patriarch.getChildren().get(0)).getString().getString(), "comment1");\r
-        assertEquals(((HSSFComment) patriarch.getChildren().get(1)).getString().getString(), "comment2");\r
-        assertEquals(((HSSFComment) patriarch.getChildren().get(2)).getString().getString(), "comment3");\r
-        \r
-        wb.close();\r
-        wbBack.close();\r
-        wbBack2.close();\r
-    }\r
-\r
-    public void testSetGetProperties() throws IOException {\r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-\r
-        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-        comment.setString(new HSSFRichTextString("comment1"));\r
-        assertEquals(comment.getString().getString(), "comment1");\r
-\r
-        comment.setAuthor("poi");\r
-        assertEquals(comment.getAuthor(), "poi");\r
-\r
-        comment.setColumn(3);\r
-        assertEquals(comment.getColumn(), 3);\r
-\r
-        comment.setRow(4);\r
-        assertEquals(comment.getRow(), 4);\r
-\r
-        comment.setVisible(false);\r
-        assertEquals(comment.isVisible(), false);\r
-\r
-        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
-        sh = wbBack.getSheetAt(0);\r
-        patriarch = sh.getDrawingPatriarch();\r
-\r
-        comment = (HSSFComment) patriarch.getChildren().get(0);\r
-\r
-        assertEquals(comment.getString().getString(), "comment1");\r
-        assertEquals("poi", comment.getAuthor());\r
-        assertEquals(comment.getColumn(), 3);\r
-        assertEquals(comment.getRow(), 4);\r
-        assertEquals(comment.isVisible(), false);\r
-\r
-        comment.setString(new HSSFRichTextString("comment12"));\r
-        comment.setAuthor("poi2");\r
-        comment.setColumn(32);\r
-        comment.setRow(42);\r
-        comment.setVisible(true);\r
-\r
-        HSSFWorkbook wbBack2 = HSSFTestDataSamples.writeOutAndReadBack(wbBack);\r
-        sh = wbBack2.getSheetAt(0);\r
-        patriarch = sh.getDrawingPatriarch();\r
-        comment = (HSSFComment) patriarch.getChildren().get(0);\r
-\r
-        assertEquals(comment.getString().getString(), "comment12");\r
-        assertEquals("poi2", comment.getAuthor());\r
-        assertEquals(comment.getColumn(), 32);\r
-        assertEquals(comment.getRow(), 42);\r
-        assertEquals(comment.isVisible(), true);\r
-        \r
-        wb.close();\r
-        wbBack.close();\r
-        wbBack2.close();\r
-    }\r
-\r
-    public void testExistingFileWithComment(){\r
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");\r
-        HSSFSheet sheet = wb.getSheet("comments");\r
-        HSSFPatriarch drawing = sheet.getDrawingPatriarch();\r
-        assertEquals(1, drawing.getChildren().size());\r
-        HSSFComment comment = (HSSFComment) drawing.getChildren().get(0);\r
-        assertEquals(comment.getAuthor(), "evgeniy");\r
-        assertEquals(comment.getString().getString(), "evgeniy:\npoi test");\r
-        assertEquals(comment.getColumn(), 1);\r
-        assertEquals(comment.getRow(), 2);\r
-    }\r
-\r
-    public void testFindComments() throws IOException{\r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-\r
-        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-        HSSFRow row = sh.createRow(5);\r
-        HSSFCell cell = row.createCell(4);\r
-        cell.setCellComment(comment);\r
-\r
-        HSSFTestModelHelper.createCommentShape(0, comment);\r
-\r
-        assertNotNull(sh.findCellComment(5, 4));\r
-        assertNull(sh.findCellComment(5, 5));\r
-\r
-        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
-        sh = wbBack.getSheetAt(0);\r
-\r
-        assertNotNull(sh.findCellComment(5, 4));\r
-        assertNull(sh.findCellComment(5, 5));\r
-        \r
-        wb.close();\r
-        wbBack.close();\r
-    }\r
-\r
-    public void testInitState() throws IOException{\r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-\r
-        EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);\r
-        assertEquals(agg.getTailRecords().size(), 0);\r
-\r
-        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-        assertEquals(agg.getTailRecords().size(), 1);\r
-\r
-        HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());\r
-        assertNotNull(shape);\r
-\r
-        assertEquals(comment.getOptRecord().getEscherProperties().size(), 10);\r
-        \r
-        wb.close();\r
-    }\r
-\r
-    public void testShapeId() throws IOException{\r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-\r
-        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
-\r
-        comment.setShapeId(2024);\r
-\r
-        assertEquals(comment.getShapeId(), 2024);\r
-\r
-        CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) comment.getObjRecord().getSubRecords().get(0);\r
-        assertEquals(2024, cod.getObjectId());\r
-        EscherSpRecord spRecord = (EscherSpRecord) comment.getEscherContainer().getChild(0);\r
-        assertEquals(2024, spRecord.getShapeId(), 2024);\r
-        assertEquals(2024, comment.getShapeId(), 2024);\r
-        assertEquals(2024, comment.getNoteRecord().getShapeId());\r
-        \r
-        wb.close();\r
-    }\r
-    \r
-    public void testAttemptToSave2CommentsWithSameCoordinates(){\r
-        Object err = null;\r
-        \r
-        HSSFWorkbook wb = new HSSFWorkbook();\r
-        HSSFSheet sh = wb.createSheet();\r
-        HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
-        patriarch.createCellComment(new HSSFClientAnchor());\r
-        patriarch.createCellComment(new HSSFClientAnchor());\r
-        \r
-        try{\r
-            HSSFTestDataSamples.writeOutAndReadBack(wb);\r
-        } catch (IllegalStateException e){\r
-            err = 1;\r
-            assertEquals(e.getMessage(), "found multiple cell comments for cell $A$1");\r
-        }\r
-        assertNotNull(err);\r
-    }\r
-}\r
index 32ca5b598b6449e4b74abf0115445feb67b24ee1..f437b0207ba3b95d5a1e1e72d43495f1cc709ec0 100644 (file)
 ==================================================================== */
 package org.apache.poi.hssf.usermodel;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
+import java.io.IOException;
+
+import org.apache.poi.ddf.EscherSpRecord;
 import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.CommentShape;
+import org.apache.poi.hssf.model.HSSFTestModelHelper;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
+import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.NoteRecord;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
 import org.apache.poi.ss.usermodel.BaseTestCellComment;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.ClientAnchor;
@@ -187,5 +199,279 @@ public final class TestHSSFComment extends BaseTestCellComment {
         cell.setCellComment(comment);
         
         return comment;
-    }    
+    }
+    
+    @Test
+    public void resultEqualsToAbstractShape() throws IOException {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+        HSSFRow row = sh.createRow(0);
+        HSSFCell cell = row.createCell(0);
+        cell.setCellComment(comment);
+
+        CommentShape commentShape = HSSFTestModelHelper.createCommentShape(1025, comment);
+
+        assertEquals(comment.getEscherContainer().getChildRecords().size(), 5);
+        assertEquals(commentShape.getSpContainer().getChildRecords().size(), 5);
+
+        //sp record
+        byte[] expected = commentShape.getSpContainer().getChild(0).serialize();
+        byte[] actual = comment.getEscherContainer().getChild(0).serialize();
+
+        assertEquals(expected.length, actual.length);
+        assertArrayEquals(expected, actual);
+
+        expected = commentShape.getSpContainer().getChild(2).serialize();
+        actual = comment.getEscherContainer().getChild(2).serialize();
+
+        assertEquals(expected.length, actual.length);
+        assertArrayEquals(expected, actual);
+
+        expected = commentShape.getSpContainer().getChild(3).serialize();
+        actual = comment.getEscherContainer().getChild(3).serialize();
+
+        assertEquals(expected.length, actual.length);
+        assertArrayEquals(expected, actual);
+
+        expected = commentShape.getSpContainer().getChild(4).serialize();
+        actual = comment.getEscherContainer().getChild(4).serialize();
+
+        assertEquals(expected.length, actual.length);
+        assertArrayEquals(expected, actual);
+
+        ObjRecord obj = comment.getObjRecord();
+        ObjRecord objShape = commentShape.getObjRecord();
+
+        expected = obj.serialize();
+        actual = objShape.serialize();
+
+        assertEquals(expected.length, actual.length);
+        //assertArrayEquals(expected, actual);
+
+        TextObjectRecord tor = comment.getTextObjectRecord();
+        TextObjectRecord torShape = commentShape.getTextObjectRecord();
+
+        expected = tor.serialize();
+        actual = torShape.serialize();
+
+        assertEquals(expected.length, actual.length);
+        assertArrayEquals(expected, actual);
+
+        NoteRecord note = comment.getNoteRecord();
+        NoteRecord noteShape = commentShape.getNoteRecord();
+
+        expected = note.serialize();
+        actual = noteShape.serialize();
+
+        assertEquals(expected.length, actual.length);
+        assertArrayEquals(expected, actual);
+
+        wb.close();
+    }
+
+    @Test
+    public void addToExistingFile() throws IOException {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+        int idx = wb.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_PNG);
+
+        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+        comment.setColumn(5);
+        comment.setString(new HSSFRichTextString("comment1"));
+        comment = patriarch.createCellComment(new HSSFClientAnchor(0,0,100,100,(short)0,0,(short)10,10));
+        comment.setRow(5);
+        comment.setString(new HSSFRichTextString("comment2"));
+        comment.setBackgroundImage(idx);
+        assertEquals(comment.getBackgroundImageId(), idx);
+
+        assertEquals(patriarch.getChildren().size(), 2);
+
+        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        sh = wbBack.getSheetAt(0);
+        patriarch = sh.getDrawingPatriarch();
+
+        comment = (HSSFComment) patriarch.getChildren().get(1);
+        assertEquals(comment.getBackgroundImageId(), idx);
+        comment.resetBackgroundImage();
+        assertEquals(comment.getBackgroundImageId(), 0);
+
+        assertEquals(patriarch.getChildren().size(), 2);
+        comment = patriarch.createCellComment(new HSSFClientAnchor());
+        comment.setString(new HSSFRichTextString("comment3"));
+
+        assertEquals(patriarch.getChildren().size(), 3);
+        HSSFWorkbook wbBack2 = HSSFTestDataSamples.writeOutAndReadBack(wbBack);
+        sh = wbBack2.getSheetAt(0);
+        patriarch = sh.getDrawingPatriarch();
+        comment = (HSSFComment) patriarch.getChildren().get(1);
+        assertEquals(comment.getBackgroundImageId(), 0);
+        assertEquals(patriarch.getChildren().size(), 3);
+        assertEquals(((HSSFComment) patriarch.getChildren().get(0)).getString().getString(), "comment1");
+        assertEquals(((HSSFComment) patriarch.getChildren().get(1)).getString().getString(), "comment2");
+        assertEquals(((HSSFComment) patriarch.getChildren().get(2)).getString().getString(), "comment3");
+        
+        wb.close();
+        wbBack.close();
+        wbBack2.close();
+    }
+
+    @Test
+    public void setGetProperties() throws IOException {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+        comment.setString(new HSSFRichTextString("comment1"));
+        assertEquals(comment.getString().getString(), "comment1");
+
+        comment.setAuthor("poi");
+        assertEquals(comment.getAuthor(), "poi");
+
+        comment.setColumn(3);
+        assertEquals(comment.getColumn(), 3);
+
+        comment.setRow(4);
+        assertEquals(comment.getRow(), 4);
+
+        comment.setVisible(false);
+        assertEquals(comment.isVisible(), false);
+
+        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        sh = wbBack.getSheetAt(0);
+        patriarch = sh.getDrawingPatriarch();
+
+        comment = (HSSFComment) patriarch.getChildren().get(0);
+
+        assertEquals(comment.getString().getString(), "comment1");
+        assertEquals("poi", comment.getAuthor());
+        assertEquals(comment.getColumn(), 3);
+        assertEquals(comment.getRow(), 4);
+        assertEquals(comment.isVisible(), false);
+
+        comment.setString(new HSSFRichTextString("comment12"));
+        comment.setAuthor("poi2");
+        comment.setColumn(32);
+        comment.setRow(42);
+        comment.setVisible(true);
+
+        HSSFWorkbook wbBack2 = HSSFTestDataSamples.writeOutAndReadBack(wbBack);
+        sh = wbBack2.getSheetAt(0);
+        patriarch = sh.getDrawingPatriarch();
+        comment = (HSSFComment) patriarch.getChildren().get(0);
+
+        assertEquals(comment.getString().getString(), "comment12");
+        assertEquals("poi2", comment.getAuthor());
+        assertEquals(comment.getColumn(), 32);
+        assertEquals(comment.getRow(), 42);
+        assertEquals(comment.isVisible(), true);
+        
+        wb.close();
+        wbBack.close();
+        wbBack2.close();
+    }
+
+    @Test
+    public void existingFileWithComment(){
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
+        HSSFSheet sheet = wb.getSheet("comments");
+        HSSFPatriarch drawing = sheet.getDrawingPatriarch();
+        assertEquals(1, drawing.getChildren().size());
+        HSSFComment comment = (HSSFComment) drawing.getChildren().get(0);
+        assertEquals(comment.getAuthor(), "evgeniy");
+        assertEquals(comment.getString().getString(), "evgeniy:\npoi test");
+        assertEquals(comment.getColumn(), 1);
+        assertEquals(comment.getRow(), 2);
+    }
+
+    @Test
+    public void findComments() throws IOException{
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+        HSSFRow row = sh.createRow(5);
+        HSSFCell cell = row.createCell(4);
+        cell.setCellComment(comment);
+
+        HSSFTestModelHelper.createCommentShape(0, comment);
+
+        assertNotNull(sh.findCellComment(5, 4));
+        assertNull(sh.findCellComment(5, 5));
+
+        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        sh = wbBack.getSheetAt(0);
+
+        assertNotNull(sh.findCellComment(5, 4));
+        assertNull(sh.findCellComment(5, 5));
+        
+        wb.close();
+        wbBack.close();
+    }
+
+    @Test
+    public void initState() throws IOException{
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+        EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
+        assertEquals(agg.getTailRecords().size(), 0);
+
+        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+        assertEquals(agg.getTailRecords().size(), 1);
+
+        HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());
+        assertNotNull(shape);
+
+        assertEquals(comment.getOptRecord().getEscherProperties().size(), 10);
+        
+        wb.close();
+    }
+
+    @Test
+    public void shapeId() throws IOException{
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+        HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+
+        comment.setShapeId(2024);
+
+        assertEquals(comment.getShapeId(), 2024);
+
+        CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) comment.getObjRecord().getSubRecords().get(0);
+        assertEquals(2024, cod.getObjectId());
+        EscherSpRecord spRecord = (EscherSpRecord) comment.getEscherContainer().getChild(0);
+        assertEquals(2024, spRecord.getShapeId(), 2024);
+        assertEquals(2024, comment.getShapeId(), 2024);
+        assertEquals(2024, comment.getNoteRecord().getShapeId());
+        
+        wb.close();
+    }
+    
+    @Test
+    public void attemptToSave2CommentsWithSameCoordinates(){
+        Object err = null;
+        
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sh = wb.createSheet();
+        HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+        patriarch.createCellComment(new HSSFClientAnchor());
+        patriarch.createCellComment(new HSSFClientAnchor());
+        
+        try{
+            HSSFTestDataSamples.writeOutAndReadBack(wb);
+        } catch (IllegalStateException e){
+            err = 1;
+            assertEquals(e.getMessage(), "found multiple cell comments for cell $A$1");
+        }
+        assertNotNull(err);
+    }
 }