eclipse warning fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-03-18 23:12:28 +00:00
parent 87f4e8fa63
commit b09c85ff04
8 changed files with 149 additions and 96 deletions

View File

@ -140,6 +140,8 @@ public class CalendarDemo {
FileOutputStream out = new FileOutputStream(file); FileOutputStream out = new FileOutputStream(file);
wb.write(out); wb.write(out);
out.close(); out.close();
wb.close();
} }
/** /**

View File

@ -127,6 +127,8 @@ public class CalendarDemo {
FileOutputStream out = new FileOutputStream("calendar-"+year+".xlsx"); FileOutputStream out = new FileOutputStream("calendar-"+year+".xlsx");
wb.write(out); wb.write(out);
out.close(); out.close();
wb.close();
} }
/** /**

View File

@ -17,6 +17,8 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import static org.junit.Assert.*;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.ss.usermodel.BaseTestDataFormat; import org.apache.poi.ss.usermodel.BaseTestDataFormat;
@ -26,6 +28,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
/** /**
* Tests for {@link XSSFDataFormat} * Tests for {@link XSSFDataFormat}
@ -39,7 +42,8 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
/** /**
* [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells * [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells
*/ */
public void test49928() { @Test
public void test49928() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx");
doTest49928Core(wb); doTest49928Core(wb);
@ -57,26 +61,31 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
short customFmtIdx = dataFormat.getFormat(customFmt); short customFmtIdx = dataFormat.getFormat(customFmt);
assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX); assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX);
assertEquals(customFmt, dataFormat.getFormat(customFmtIdx)); assertEquals(customFmt, dataFormat.getFormat(customFmtIdx));
wb.close();
} }
/** /**
* [Bug 58532] Handle formats that go numnum, numK, numM etc * [Bug 58532] Handle formats that go numnum, numK, numM etc
*/ */
public void test58532() { @Test
public void test58532() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("FormatKM.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("FormatKM.xlsx");
doTest58532Core(wb); doTest58532Core(wb);
wb.close();
} }
/** /**
* [Bug 58778] Built-in number formats can be overridden with XSSFDataFormat.putFormat(int id, String fmt) * [Bug 58778] Built-in number formats can be overridden with XSSFDataFormat.putFormat(int id, String fmt)
*/ */
@Test
public void test58778() throws IOException { public void test58778() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb1 = new XSSFWorkbook();
Cell cell = wb.createSheet("bug58778").createRow(0).createCell(0); Cell cell = wb1.createSheet("bug58778").createRow(0).createCell(0);
cell.setCellValue(5.25); cell.setCellValue(5.25);
CellStyle style = wb.createCellStyle(); CellStyle style = wb1.createCellStyle();
XSSFDataFormat dataFormat = wb.createDataFormat(); XSSFDataFormat dataFormat = wb1.createDataFormat();
short poundFmtIdx = 6; short poundFmtIdx = 6;
dataFormat.putFormat(poundFmtIdx, poundFmt); dataFormat.putFormat(poundFmtIdx, poundFmt);
@ -84,9 +93,9 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
cell.setCellStyle(style); cell.setCellStyle(style);
// Cell should appear as "<poundsymbol>5" // Cell should appear as "<poundsymbol>5"
wb = XSSFTestDataSamples.writeOutCloseAndReadBack(wb); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutCloseAndReadBack(wb1);
cell = wb.getSheet("bug58778").getRow(0).getCell(0); cell = wb2.getSheet("bug58778").getRow(0).getCell(0);
assertEquals(5.25, cell.getNumericCellValue()); assertEquals(5.25, cell.getNumericCellValue(), 0);
style = cell.getCellStyle(); style = cell.getCellStyle();
assertEquals(poundFmt, style.getDataFormatString()); assertEquals(poundFmt, style.getDataFormatString());
@ -94,6 +103,7 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
// manually check the file to make sure the cell is rendered as "<poundsymbol>5" // manually check the file to make sure the cell is rendered as "<poundsymbol>5"
// Verified with LibreOffice 4.2.8.2 on 2015-12-28 // Verified with LibreOffice 4.2.8.2 on 2015-12-28
wb.close(); wb2.close();
wb1.close();
} }
} }

