==================================================================== */
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
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());
+
+ CoreProperties cprops = xml.getProperties().getCoreProperties();
+ assertNull(cprops.getTitle());
+ assertNull(cprops.getUnderlyingProperties().getSubjectProperty().getValue());
- assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
- assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+ xml.close();
}
}
==================================================================== */
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();
@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
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());
assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+
+ xml.close();
}
@Test
}
// 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());
assertEquals(null, slide.getComments());
}
}
+
+ xmlComments.close();
+ xml.close();
}
}
runTest56574(true);
}
- @SuppressWarnings("deprecation")
private void runTest56574(boolean createRow) throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56574.xlsx");
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;
* </em>
*
*/
-public class TestXSSFColGrouping extends TestCase {
+public class TestXSSFColGrouping {
private static final POILogger logger = POILogFactory.getLogger(TestXSSFColGrouping.class);
* 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);
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);
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));
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();
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();
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();
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();
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();
}
}
@Test
- @SuppressWarnings("deprecation")
public void groupUngroupColumn() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
*/
@Override
@Test
- @SuppressWarnings("deprecation")
public void createRow() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
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());
// 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",
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();
assertEquals("Show row stripes",
outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes());
+ inputWorkbook.close();
+ outputWorkbook.close();
}
}
\ No newline at end of file
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;
/**
* 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();
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();
}
/**
*
* @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());
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();
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();
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();
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();
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();
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();
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();
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();
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);
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);
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());
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();
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());
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");
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());
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();
assertNotNull(p.getRun(run));
assertNull(p.getRun(null));
+ doc.close();
}
}