remove unnecessary @SuppressWarnings("deprecation") warnings (because of old xml schemas)

close resources

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722482 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-01-01 02:22:31 +00:00
parent 8ed770dfe3
commit 318f0b35b8
7 changed files with 221 additions and 110 deletions

View File

@ -16,55 +16,64 @@
==================================================================== */
package org.apache.poi.xslf;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIXMLProperties.CoreProperties;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.xmlbeans.XmlException;
import org.junit.Before;
import org.junit.Test;
import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
public class TestXSLFSlideShow extends TestCase {
public class TestXSLFSlideShow {
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
private OPCPackage pack;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
}
@Test
public void testContainsMainContentType() throws Exception {
boolean found = false;
for(PackagePart part : pack.getParts()) {
if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
found = true;
}
//System.out.println(part);
}
assertTrue(found);
}
public void testOpen() throws Exception {
XSLFSlideShow xml;
// With the finalised uri, should be fine
xml = new XSLFSlideShow(pack);
@Test
public void testOpen() throws IOException, OpenXML4JException, XmlException {
// With the finalized uri, should be fine
XSLFSlideShow xml = new XSLFSlideShow(pack);
// Check the core
assertNotNull(xml.getPresentation());
// Check it has some slides
assertTrue(
xml.getSlideReferences().sizeOfSldIdArray() > 0
);
assertTrue(
xml.getSlideMasterReferences().sizeOfSldMasterIdArray() > 0
);
assertNotEquals(0, xml.getSlideReferences().sizeOfSldIdArray());
assertNotEquals(0, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
xml.close();
}
@SuppressWarnings("deprecation")
public void testSlideBasics() throws Exception {
@Test
public void testSlideBasics() throws IOException, OpenXML4JException, XmlException {
XSLFSlideShow xml = new XSLFSlideShow(pack);
// Should have 1 master
@ -95,19 +104,26 @@ public class TestXSLFSlideShow extends TestCase {
assertEquals(2147483648l, masters[0].getId());
assertEquals("rId1", masters[0].getId2());
assertNotNull(xml.getSlideMaster(masters[0]));
xml.close();
}
public void testMetadataBasics() throws Exception {
@Test
public void testMetadataBasics() throws IOException, OpenXML4JException, XmlException {
XSLFSlideShow xml = new XSLFSlideShow(pack);
assertNotNull(xml.getProperties().getCoreProperties());
assertNotNull(xml.getProperties().getExtendedProperties());
assertEquals("Microsoft Office PowerPoint", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
CTProperties props = xml.getProperties().getExtendedProperties().getUnderlyingProperties();
assertEquals("Microsoft Office PowerPoint", props.getApplication());
assertEquals(0, props.getCharacters());
assertEquals(0, props.getLines());
assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
CoreProperties cprops = xml.getProperties().getCoreProperties();
assertNull(cprops.getTitle());
assertNull(cprops.getUnderlyingProperties().getSubjectProperty().getValue());
xml.close();
}
}

View File

@ -16,14 +16,21 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.junit.Before;
import org.junit.Test;
import org.openxmlformats.schemas.presentationml.x2006.main.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
public class TestXMLSlideShow {
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
@ -47,21 +54,20 @@ public class TestXMLSlideShow {
@Test
public void testOpen() throws Exception {
XMLSlideShow xml;
// With the finalised uri, should be fine
xml = new XMLSlideShow(pack);
XMLSlideShow xml = new XMLSlideShow(pack);
// Check the core
assertNotNull(xml.getCTPresentation());
// Check it has some slides
assertFalse(xml.getSlides().isEmpty());
assertFalse(xml.getSlideMasters().isEmpty());
xml.close();
}
@Test
@SuppressWarnings("deprecation")
public void testSlideBasics() throws Exception {
public void testSlideBasics() throws IOException {
XMLSlideShow xml = new XMLSlideShow(pack);
// Should have 1 master
@ -99,10 +105,12 @@ public class TestXMLSlideShow {
assertNotNull(notesMaster);
assertNotNull(xml.getNotesMaster());
xml.close();
}
@Test
public void testMetadataBasics() throws Exception {
public void testMetadataBasics() throws IOException {
XMLSlideShow xml = new XMLSlideShow(pack);
assertNotNull(xml.getProperties().getCoreProperties());
@ -114,6 +122,8 @@ public class TestXMLSlideShow {
assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
xml.close();
}
@Test
@ -128,8 +138,7 @@ public class TestXMLSlideShow {
}
// Try another with comments
OPCPackage packComments = OPCPackage.open(slTests.openResourceAsStream("45545_Comment.pptx"));
XMLSlideShow xmlComments = new XMLSlideShow(packComments);
XMLSlideShow xmlComments = new XMLSlideShow(slTests.openResourceAsStream("45545_Comment.pptx"));
// Has one author
assertNotNull(xmlComments.getCommentAuthors());
@ -155,5 +164,8 @@ public class TestXMLSlideShow {
assertEquals(null, slide.getComments());
}
}
xmlComments.close();
xml.close();
}
}

View File

@ -2539,7 +2539,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
runTest56574(true);
}
@SuppressWarnings("deprecation")
private void runTest56574(boolean createRow) throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56574.xlsx");

View File

@ -17,11 +17,15 @@
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
@ -36,7 +40,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
* </em>
*
*/
public class TestXSSFColGrouping extends TestCase {
public class TestXSSFColGrouping {
private static final POILogger logger = POILogFactory.getLogger(TestXSSFColGrouping.class);
@ -45,10 +49,10 @@ public class TestXSSFColGrouping extends TestCase {
* Tests that POI doesn't produce "col" elements without "width" attribute.
* POI-52186
*/
@SuppressWarnings("deprecation")
public void testNoColsWithoutWidthWhenGrouping() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("test");
@Test
public void testNoColsWithoutWidthWhenGrouping() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
@ -56,24 +60,27 @@ public class TestXSSFColGrouping extends TestCase {
sheet.groupColumn((short) 4, (short) 7);
sheet.groupColumn((short) 9, (short) 12);
wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testNoColsWithoutWidthWhenGrouping");
sheet = wb.getSheet("test");
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGrouping");
sheet = wb2.getSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
for (CTCol col : cols.getColArray()) {
assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
}
wb2.close();
wb1.close();
}
/**
* Tests that POI doesn't produce "col" elements without "width" attribute.
* POI-52186
*/
@SuppressWarnings("deprecation")
public void testNoColsWithoutWidthWhenGroupingAndCollapsing() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("test");
@Test
public void testNoColsWithoutWidthWhenGroupingAndCollapsing() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
@ -85,8 +92,8 @@ public class TestXSSFColGrouping extends TestCase {
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols);
wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
sheet = wb.getSheet("test");
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
sheet = wb2.getSheet("test");
for (int i = 4; i <= 5; i++) {
assertEquals("Unexpected width of column "+ i, 5000, sheet.getColumnWidth(i));
@ -95,14 +102,17 @@ public class TestXSSFColGrouping extends TestCase {
for (CTCol col : cols.getColArray()) {
assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
}
wb2.close();
wb1.close();
}
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_2_WRAPS
*/
public void testMergingOverlappingCols_OVERLAPS_2_WRAPS() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("test");
@Test
public void testMergingOverlappingCols_OVERLAPS_2_WRAPS() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
CTCol col = cols.addNewCol();
@ -133,20 +143,24 @@ public class TestXSSFColGrouping extends TestCase {
assertEquals(3, cols.sizeOfColArray());
wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_2_WRAPS");
sheet = wb.getSheet("test");
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_WRAPS");
sheet = wb2.getSheet("test");
for (int i = 1; i <= 4; i++) {
assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
}
wb2.close();
wb1.close();
}
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_1_WRAPS
*/
public void testMergingOverlappingCols_OVERLAPS_1_WRAPS() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("test");
@Test
public void testMergingOverlappingCols_OVERLAPS_1_WRAPS() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
CTCol col = cols.addNewCol();
@ -177,20 +191,24 @@ public class TestXSSFColGrouping extends TestCase {
assertEquals(3, cols.sizeOfColArray());
wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_1_WRAPS");
sheet = wb.getSheet("test");
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_WRAPS");
sheet = wb2.getSheet("test");
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
}
wb2.close();
wb1.close();
}
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_1_MINOR
*/
public void testMergingOverlappingCols_OVERLAPS_1_MINOR() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("test");
@Test
public void testMergingOverlappingCols_OVERLAPS_1_MINOR() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
CTCol col = cols.addNewCol();
@ -221,21 +239,25 @@ public class TestXSSFColGrouping extends TestCase {
assertEquals(3, cols.sizeOfColArray());
wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_1_MINOR");
sheet = wb.getSheet("test");
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_MINOR");
sheet = wb2.getSheet("test");
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
}
assertEquals("Unexpected width of column "+ 5, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(5));
wb2.close();
wb1.close();
}
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_2_MINOR
*/
public void testMergingOverlappingCols_OVERLAPS_2_MINOR() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("test");
@Test
public void testMergingOverlappingCols_OVERLAPS_2_MINOR() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
CTCol col = cols.addNewCol();
@ -266,13 +288,16 @@ public class TestXSSFColGrouping extends TestCase {
assertEquals(3, cols.sizeOfColArray());
wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_2_MINOR");
sheet = wb.getSheet("test");
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_MINOR");
sheet = wb2.getSheet("test");
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
}
assertEquals("Unexpected width of column "+ 1, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(1));
wb2.close();
wb1.close();
}
}

View File

@ -327,7 +327,6 @@ public final class TestXSSFSheet extends BaseTestSheet {
@Test
@SuppressWarnings("deprecation")
public void groupUngroupColumn() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
@ -969,7 +968,6 @@ public final class TestXSSFSheet extends BaseTestSheet {
*/
@Override
@Test
@SuppressWarnings("deprecation")
public void createRow() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();

View File

@ -38,17 +38,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
public final class TestXSSFTable {
public TestXSSFTable() {
}
@Test
@SuppressWarnings("deprecation")
public void bug56274() throws IOException {
// read sample file
XSSFWorkbook inputWorkbook = XSSFTestDataSamples.openSampleWorkbook("56274.xlsx");
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("56274.xlsx");
// read the original sheet header order
XSSFRow row = inputWorkbook.getSheetAt(0).getRow(0);
XSSFRow row = wb1.getSheetAt(0).getRow(0);
List<String> headers = new ArrayList<String>();
for (Cell cell : row) {
headers.add(cell.getStringCellValue());
@ -56,12 +52,17 @@ public final class TestXSSFTable {
// save the worksheet as-is using SXSSF
File outputFile = TempFile.createTempFile("poi-56274", ".xlsx");
SXSSFWorkbook outputWorkbook = new org.apache.poi.xssf.streaming.SXSSFWorkbook(inputWorkbook);
outputWorkbook.write(new FileOutputStream(outputFile));
SXSSFWorkbook outputWorkbook = new SXSSFWorkbook(wb1);
FileOutputStream fos = new FileOutputStream(outputFile);
outputWorkbook.write(fos);
fos.close();
outputWorkbook.close();
// re-read the saved file and make sure headers in the xml are in the original order
inputWorkbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(new FileInputStream(outputFile));
CTTable ctTable = inputWorkbook.getSheetAt(0).getTables().get(0).getCTTable();
FileInputStream fis = new FileInputStream(outputFile);
XSSFWorkbook wb2 = new XSSFWorkbook(fis);
fis.close();
CTTable ctTable = wb2.getSheetAt(0).getTables().get(0).getCTTable();
CTTableColumn[] ctTableColumnArray = ctTable.getTableColumns().getTableColumnArray();
assertEquals("number of headers in xml table should match number of header cells in worksheet",
@ -71,10 +72,12 @@ public final class TestXSSFTable {
headers.get(i), ctTableColumnArray[i].getName());
}
assertTrue(outputFile.delete());
wb2.close();
wb1.close();
}
@Test
public void testCTTableStyleInfo(){
public void testCTTableStyleInfo() throws IOException {
XSSFWorkbook outputWorkbook = new XSSFWorkbook();
XSSFSheet sheet = outputWorkbook.createSheet();
@ -103,6 +106,8 @@ public final class TestXSSFTable {
assertEquals("Show row stripes",
outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes());
inputWorkbook.close();
outputWorkbook.close();
}
}

View File

@ -17,13 +17,19 @@
package org.apache.poi.xwpf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.junit.Ignore;
import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
@ -47,14 +53,16 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
/**
* Tests for XWPF Paragraphs
*/
public final class TestXWPFParagraph extends TestCase {
public final class TestXWPFParagraph {
/**
* Check that we get the right paragraph from the header
*
* @throws IOException
*/
public void disabled_testHeaderParagraph() throws IOException {
@Test
@Ignore
public void testHeaderParagraph() throws IOException {
XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
@ -65,8 +73,9 @@ public final class TestXWPFParagraph extends TestCase {
XWPFParagraph p = ps.get(0);
assertEquals(5, p.getCTP().sizeOfRArray());
assertEquals("First header column!\tMid header\tRight header!", p
.getText());
assertEquals("First header column!\tMid header\tRight header!", p.getText());
xml.close();
}
/**
@ -74,7 +83,9 @@ public final class TestXWPFParagraph extends TestCase {
*
* @throws IOException
*/
public void disabled_testDocumentParagraph() throws IOException {
@Test
@Ignore
public void testDocumentParagraph() throws IOException {
XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
List<XWPFParagraph> ps = xml.getParagraphs();
assertEquals(10, ps.size());
@ -95,9 +106,12 @@ public final class TestXWPFParagraph extends TestCase {
assertFalse(ps.get(4).isEmpty());
assertEquals("More on page one", ps.get(4).getText());
xml.close();
}
public void testSetGetBorderTop() {
@Test
public void testSetGetBorderTop() throws IOException {
//new clean instance of paragraph
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -116,9 +130,12 @@ public final class TestXWPFParagraph extends TestCase {
assertEquals(Borders.DOUBLE, p.getBorderTop());
p.setBorderTop(Borders.SINGLE);
assertEquals(STBorder.SINGLE, borderTop.getVal());
doc.close();
}
public void testSetGetAlignment() {
@Test
public void testSetGetAlignment() throws IOException {
//new clean instance of paragraph
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -134,10 +151,12 @@ public final class TestXWPFParagraph extends TestCase {
p.setAlignment(ParagraphAlignment.BOTH);
assertEquals(STJc.BOTH, ppr.getJc().getVal());
doc.close();
}
public void testSetGetSpacing() {
@Test
public void testSetGetSpacing() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -152,9 +171,12 @@ public final class TestXWPFParagraph extends TestCase {
p.setSpacingAfter(100);
assertEquals(100, spacing.getAfter().intValue());
doc.close();
}
public void testSetGetSpacingLineRule() {
@Test
public void testSetGetSpacingLineRule() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -169,9 +191,12 @@ public final class TestXWPFParagraph extends TestCase {
p.setSpacingAfter(100);
assertEquals(100, spacing.getAfter().intValue());
doc.close();
}
public void testSetGetIndentation() {
@Test
public void testSetGetIndentation() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -188,9 +213,12 @@ public final class TestXWPFParagraph extends TestCase {
p.setIndentationLeft(100);
assertEquals(100, ind.getLeft().intValue());
doc.close();
}
public void testSetGetVerticalAlignment() {
@Test
public void testSetGetVerticalAlignment() throws IOException {
//new clean instance of paragraph
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -204,9 +232,12 @@ public final class TestXWPFParagraph extends TestCase {
p.setVerticalAlignment(TextAlignment.BOTTOM);
assertEquals(STTextAlignment.BOTTOM, ppr.getTextAlignment().getVal());
doc.close();
}
public void testSetGetWordWrap() {
@Test
public void testSetGetWordWrap() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -217,12 +248,14 @@ public final class TestXWPFParagraph extends TestCase {
wordWrap.setVal(STOnOff.FALSE);
assertEquals(false, p.isWordWrap());
p.setWordWrap(true);
p.setWordWrapped(true);
assertEquals(STOnOff.TRUE, ppr.getWordWrap().getVal());
doc.close();
}
public void testSetGetPageBreak() {
@Test
public void testSetGetPageBreak() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -235,9 +268,10 @@ public final class TestXWPFParagraph extends TestCase {
p.setPageBreak(true);
assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
doc.close();
}
@SuppressWarnings("deprecation")
@Test
public void testBookmarks() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("bookmarks.docx");
XWPFParagraph paragraph = doc.getParagraphs().get(0);
@ -249,17 +283,21 @@ public final class TestXWPFParagraph extends TestCase {
for (CTBookmark bookmark : paragraph.getCTP().getBookmarkStartArray()) {
assertEquals("poi", bookmark.getName());
}
doc.close();
}
public void testGetSetNumID() {
@Test
public void testGetSetNumID() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
p.setNumID(new BigInteger("10"));
assertEquals("10", p.getNumID().toString());
doc.close();
}
public void testAddingRuns() throws Exception {
@Test
public void testAddingRuns() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
XWPFParagraph p = doc.getParagraphs().get(0);
@ -273,9 +311,12 @@ public final class TestXWPFParagraph extends TestCase {
assertEquals(4, p.getRuns().size());
assertEquals(1, p.getRuns().indexOf(r2));
assertEquals(3, p.getRuns().indexOf(r));
doc.close();
}
public void testPictures() throws Exception {
@Test
public void testPictures() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
assertEquals(7, doc.getParagraphs().size());
@ -346,17 +387,22 @@ public final class TestXWPFParagraph extends TestCase {
r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
PicDocument pd = new PicDocumentImpl(null);
assertTrue(pd.isNil());
doc.close();
}
@Test
public void testTika792() throws Exception {
//This test forces the loading of CTMoveBookmark and
//CTMoveBookmarkImpl into ooxml-lite.
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Tika-792.docx");
XWPFParagraph paragraph = doc.getParagraphs().get(0);
assertEquals("s", paragraph.getText());
doc.close();
}
public void testSettersGetters() {
@Test
public void testSettersGetters() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -455,9 +501,9 @@ public final class TestXWPFParagraph extends TestCase {
assertEquals(25, p.getIndentationFirstLine());
assertFalse(p.isWordWrap());
p.setWordWrap(true);
p.setWordWrapped(true);
assertTrue(p.isWordWrap());
p.setWordWrap(false);
p.setWordWrapped(false);
assertFalse(p.isWordWrap());
assertNull(p.getStyle());
@ -471,16 +517,21 @@ public final class TestXWPFParagraph extends TestCase {
assertNotNull(p.getBody());
assertEquals(BodyElementType.PARAGRAPH, p.getElementType());
assertEquals(BodyType.DOCUMENT, p.getPartType());
doc.close();
}
public void testSearchTextNotFound() {
@Test
public void testSearchTextNotFound() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
assertNull(p.searchText("test", new PositionInParagraph()));
assertEquals("", p.getText());
doc.close();
}
@Test
public void testSearchTextFound() throws IOException {
XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
@ -495,9 +546,11 @@ public final class TestXWPFParagraph extends TestCase {
assertEquals("sample word document", p.getText(segment));
assertTrue(p.removeRun(0));
xml.close();
}
public void testFieldRuns() throws Exception {
@Test
public void testFieldRuns() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx");
List<XWPFParagraph> ps = doc.getParagraphs();
assertEquals(1, ps.size());
@ -513,10 +566,12 @@ public final class TestXWPFParagraph extends TestCase {
assertEquals(" FILENAME \\* MERGEFORMAT ", fr.getFieldInstruction());
assertEquals("FldSimple.docx", fr.text());
assertEquals("FldSimple.docx", p.getText());
doc.close();
}
@SuppressWarnings("deprecation")
public void testRuns() {
@Test
public void testRuns() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
@ -527,5 +582,6 @@ public final class TestXWPFParagraph extends TestCase {
assertNotNull(p.getRun(run));
assertNull(p.getRun(null));
doc.close();
}
}