View File

@ -17,11 +17,22 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.junit.Test;
/** /**
* Tests for {@link HSSFDataFormat} * Tests for {@link HSSFDataFormat}
@ -36,7 +47,8 @@ public final class TestHSSFDataFormat extends BaseTestDataFormat {
/** /**
* [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells * [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells
*/ */
public void test49928(){ @Test
public void test49928() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49928.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49928.xls");
doTest49928Core(wb); doTest49928Core(wb);
@ -49,20 +61,25 @@ public final class TestHSSFDataFormat extends BaseTestDataFormat {
short customFmtIdx = dataFormat.getFormat("\u00a3##.00[Yellow]"); short customFmtIdx = dataFormat.getFormat("\u00a3##.00[Yellow]");
assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX ); assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX );
assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx)); assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx));
wb.close();
} }
/** /**
* [Bug 58532] Handle formats that go numnum, numK, numM etc * [Bug 58532] Handle formats that go numnum, numK, numM etc
*/ */
public void test58532() { @Test
public void test58532() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("FormatKM.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("FormatKM.xls");
doTest58532Core(wb); doTest58532Core(wb);
wb.close();
} }
/** /**
* Bug 51378: getDataFormatString method call crashes when reading the test file * Bug 51378: getDataFormatString method call crashes when reading the test file
*/ */
public void test51378(){ @Test
public void test51378() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("12561-1.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("12561-1.xls");
for (int i = 0; i < wb.getNumberOfSheets(); i++) { for (int i = 0; i < wb.getNumberOfSheets(); i++) {
HSSFSheet sheet = wb.getSheetAt(i); HSSFSheet sheet = wb.getSheetAt(i);
@ -77,6 +94,7 @@ public final class TestHSSFDataFormat extends BaseTestDataFormat {
} }
} }
} }
wb.close();
} }
} }

View File

@ -34,6 +34,7 @@ import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
public class BaseTestSlideShowFactory { public class BaseTestSlideShowFactory {
private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@SuppressWarnings("resource")
protected static void testFactoryFromFile(String file) throws Exception { protected static void testFactoryFromFile(String file) throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// from file // from file
@ -42,6 +43,7 @@ public class BaseTestSlideShowFactory {
assertCloseDoesNotModifyFile(file, ss); assertCloseDoesNotModifyFile(file, ss);
} }
@SuppressWarnings("resource")
protected static void testFactoryFromStream(String file) throws Exception { protected static void testFactoryFromStream(String file) throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// from stream // from stream
@ -50,6 +52,7 @@ public class BaseTestSlideShowFactory {
assertCloseDoesNotModifyFile(file, ss); assertCloseDoesNotModifyFile(file, ss);
} }
@SuppressWarnings("resource")
protected static void testFactoryFromNative(String file) throws Exception { protected static void testFactoryFromNative(String file) throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// from NPOIFS // from NPOIFS
@ -70,6 +73,7 @@ public class BaseTestSlideShowFactory {
} }
} }
@SuppressWarnings("resource")
protected static void testFactoryFromProtectedFile(String protectedFile, String password) throws Exception { protected static void testFactoryFromProtectedFile(String protectedFile, String password) throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// from protected file // from protected file
@ -78,6 +82,7 @@ public class BaseTestSlideShowFactory {
assertCloseDoesNotModifyFile(protectedFile, ss); assertCloseDoesNotModifyFile(protectedFile, ss);
} }
@SuppressWarnings("resource")
protected static void testFactoryFromProtectedStream(String protectedFile, String password) throws Exception { protected static void testFactoryFromProtectedStream(String protectedFile, String password) throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// from protected stream // from protected stream
@ -86,6 +91,7 @@ public class BaseTestSlideShowFactory {
assertCloseDoesNotModifyFile(protectedFile, ss); assertCloseDoesNotModifyFile(protectedFile, ss);
} }
@SuppressWarnings("resource")
protected static void testFactoryFromProtectedNative(String protectedFile, String password) throws Exception { protected static void testFactoryFromProtectedNative(String protectedFile, String password) throws Exception {
SlideShow<?,?> ss; SlideShow<?,?> ss;
// Encryption layer is a BIFF8 binary format that can be read by NPOIFSFileSystem, // Encryption layer is a BIFF8 binary format that can be read by NPOIFSFileSystem,

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
import org.junit.Test; import org.junit.Test;
@ -47,11 +48,11 @@ public abstract class BaseTestCellComment {
public final void find() throws IOException { public final void find() throws IOException {
Workbook book = _testDataProvider.createWorkbook(); Workbook book = _testDataProvider.createWorkbook();
Sheet sheet = book.createSheet(); Sheet sheet = book.createSheet();
assertNull(sheet.getCellComment(0, 0)); assertNull(sheet.getCellComment(new CellAddress(0, 0)));
Row row = sheet.createRow(0); Row row = sheet.createRow(0);
Cell cell = row.createCell(0); Cell cell = row.createCell(0);
assertNull(sheet.getCellComment(0, 0)); assertNull(sheet.getCellComment(new CellAddress(0, 0)));
assertNull(cell.getCellComment()); assertNull(cell.getCellComment());
book.close(); book.close();
} }
@ -68,12 +69,12 @@ public abstract class BaseTestCellComment {
CreationHelper factory = wb1.getCreationHelper(); CreationHelper factory = wb1.getCreationHelper();
Sheet sheet = wb1.createSheet(); Sheet sheet = wb1.createSheet();
assertNull(sheet.getCellComment(cellRow, cellColumn)); assertNull(sheet.getCellComment(new CellAddress(cellRow, cellColumn)));
Cell cell = sheet.createRow(cellRow).createCell(cellColumn); Cell cell = sheet.createRow(cellRow).createCell(cellColumn);
cell.setCellValue(factory.createRichTextString(cellText)); cell.setCellValue(factory.createRichTextString(cellText));
assertNull(cell.getCellComment()); assertNull(cell.getCellComment());
assertNull(sheet.getCellComment(cellRow, cellColumn)); assertNull(sheet.getCellComment(new CellAddress(cellRow, cellColumn)));
Drawing patr = sheet.createDrawingPatriarch(); Drawing patr = sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor(); ClientAnchor anchor = factory.createClientAnchor();
@ -90,7 +91,7 @@ public abstract class BaseTestCellComment {
comment.setAuthor(commentAuthor); comment.setAuthor(commentAuthor);
cell.setCellComment(comment); cell.setCellComment(comment);
assertNotNull(cell.getCellComment()); assertNotNull(cell.getCellComment());
assertNotNull(sheet.getCellComment(cellRow, cellColumn)); assertNotNull(sheet.getCellComment(new CellAddress(cellRow, cellColumn)));
//verify our settings //verify our settings
assertEquals(commentAuthor, comment.getAuthor()); assertEquals(commentAuthor, comment.getAuthor());
@ -152,7 +153,7 @@ public abstract class BaseTestCellComment {
cell = row.getCell(0); cell = row.getCell(0);
comment = cell.getCellComment(); comment = cell.getCellComment();
assertNull("Cells in the first column are not commented", comment); assertNull("Cells in the first column are not commented", comment);
assertNull(sheet.getCellComment(rownum, 0)); assertNull(sheet.getCellComment(new CellAddress(rownum, 0)));
} }
for (int rownum = 0; rownum < 3; rownum++) { for (int rownum = 0; rownum < 3; rownum++) {
@ -160,7 +161,7 @@ public abstract class BaseTestCellComment {
cell = row.getCell(1); cell = row.getCell(1);
comment = cell.getCellComment(); comment = cell.getCellComment();
assertNotNull("Cells in the second column have comments", comment); assertNotNull("Cells in the second column have comments", comment);
assertNotNull("Cells in the second column have comments", sheet.getCellComment(rownum, 1)); assertNotNull("Cells in the second column have comments", sheet.getCellComment(new CellAddress(rownum, 1)));
assertEquals("Yegor Kozlov", comment.getAuthor()); assertEquals("Yegor Kozlov", comment.getAuthor());
assertFalse("cells in the second column have not empyy notes", assertFalse("cells in the second column have not empyy notes",

View File

@ -17,17 +17,20 @@
package org.apache.poi.ss.usermodel; package org.apache.poi.ss.usermodel;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.junit.Test;
/** /**
* Tests of implementation of {@link DataFormat} * Tests of implementation of {@link DataFormat}
* *
*/ */
public abstract class BaseTestDataFormat extends TestCase { public abstract class BaseTestDataFormat {
private final ITestDataProvider _testDataProvider; private final ITestDataProvider _testDataProvider;
@ -40,7 +43,8 @@ public abstract class BaseTestDataFormat extends TestCase {
assertEquals(-1, BuiltinFormats.getBuiltinFormat(customFmt)); assertEquals(-1, BuiltinFormats.getBuiltinFormat(customFmt));
} }
public final void testBuiltinFormats() { @Test
public final void testBuiltinFormats() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
DataFormat df = wb.createDataFormat(); DataFormat df = wb.createDataFormat();
@ -66,13 +70,16 @@ public abstract class BaseTestDataFormat extends TestCase {
assertTrue(customIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX); assertTrue(customIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX);
//read and verify the string representation //read and verify the string representation
assertEquals(customFmt, df.getFormat((short)customIdx)); assertEquals(customFmt, df.getFormat((short)customIdx));
wb.close();
} }
/** /**
* [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells * [Bug 49928] formatCellValue returns incorrect value for \u00a3 formatted cells
*/ */
public abstract void test49928(); @Test
protected final String poundFmt = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0"; public abstract void test49928() throws IOException;
protected final static String poundFmt = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0";
public void doTest49928Core(Workbook wb){ public void doTest49928Core(Workbook wb){
DataFormatter df = new DataFormatter(); DataFormatter df = new DataFormatter();
@ -80,7 +87,6 @@ public abstract class BaseTestDataFormat extends TestCase {
Cell cell = sheet.getRow(0).getCell(0); Cell cell = sheet.getRow(0).getCell(0);
CellStyle style = cell.getCellStyle(); CellStyle style = cell.getCellStyle();
String poundFmt = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0";
// not expected normally, id of a custom format should be greater // not expected normally, id of a custom format should be greater
// than BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX // than BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX
short poundFmtIdx = 6; short poundFmtIdx = 6;
@ -95,6 +101,7 @@ public abstract class BaseTestDataFormat extends TestCase {
assertEquals(poundFmt, dataFormat.getFormat(poundFmtIdx)); assertEquals(poundFmt, dataFormat.getFormat(poundFmtIdx));
} }
@Test
public void testReadbackFormat() throws IOException { public void testReadbackFormat() throws IOException {
readbackFormat("built-in format", "0.00"); readbackFormat("built-in format", "0.00");
readbackFormat("overridden built-in format", poundFmt); readbackFormat("overridden built-in format", poundFmt);
@ -116,7 +123,8 @@ public abstract class BaseTestDataFormat extends TestCase {
} }
} }
public abstract void test58532(); @Test
public abstract void test58532() throws IOException;
public void doTest58532Core(Workbook wb) { public void doTest58532Core(Workbook wb) {
Sheet s = wb.getSheetAt(0); Sheet s = wb.getSheetAt(0);
DataFormatter fmt = new DataFormatter(); DataFormatter fmt = new DataFormatter();
@ -161,9 +169,10 @@ public abstract class BaseTestDataFormat extends TestCase {
} }
/** /**
* Localised accountancy formats * Localized accountancy formats
*/ */
public final void test58536() { @Test
public final void test58536() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
DataFormatter formatter = new DataFormatter(); DataFormatter formatter = new DataFormatter();
DataFormat fmt = wb.createDataFormat(); DataFormat fmt = wb.createDataFormat();
@ -192,13 +201,16 @@ public abstract class BaseTestDataFormat extends TestCase {
assertEquals("-"+pound+" 12,345", formatter.formatCellValue(nve)); assertEquals("-"+pound+" 12,345", formatter.formatCellValue(nve));
// TODO Fix this to not have an extra 0 at the end // TODO Fix this to not have an extra 0 at the end
//assertEquals(pound+" - ", formatter.formatCellValue(zero)); //assertEquals(pound+" - ", formatter.formatCellValue(zero));
wb.close();
} }
/** /**
* Using a single quote (') instead of a comma (,) as * Using a single quote (') instead of a comma (,) as
* a number separator, eg 1000 -> 1'000 * a number separator, eg 1000 -> 1'000
*/ */
public final void test55265() { @Test
public final void test55265() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
DataFormatter formatter = new DataFormatter(); DataFormatter formatter = new DataFormatter();
DataFormat fmt = wb.createDataFormat(); DataFormat fmt = wb.createDataFormat();
@ -228,5 +240,6 @@ public abstract class BaseTestDataFormat extends TestCase {
assertEquals("12", formatter.formatCellValue(sml)); assertEquals("12", formatter.formatCellValue(sml));
assertEquals("1'234", formatter.formatCellValue(med)); assertEquals("1'234", formatter.formatCellValue(med));
assertEquals("12'345'678", formatter.formatCellValue(lge)); assertEquals("12'345'678", formatter.formatCellValue(lge));
wb.close();
} }
} }

View File

@ -168,16 +168,16 @@ public abstract class BaseTestSheetShiftRows {
assertEquals(3, sheet.getLastRowNum()); assertEquals(3, sheet.getLastRowNum());
// Verify comments are in the position expected // Verify comments are in the position expected
assertNotNull(sheet.getCellComment(0,0)); assertNotNull(sheet.getCellComment(new CellAddress(0,0)));
assertNull(sheet.getCellComment(1,0)); assertNull(sheet.getCellComment(new CellAddress(1,0)));
assertNotNull(sheet.getCellComment(2,0)); assertNotNull(sheet.getCellComment(new CellAddress(2,0)));
assertNotNull(sheet.getCellComment(3,0)); assertNotNull(sheet.getCellComment(new CellAddress(3,0)));
String comment1 = sheet.getCellComment(0,0).getString().getString(); String comment1 = sheet.getCellComment(new CellAddress(0,0)).getString().getString();
assertEquals(comment1,"comment top row1 (index0)\n"); assertEquals(comment1,"comment top row1 (index0)\n");
String comment3 = sheet.getCellComment(2,0).getString().getString(); String comment3 = sheet.getCellComment(new CellAddress(2,0)).getString().getString();
assertEquals(comment3,"comment top row3 (index2)\n"); assertEquals(comment3,"comment top row3 (index2)\n");
String comment4 = sheet.getCellComment(3,0).getString().getString(); String comment4 = sheet.getCellComment(new CellAddress(3,0)).getString().getString();
assertEquals(comment4,"comment top row4 (index3)\n"); assertEquals(comment4,"comment top row4 (index3)\n");
//Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb); //Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb);
@ -187,17 +187,17 @@ public abstract class BaseTestSheetShiftRows {
// Test that comments were shifted as expected // Test that comments were shifted as expected
assertEquals(4, sheet.getLastRowNum()); assertEquals(4, sheet.getLastRowNum());
assertNotNull(sheet.getCellComment(0,0)); assertNotNull(sheet.getCellComment(new CellAddress(0,0)));
assertNull(sheet.getCellComment(1,0)); assertNull(sheet.getCellComment(new CellAddress(1,0)));
assertNull(sheet.getCellComment(2,0)); assertNull(sheet.getCellComment(new CellAddress(2,0)));
assertNotNull(sheet.getCellComment(3,0)); assertNotNull(sheet.getCellComment(new CellAddress(3,0)));
assertNotNull(sheet.getCellComment(4,0)); assertNotNull(sheet.getCellComment(new CellAddress(4,0)));
String comment1_shifted = sheet.getCellComment(0,0).getString().getString(); String comment1_shifted = sheet.getCellComment(new CellAddress(0,0)).getString().getString();
assertEquals(comment1,comment1_shifted); assertEquals(comment1,comment1_shifted);
String comment3_shifted = sheet.getCellComment(3,0).getString().getString(); String comment3_shifted = sheet.getCellComment(new CellAddress(3,0)).getString().getString();
assertEquals(comment3,comment3_shifted); assertEquals(comment3,comment3_shifted);
String comment4_shifted = sheet.getCellComment(4,0).getString().getString(); String comment4_shifted = sheet.getCellComment(new CellAddress(4,0)).getString().getString();
assertEquals(comment4,comment4_shifted); assertEquals(comment4,comment4_shifted);
// Write out and read back in again // Write out and read back in again
@ -209,17 +209,17 @@ public abstract class BaseTestSheetShiftRows {
assertEquals(4, sheet.getLastRowNum()); assertEquals(4, sheet.getLastRowNum());
// Verify comments are in the position expected after the shift // Verify comments are in the position expected after the shift
assertNotNull(sheet.getCellComment(0,0)); assertNotNull(sheet.getCellComment(new CellAddress(0,0)));
assertNull(sheet.getCellComment(1,0)); assertNull(sheet.getCellComment(new CellAddress(1,0)));
assertNull(sheet.getCellComment(2,0)); assertNull(sheet.getCellComment(new CellAddress(2,0)));
assertNotNull(sheet.getCellComment(3,0)); assertNotNull(sheet.getCellComment(new CellAddress(3,0)));
assertNotNull(sheet.getCellComment(4,0)); assertNotNull(sheet.getCellComment(new CellAddress(4,0)));
comment1_shifted = sheet.getCellComment(0,0).getString().getString(); comment1_shifted = sheet.getCellComment(new CellAddress(0,0)).getString().getString();
assertEquals(comment1,comment1_shifted); assertEquals(comment1,comment1_shifted);
comment3_shifted = sheet.getCellComment(3,0).getString().getString(); comment3_shifted = sheet.getCellComment(new CellAddress(3,0)).getString().getString();
assertEquals(comment3,comment3_shifted); assertEquals(comment3,comment3_shifted);
comment4_shifted = sheet.getCellComment(4,0).getString().getString(); comment4_shifted = sheet.getCellComment(new CellAddress(4,0)).getString().getString();
assertEquals(comment4,comment4_shifted); assertEquals(comment4,comment4_shifted);
// Shifting back up again, now two rows // Shifting back up again, now two rows
@ -231,15 +231,15 @@ public abstract class BaseTestSheetShiftRows {
assertEquals(2, sheet.getLastRowNum()); assertEquals(2, sheet.getLastRowNum());
// Verify comments are in the position expected // Verify comments are in the position expected
assertNull("Had: " + (sheet.getCellComment(0,0) == null ? "null" : sheet.getCellComment(0,0).getString()), assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()),
sheet.getCellComment(0,0)); sheet.getCellComment(new CellAddress(0,0)));
assertNotNull(sheet.getCellComment(1,0)); assertNotNull(sheet.getCellComment(new CellAddress(1,0)));
assertNotNull(sheet.getCellComment(2,0)); assertNotNull(sheet.getCellComment(new CellAddress(2,0)));
} }
comment1 = sheet.getCellComment(1,0).getString().getString(); comment1 = sheet.getCellComment(new CellAddress(1,0)).getString().getString();
assertEquals(comment1,"comment top row3 (index2)\n"); assertEquals(comment1,"comment top row3 (index2)\n");
String comment2 = sheet.getCellComment(2,0).getString().getString(); String comment2 = sheet.getCellComment(new CellAddress(2,0)).getString().getString();
assertEquals(comment2,"comment top row4 (index3)\n"); assertEquals(comment2,"comment top row4 (index3)\n");
wb2.close(); wb2.close();
@ -342,6 +342,7 @@ public abstract class BaseTestSheetShiftRows {
expectedMergedRegions.add(C4_D8); expectedMergedRegions.add(C4_D8);
assertEquals(expectedMergedRegions, sheet.getMergedRegions()); assertEquals(expectedMergedRegions, sheet.getMergedRegions());
wb.close();
} }