mirror of https://github.com/apache/poi.git
IDE and JavaDoc fixes, close() in tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849812 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c218c3cbc4
commit
ae3d6944db
|
@ -1571,7 +1571,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
|||
*
|
||||
* @param oldContentType the content type to be replaced
|
||||
* @param newContentType the replacement
|
||||
* @return whether replacement was succesfull
|
||||
* @return whether replacement was successful
|
||||
* @since POI-3.8
|
||||
*/
|
||||
public boolean replaceContentType(String oldContentType, String newContentType){
|
||||
|
|
|
@ -470,7 +470,6 @@ public class TestExtractorFactory {
|
|||
ExtractorFactory.getEmbededDocsTextExtractors((POIXMLTextExtractor) null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetEmbeddedFromXMLExtractor() {
|
||||
// currently not implemented
|
||||
|
|
|
@ -112,7 +112,6 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
|
|||
return;
|
||||
}
|
||||
Cell readCell = readRow.getCell(0);
|
||||
//noinspection deprecation
|
||||
if(readCell.getCellType() == CellType.NUMERIC) {
|
||||
assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
|
||||
} else {
|
||||
|
@ -470,7 +469,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
|
|||
// bug 60260: shift rows or rename a sheet containing a named range
|
||||
// that refers to formula with a unicode (non-ASCII) sheet name formula
|
||||
@Test
|
||||
public void shiftRowsWithUnicodeNamedRange() throws IOException {
|
||||
public void shiftRowsWithUnicodeNamedRange() {
|
||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("unicodeSheetName.xlsx");
|
||||
XSSFSheet sheet = wb.getSheetAt(0);
|
||||
sheet.shiftRows(1, 2, 3);
|
||||
|
|
|
@ -32,27 +32,26 @@ public final class TestXWPFSDT {
|
|||
|
||||
/**
|
||||
* Test simple tag and title extraction from SDT
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testTagTitle() throws Exception {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
|
||||
String tag = null;
|
||||
String title = null;
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
for (XWPFAbstractSDT sdt : sdts) {
|
||||
if (sdt.getContent().toString().equals("Rich_text")) {
|
||||
tag = "MyTag";
|
||||
title = "MyTitle";
|
||||
break;
|
||||
try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug54849.docx")) {
|
||||
String tag = null;
|
||||
String title = null;
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
for (XWPFAbstractSDT sdt : sdts) {
|
||||
if (sdt.getContent().toString().equals("Rich_text")) {
|
||||
tag = "MyTag";
|
||||
title = "MyTitle";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
assertEquals("controls size", 13, sdts.size());
|
||||
|
||||
assertEquals("tag", "MyTag", tag);
|
||||
assertEquals("title", "MyTitle", title);
|
||||
}
|
||||
assertEquals("controls size", 13, sdts.size());
|
||||
|
||||
assertEquals("tag", "MyTag", tag);
|
||||
assertEquals("title", "MyTitle", title);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,14 +72,15 @@ public final class TestXWPFSDT {
|
|||
"Endnote_sdt"
|
||||
|
||||
};
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug54849.docx")) {
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
|
||||
assertEquals("number of sdts", contents.length, sdts.size());
|
||||
assertEquals("number of sdts", contents.length, sdts.size());
|
||||
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
XWPFAbstractSDT sdt = sdts.get(i);
|
||||
assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString());
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
XWPFAbstractSDT sdt = sdts.get(i);
|
||||
assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,25 +91,26 @@ public final class TestXWPFSDT {
|
|||
public void testSDTAsCell() throws Exception {
|
||||
//Bug54771a.docx and Bug54771b.docx test slightly
|
||||
//different recursion patterns. Keep both!
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx");
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
String text = sdts.get(0).getContent().getText();
|
||||
assertEquals(2, sdts.size());
|
||||
assertContains(text, "Test");
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx")) {
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
String text = sdts.get(0).getContent().getText();
|
||||
assertEquals(2, sdts.size());
|
||||
assertContains(text, "Test");
|
||||
|
||||
text = sdts.get(1).getContent().getText();
|
||||
assertContains(text, "Test Subtitle");
|
||||
assertContains(text, "Test User");
|
||||
assertTrue(text.indexOf("Test") < text.indexOf("Test Subtitle"));
|
||||
text = sdts.get(1).getContent().getText();
|
||||
assertContains(text, "Test Subtitle");
|
||||
assertContains(text, "Test User");
|
||||
assertTrue(text.indexOf("Test") < text.indexOf("Test Subtitle"));
|
||||
}
|
||||
|
||||
doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx");
|
||||
sdts = extractAllSDTs(doc);
|
||||
assertEquals(3, sdts.size());
|
||||
assertContains(sdts.get(0).getContent().getText(), "Test");
|
||||
|
||||
assertContains(sdts.get(1).getContent().getText(), "Test Subtitle");
|
||||
assertContains(sdts.get(2).getContent().getText(), "Test User");
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx")) {
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
assertEquals(3, sdts.size());
|
||||
assertContains(sdts.get(0).getContent().getText(), "Test");
|
||||
|
||||
assertContains(sdts.get(1).getContent().getText(), "Test Subtitle");
|
||||
assertContains(sdts.get(2).getContent().getText(), "Test User");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,35 +118,37 @@ public final class TestXWPFSDT {
|
|||
*/
|
||||
@Test
|
||||
public void testNewLinesBetweenRuns() throws Exception {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx");
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
List<String> targs = new ArrayList<>();
|
||||
//these test newlines and tabs in paragraphs/body elements
|
||||
targs.add("Rich-text1 abcdefghi");
|
||||
targs.add("Rich-text2 abcd\t\tefgh");
|
||||
targs.add("Rich-text3 abcd\nefg");
|
||||
targs.add("Rich-text4 abcdefg");
|
||||
targs.add("Rich-text5 abcdefg\nhijk");
|
||||
targs.add("Plain-text1 abcdefg");
|
||||
targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
|
||||
//this tests consecutive runs within a cell (not a paragraph)
|
||||
//this test case was triggered by Tika-1130
|
||||
targs.add("sdt_incell2 abcdefg");
|
||||
try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug55142.docx")) {
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
List<String> targs = new ArrayList<>();
|
||||
//these test newlines and tabs in paragraphs/body elements
|
||||
targs.add("Rich-text1 abcdefghi");
|
||||
targs.add("Rich-text2 abcd\t\tefgh");
|
||||
targs.add("Rich-text3 abcd\nefg");
|
||||
targs.add("Rich-text4 abcdefg");
|
||||
targs.add("Rich-text5 abcdefg\nhijk");
|
||||
targs.add("Plain-text1 abcdefg");
|
||||
targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
|
||||
//this tests consecutive runs within a cell (not a paragraph)
|
||||
//this test case was triggered by Tika-1130
|
||||
targs.add("sdt_incell2 abcdefg");
|
||||
|
||||
for (int i = 0; i < sdts.size(); i++) {
|
||||
XWPFAbstractSDT sdt = sdts.get(i);
|
||||
assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
|
||||
for (int i = 0; i < sdts.size(); i++) {
|
||||
XWPFAbstractSDT sdt = sdts.get(i);
|
||||
assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test60341() throws IOException {
|
||||
//handle sdtbody without an sdtpr
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug60341.docx");
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
assertEquals(1, sdts.size());
|
||||
assertEquals("", sdts.get(0).getTag());
|
||||
assertEquals("", sdts.get(0).getTitle());
|
||||
try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug60341.docx")) {
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
assertEquals(1, sdts.size());
|
||||
assertEquals("", sdts.get(0).getTag());
|
||||
assertEquals("", sdts.get(0).getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -154,15 +157,15 @@ public final class TestXWPFSDT {
|
|||
//it does test for a related issue, and the fix fixes both.
|
||||
//We should try to add the actual triggering document
|
||||
//to our test suite.
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug62859.docx");
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
assertEquals(1, sdts.size());
|
||||
assertEquals("", sdts.get(0).getTag());
|
||||
assertEquals("", sdts.get(0).getTitle());
|
||||
try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug62859.docx")) {
|
||||
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
|
||||
assertEquals(1, sdts.size());
|
||||
assertEquals("", sdts.get(0).getTag());
|
||||
assertEquals("", sdts.get(0).getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
|
||||
|
||||
List<XWPFAbstractSDT> sdts = new ArrayList<>();
|
||||
|
||||
List<XWPFHeader> headers = doc.getHeaderList();
|
||||
|
|
|
@ -30,10 +30,11 @@ import static org.apache.poi.POITestCase.assertContains;
|
|||
public final class TestXWPFSmartTag extends TestCase {
|
||||
|
||||
public void testSmartTags() throws IOException {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx");
|
||||
XWPFParagraph p = doc.getParagraphArray(0);
|
||||
assertContains(p.getText(), "Carnegie Mellon University School of Computer Science");
|
||||
p = doc.getParagraphArray(2);
|
||||
assertContains(p.getText(), "Alice's Adventures");
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx")) {
|
||||
XWPFParagraph p = doc.getParagraphArray(0);
|
||||
assertContains(p.getText(), "Carnegie Mellon University School of Computer Science");
|
||||
p = doc.getParagraphArray(2);
|
||||
assertContains(p.getText(), "Alice's Adventures");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
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;
|
||||
|
@ -39,18 +40,19 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
|
|||
public final class TestXWPFStyles {
|
||||
@Test
|
||||
public void testGetUsedStyles() throws IOException {
|
||||
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx");
|
||||
List<XWPFStyle> testUsedStyleList = new ArrayList<>();
|
||||
XWPFStyles styles = sampleDoc.getStyles();
|
||||
XWPFStyle style = styles.getStyle("berschrift1");
|
||||
testUsedStyleList.add(style);
|
||||
testUsedStyleList.add(styles.getStyle("Standard"));
|
||||
testUsedStyleList.add(styles.getStyle("berschrift1Zchn"));
|
||||
testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart"));
|
||||
style.hasSameName(style);
|
||||
try (XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx")) {
|
||||
List<XWPFStyle> testUsedStyleList = new ArrayList<>();
|
||||
XWPFStyles styles = sampleDoc.getStyles();
|
||||
XWPFStyle style = styles.getStyle("berschrift1");
|
||||
testUsedStyleList.add(style);
|
||||
testUsedStyleList.add(styles.getStyle("Standard"));
|
||||
testUsedStyleList.add(styles.getStyle("berschrift1Zchn"));
|
||||
testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart"));
|
||||
style.hasSameName(style);
|
||||
|
||||
List<XWPFStyle> usedStyleList = styles.getUsedStyleList(style);
|
||||
assertEquals(usedStyleList, testUsedStyleList);
|
||||
List<XWPFStyle> usedStyleList = styles.getUsedStyleList(style);
|
||||
assertEquals(usedStyleList, testUsedStyleList);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -79,13 +81,14 @@ public final class TestXWPFStyles {
|
|||
*/
|
||||
@Test
|
||||
public void test52449() throws Exception {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx");
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
assertNotNull(styles);
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx")) {
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
assertNotNull(styles);
|
||||
|
||||
XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
||||
styles = docIn.getStyles();
|
||||
assertNotNull(styles);
|
||||
XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
||||
styles = docIn.getStyles();
|
||||
assertNotNull(styles);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,8 +124,8 @@ public final class TestXWPFStyles {
|
|||
CTLsdException ex = latentStyles.addNewLsdException();
|
||||
ex.setName("ex1");
|
||||
XWPFLatentStyles ls = new XWPFLatentStyles(latentStyles);
|
||||
assertEquals(true, ls.isLatentStyle("ex1"));
|
||||
assertEquals(false, ls.isLatentStyle("notex1"));
|
||||
assertTrue(ls.isLatentStyle("ex1"));
|
||||
assertFalse(ls.isLatentStyle("notex1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -147,88 +150,89 @@ public final class TestXWPFStyles {
|
|||
|
||||
@Test
|
||||
public void testEasyAccessToStyles() throws IOException {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
assertNotNull(styles);
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx")) {
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
assertNotNull(styles);
|
||||
|
||||
// Has 3 paragraphs on page one, a break, and 3 on page 2
|
||||
assertEquals(7, doc.getParagraphs().size());
|
||||
// Has 3 paragraphs on page one, a break, and 3 on page 2
|
||||
assertEquals(7, doc.getParagraphs().size());
|
||||
|
||||
// Check the first three have no run styles, just default paragraph style
|
||||
for (int i = 0; i < 3; i++) {
|
||||
XWPFParagraph p = doc.getParagraphs().get(i);
|
||||
assertEquals(null, p.getStyle());
|
||||
assertEquals(null, p.getStyleID());
|
||||
assertEquals(1, p.getRuns().size());
|
||||
// Check the first three have no run styles, just default paragraph style
|
||||
for (int i = 0; i < 3; i++) {
|
||||
XWPFParagraph p = doc.getParagraphs().get(i);
|
||||
assertNull(p.getStyle());
|
||||
assertNull(p.getStyleID());
|
||||
assertEquals(1, p.getRuns().size());
|
||||
|
||||
XWPFRun r = p.getRuns().get(0);
|
||||
assertEquals(null, r.getColor());
|
||||
assertEquals(null, r.getFontFamily());
|
||||
assertEquals(null, r.getFontName());
|
||||
assertEquals(-1, r.getFontSize());
|
||||
XWPFRun r = p.getRuns().get(0);
|
||||
assertNull(r.getColor());
|
||||
assertNull(r.getFontFamily());
|
||||
assertNull(r.getFontName());
|
||||
assertEquals(-1, r.getFontSize());
|
||||
}
|
||||
|
||||
// On page two, has explicit styles, but on runs not on
|
||||
// the paragraph itself
|
||||
for (int i = 4; i < 7; i++) {
|
||||
XWPFParagraph p = doc.getParagraphs().get(i);
|
||||
assertNull(p.getStyle());
|
||||
assertNull(p.getStyleID());
|
||||
assertEquals(1, p.getRuns().size());
|
||||
|
||||
XWPFRun r = p.getRuns().get(0);
|
||||
assertEquals("Arial Black", r.getFontFamily());
|
||||
assertEquals("Arial Black", r.getFontName());
|
||||
assertEquals(16, r.getFontSize());
|
||||
assertEquals("548DD4", r.getColor());
|
||||
}
|
||||
|
||||
// Check the document styles
|
||||
// Should have a style defined for each type
|
||||
assertEquals(4, styles.getNumberOfStyles());
|
||||
assertNotNull(styles.getStyle("Normal"));
|
||||
assertNotNull(styles.getStyle("DefaultParagraphFont"));
|
||||
assertNotNull(styles.getStyle("TableNormal"));
|
||||
assertNotNull(styles.getStyle("NoList"));
|
||||
|
||||
// We can't do much yet with latent styles
|
||||
assertEquals(137, styles.getLatentStyles().getNumberOfStyles());
|
||||
|
||||
// Check the default styles
|
||||
assertNotNull(styles.getDefaultRunStyle());
|
||||
assertNotNull(styles.getDefaultParagraphStyle());
|
||||
|
||||
assertEquals(11, styles.getDefaultRunStyle().getFontSize());
|
||||
assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
|
||||
}
|
||||
|
||||
// On page two, has explicit styles, but on runs not on
|
||||
// the paragraph itself
|
||||
for (int i = 4; i < 7; i++) {
|
||||
XWPFParagraph p = doc.getParagraphs().get(i);
|
||||
assertEquals(null, p.getStyle());
|
||||
assertEquals(null, p.getStyleID());
|
||||
assertEquals(1, p.getRuns().size());
|
||||
|
||||
XWPFRun r = p.getRuns().get(0);
|
||||
assertEquals("Arial Black", r.getFontFamily());
|
||||
assertEquals("Arial Black", r.getFontName());
|
||||
assertEquals(16, r.getFontSize());
|
||||
assertEquals("548DD4", r.getColor());
|
||||
}
|
||||
|
||||
// Check the document styles
|
||||
// Should have a style defined for each type
|
||||
assertEquals(4, styles.getNumberOfStyles());
|
||||
assertNotNull(styles.getStyle("Normal"));
|
||||
assertNotNull(styles.getStyle("DefaultParagraphFont"));
|
||||
assertNotNull(styles.getStyle("TableNormal"));
|
||||
assertNotNull(styles.getStyle("NoList"));
|
||||
|
||||
// We can't do much yet with latent styles
|
||||
assertEquals(137, styles.getLatentStyles().getNumberOfStyles());
|
||||
|
||||
// Check the default styles
|
||||
assertNotNull(styles.getDefaultRunStyle());
|
||||
assertNotNull(styles.getDefaultParagraphStyle());
|
||||
|
||||
assertEquals(11, styles.getDefaultRunStyle().getFontSize());
|
||||
assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
|
||||
}
|
||||
|
||||
// Bug 60329: style with missing StyleID throws NPE
|
||||
@Test
|
||||
public void testMissingStyleId() throws IOException {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60329.docx");
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
// Styles exist in the test document in this order, EmptyCellLayoutStyle
|
||||
// is missing a StyleId
|
||||
try {
|
||||
assertNotNull(styles.getStyle("NoList"));
|
||||
assertNull(styles.getStyle("EmptyCellLayoutStyle"));
|
||||
assertNotNull(styles.getStyle("BalloonText"));
|
||||
} catch (NullPointerException e) {
|
||||
fail(e.toString());
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60329.docx")) {
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
// Styles exist in the test document in this order, EmptyCellLayoutStyle
|
||||
// is missing a StyleId
|
||||
try {
|
||||
assertNotNull(styles.getStyle("NoList"));
|
||||
assertNull(styles.getStyle("EmptyCellLayoutStyle"));
|
||||
assertNotNull(styles.getStyle("BalloonText"));
|
||||
} catch (NullPointerException e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
doc.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStyleByName() throws IOException {
|
||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
assertNotNull(styles);
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx")) {
|
||||
XWPFStyles styles = doc.getStyles();
|
||||
assertNotNull(styles);
|
||||
|
||||
String styleName = "Normal Table";
|
||||
XWPFStyle style = styles.getStyleWithName(styleName);
|
||||
assertNotNull("Expected to find style \"" + styleName + "\"", style);
|
||||
assertEquals(styleName, style.getName());
|
||||
String styleName = "Normal Table";
|
||||
XWPFStyle style = styles.getStyleWithName(styleName);
|
||||
assertNotNull("Expected to find style \"" + styleName + "\"", style);
|
||||
assertEquals(styleName, style.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.List;
|
|||
public class TestXWPFTableCell {
|
||||
|
||||
@Test
|
||||
public void testSetGetVertAlignment() throws Exception {
|
||||
public void testSetGetVertAlignment() {
|
||||
// instantiate the following classes so they'll get picked up by
|
||||
// the XmlBean process and added to the jar file. they are required
|
||||
// for the following XWPFTableCell methods.
|
||||
|
@ -62,7 +62,7 @@ public class TestXWPFTableCell {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSetGetColor() throws Exception {
|
||||
public void testSetGetColor() {
|
||||
// create a table
|
||||
XWPFDocument doc = new XWPFDocument();
|
||||
CTTbl ctTable = CTTbl.Factory.newInstance();
|
||||
|
@ -81,7 +81,6 @@ public class TestXWPFTableCell {
|
|||
/**
|
||||
* ensure that CTHMerge and CTTcBorders go in poi-ooxml.jar
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void test54099() {
|
||||
XWPFDocument doc = new XWPFDocument();
|
||||
|
@ -96,24 +95,27 @@ public class TestXWPFTableCell {
|
|||
hMerge.setVal(STMerge.RESTART);
|
||||
|
||||
CTTcBorders tblBorders = tcPr.addNewTcBorders();
|
||||
assertNotNull(tblBorders);
|
||||
CTVMerge vMerge = tcPr.addNewVMerge();
|
||||
assertNotNull(vMerge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCellVerticalAlign() throws Exception{
|
||||
XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("59030.docx");
|
||||
List<XWPFTable> tables = docx.getTables();
|
||||
assertEquals(1, tables.size());
|
||||
try (XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("59030.docx")) {
|
||||
List<XWPFTable> tables = docx.getTables();
|
||||
assertEquals(1, tables.size());
|
||||
|
||||
XWPFTable table = tables.get(0);
|
||||
XWPFTable table = tables.get(0);
|
||||
|
||||
List<XWPFTableRow> tableRows = table.getRows();
|
||||
assertEquals(2, tableRows.size());
|
||||
List<XWPFTableRow> tableRows = table.getRows();
|
||||
assertEquals(2, tableRows.size());
|
||||
|
||||
assertNull(tableRows.get(0).getCell(0).getVerticalAlignment());
|
||||
assertEquals(XWPFVertAlign.BOTTOM, tableRows.get(0).getCell(1).getVerticalAlignment());
|
||||
assertEquals(XWPFVertAlign.CENTER, tableRows.get(1).getCell(0).getVerticalAlignment());
|
||||
assertNull(tableRows.get(1).getCell(1).getVerticalAlignment()); // should return null since alignment isn't set
|
||||
assertNull(tableRows.get(0).getCell(0).getVerticalAlignment());
|
||||
assertEquals(XWPFVertAlign.BOTTOM, tableRows.get(0).getCell(1).getVerticalAlignment());
|
||||
assertEquals(XWPFVertAlign.CENTER, tableRows.get(1).getCell(0).getVerticalAlignment());
|
||||
assertNull(tableRows.get(1).getCell(1).getVerticalAlignment()); // should return null since alignment isn't set
|
||||
}
|
||||
}
|
||||
|
||||
// This is not a very useful test as written. It is not worth the execution time for a unit test
|
||||
|
|
|
@ -102,20 +102,21 @@ public class TestXWPFTableRow {
|
|||
// generated in Word
|
||||
@Test
|
||||
public void testIsRepeatHeader() throws Exception {
|
||||
XWPFDocument doc = XWPFTestDataSamples
|
||||
.openSampleDocument("Bug60337.docx");
|
||||
XWPFTable table = doc.getTables().get(0);
|
||||
XWPFTableRow tr = table.getRow(0);
|
||||
boolean isRpt = tr.isRepeatHeader();
|
||||
assertTrue(isRpt);
|
||||
|
||||
tr = table.getRow(1);
|
||||
isRpt = tr.isRepeatHeader();
|
||||
assertFalse(isRpt);
|
||||
|
||||
tr = table.getRow(2);
|
||||
isRpt = tr.isRepeatHeader();
|
||||
assertFalse(isRpt);
|
||||
try (XWPFDocument doc = XWPFTestDataSamples
|
||||
.openSampleDocument("Bug60337.docx")) {
|
||||
XWPFTable table = doc.getTables().get(0);
|
||||
XWPFTableRow tr = table.getRow(0);
|
||||
boolean isRpt = tr.isRepeatHeader();
|
||||
assertTrue(isRpt);
|
||||
|
||||
tr = table.getRow(1);
|
||||
isRpt = tr.isRepeatHeader();
|
||||
assertFalse(isRpt);
|
||||
|
||||
tr = table.getRow(2);
|
||||
isRpt = tr.isRepeatHeader();
|
||||
assertFalse(isRpt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,20 +124,21 @@ public class TestXWPFTableRow {
|
|||
// generated in Word
|
||||
@Test
|
||||
public void testIsCantSplit() throws Exception {
|
||||
XWPFDocument doc = XWPFTestDataSamples
|
||||
.openSampleDocument("Bug60337.docx");
|
||||
XWPFTable table = doc.getTables().get(0);
|
||||
XWPFTableRow tr = table.getRow(0);
|
||||
boolean isCantSplit = tr.isCantSplitRow();
|
||||
assertFalse(isCantSplit);
|
||||
|
||||
tr = table.getRow(1);
|
||||
isCantSplit = tr.isCantSplitRow();
|
||||
assertFalse(isCantSplit);
|
||||
try (XWPFDocument doc = XWPFTestDataSamples
|
||||
.openSampleDocument("Bug60337.docx")) {
|
||||
XWPFTable table = doc.getTables().get(0);
|
||||
XWPFTableRow tr = table.getRow(0);
|
||||
boolean isCantSplit = tr.isCantSplitRow();
|
||||
assertFalse(isCantSplit);
|
||||
|
||||
tr = table.getRow(2);
|
||||
isCantSplit = tr.isCantSplitRow();
|
||||
assertTrue(isCantSplit);
|
||||
tr = table.getRow(1);
|
||||
isCantSplit = tr.isCantSplitRow();
|
||||
assertFalse(isCantSplit);
|
||||
|
||||
tr = table.getRow(2);
|
||||
isCantSplit = tr.isCantSplitRow();
|
||||
assertTrue(isCantSplit);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -52,7 +52,7 @@ public final class TestBoundSheetRecord extends TestCase {
|
|||
|
||||
try {
|
||||
record.setSheetname("s//*s");
|
||||
throw new AssertionFailedError("Should have thrown IllegalArgumentException, but didnt");
|
||||
fail("Should have thrown IllegalArgumentException, but didnt");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue