aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2017-11-04 13:45:04 +0000
committerDominik Stadler <centic@apache.org>2017-11-04 13:45:04 +0000
commitb7f7ff71b459d72e01ac3c3d6af4b2c6e7ced1f5 (patch)
treec48856637f13a5e82a4ee018521d5b1dc13436c6 /src/testcases
parent3e1ee0afebe4c3d53ba5486b873a1b52878bbf9a (diff)
downloadpoi-b7f7ff71b459d72e01ac3c3d6af4b2c6e7ced1f5.tar.gz
poi-b7f7ff71b459d72e01ac3c3d6af4b2c6e7ced1f5.zip
Fix some IntelliJ and JavaDoc warnings and avoid code-duplication and duplicated test-methods
Adjust tests slighlty, close resources git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814289 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java11
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java110
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java6
3 files changed, 40 insertions, 87 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index dab7c28299..6bd3d73281 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -98,7 +98,6 @@ public final class TestHSSFSheet extends BaseTestSheet {
wb.close();
}
-
@Test
public void getSetMargin() throws IOException {
baseTestGetSetMargin(new double[]{0.75, 0.75, 1.0, 1.0, 0.3, 0.3});
@@ -156,7 +155,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
/**
- * Test WSBboolRecord fields get set in the user model.
+ * Test WSBoolRecord fields get set in the user model.
*/
@Test
public void wsBool() throws IOException {
@@ -166,6 +165,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
(WSBoolRecord) s.getSheet().findFirstRecordBySid(WSBoolRecord.sid);
// Check defaults
+ assertNotNull(record);
assertTrue(record.getAlternateExpression());
assertTrue(record.getAlternateFormula());
assertFalse(record.getAutobreaks());
@@ -518,7 +518,9 @@ public final class TestHSSFSheet extends BaseTestSheet {
sheet.setZoom(75);
assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0);
SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid);
- assertEquals(75, 100*sclRecord.getNumerator()/sclRecord.getDenominator());
+ assertNotNull(sclRecord);
+ short numerator = sclRecord.getNumerator();
+ assertEquals(75, 100* numerator /sclRecord.getDenominator());
int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
@@ -942,6 +944,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
// Details checks
HSSFCellStyle bs = wbSimple.getSheetAt(0).getColumnStyle(1);
+ assertNotNull(bs);
assertEquals(62, bs.getIndex());
assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", bs.getDataFormatString());
assertEquals("Calibri", bs.getFont(wbSimple).getFontName());
@@ -952,6 +955,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
HSSFCellStyle cs = wbComplex.getSheetAt(0).getColumnStyle(1);
+ assertNotNull(cs);
assertEquals(62, cs.getIndex());
assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", cs.getDataFormatString());
assertEquals("Arial", cs.getFont(wbComplex).getFontName());
@@ -1023,6 +1027,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
sh = wb2.getSheetAt(0);
ish = sh.getSheet();
ObjRecord objRecord = (ObjRecord)ish.findFirstRecordBySid(ObjRecord.sid);
+ assertNotNull(objRecord);
List<SubRecord> subRecords = objRecord.getSubRecords();
assertEquals(3, subRecords.size());
assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord );
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
index 33dfb308d4..70bb3b8877 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
@@ -17,11 +17,6 @@
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -30,13 +25,12 @@ import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
-import org.apache.poi.ss.usermodel.CellType;
-import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.Test;
+import static org.junit.Assert.*;
+
/**
* Class to test Workbook functionality
*/
@@ -71,19 +65,8 @@ public final class TestWorkbook {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
+ populateSheet(s);
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
-
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
sanityChecker.checkHSSFWorkbook(wb1);
@@ -112,18 +95,8 @@ public final class TestWorkbook {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
+ populateSheet(s);
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
for (int rownum = 0; rownum < 25; rownum++) {
HSSFRow r = s.getRow(rownum);
s.removeRow(r);
@@ -411,18 +384,8 @@ public final class TestWorkbook {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
+ populateSheet(s);
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
s.addMergedRegion(new CellRangeAddress(0, 10, 0, 10));
s.addMergedRegion(new CellRangeAddress(30, 40, 5, 15));
sanityChecker.checkHSSFWorkbook(wb1);
@@ -434,11 +397,26 @@ public final class TestWorkbook {
confirmRegion(new CellRangeAddress(0, 10, 0, 10), r1);
confirmRegion(new CellRangeAddress(30, 40,5, 15), r2);
-
+
wb2.close();
wb1.close();
}
+ private void populateSheet(Sheet s) {
+ for (int rownum = 0; rownum < 100; rownum++) {
+ Row r = s.createRow(rownum);
+
+ for (int cellnum = 0; cellnum < 50; cellnum += 2) {
+ Cell c = r.createCell(cellnum);
+ c.setCellValue(rownum * 10000 + cellnum
+ + ((( double ) rownum / 1000)
+ + (( double ) cellnum / 10000)));
+ c = r.createCell(cellnum + 1);
+ c.setCellValue(new HSSFRichTextString("TEST"));
+ }
+ }
+ }
+
private static void confirmRegion(CellRangeAddress ra, CellRangeAddress rb) {
assertEquals(ra.getFirstRow(), rb.getFirstRow());
assertEquals(ra.getLastRow(), rb.getLastRow());
@@ -448,7 +426,6 @@ public final class TestWorkbook {
/**
* Test the backup field gets set as expected.
- * @throws IOException
*/
@Test
public void testBackupRecord() throws IOException {
@@ -490,7 +467,6 @@ public final class TestWorkbook {
* This tests is for bug [ #506658 ] Repeating output.
*
* We need to make sure only one LabelSSTRecord is produced.
- * @throws IOException
*/
@Test
public void testRepeatingBug() throws IOException {
@@ -501,6 +477,7 @@ public final class TestWorkbook {
cell.setCellValue(new HSSFRichTextString("Class"));
cell = row.createCell(2);
+ assertNotNull(cell);
RecordCounter rc = new RecordCounter();
sheet.getSheet().visitContainedRecords(rc, 0);
@@ -584,12 +561,16 @@ public final class TestWorkbook {
try {
sheet.setRepeatingColumns(cra);
fail("invalid start index is ignored");
- } catch (IllegalArgumentException e) {}
+ } catch (IllegalArgumentException e) {
+ // expected here
+ }
try {
sheet.setRepeatingRows(cra);
fail("invalid start index is ignored");
- } catch (IllegalArgumentException e) {}
+ } catch (IllegalArgumentException e) {
+ // expected here
+ }
sheet.setRepeatingColumns(null);
sheet.setRepeatingRows(null);
@@ -600,39 +581,6 @@ public final class TestWorkbook {
}
@Test
- public void testAddMergedRegionWithRegion() throws IOException {
- HSSFWorkbook wb1 = new HSSFWorkbook();
- HSSFSheet s = wb1.createSheet();
-
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
-
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
- s.addMergedRegion(new CellRangeAddress(0, 10, 0, 10));
- s.addMergedRegion(new CellRangeAddress(30, 40, 5, 15));
- sanityChecker.checkHSSFWorkbook(wb1);
- HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
-
- s = wb2.getSheetAt(0);
- CellRangeAddress r1 = s.getMergedRegion(0);
- CellRangeAddress r2 = s.getMergedRegion(1);
-
- confirmRegion(new CellRangeAddress(0, 10, 0, 10), r1);
- confirmRegion(new CellRangeAddress(30, 40,5, 15), r2);
-
- wb2.close();
- wb1.close();
- }
-
- @Test
public void testBug58085RemoveSheetWithNames() throws Exception {
HSSFWorkbook wb1 = new HSSFWorkbook();
Sheet sheet1 = wb1.createSheet("sheet1");
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
index 1c15804fb7..08414cd5c8 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
@@ -18,7 +18,6 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.common.usermodel.HyperlinkType;
-import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellAddress;
@@ -37,8 +36,9 @@ import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
/**
- * Common superclass for testing {@link HSSFCell}, org.apache.poi.xssf.usermodel.XSSFCell and
- * org.apache.poi.xssf.streaming.SXSSFCell
+ * Common superclass for testing {@link org.apache.poi.hssf.usermodel.HSSFCell},
+ * {@link org.apache.poi.xssf.usermodel.XSSFCell} and
+ * {@link org.apache.poi.xssf.streaming.SXSSFCell}
*/
public abstract class BaseTestSheet {
private static final int ROW_COUNT = 40000;