Browse Source

sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894365 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_0
Andreas Beeker 2 years ago
parent
commit
3c3154ea8c
30 changed files with 1151 additions and 1244 deletions
  1. 1
    1
      poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java
  2. 1
    1
      poi-excelant/src/test/java/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
  3. 6
    18
      poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
  4. 2
    2
      poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
  5. 20
    21
      poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java
  6. 1
    1
      poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFSheetXMLHandler.java
  7. 20
    29
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java
  8. 20
    25
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
  9. 16
    15
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java
  10. 781
    811
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
  11. 59
    72
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
  12. 2
    2
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java
  13. 2
    2
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java
  14. 3
    3
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java
  15. 3
    8
      poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java
  16. 5
    5
      poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
  17. 104
    118
      poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
  18. 1
    1
      poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java
  19. 1
    1
      poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java
  20. 3
    3
      poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java
  21. 7
    6
      poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java
  22. 7
    7
      poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java
  23. 2
    2
      poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java
  24. 1
    1
      poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java
  25. 37
    39
      poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestPlexOfCps.java
  26. 22
    24
      poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestPictures.java
  27. 19
    21
      poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRange.java
  28. 1
    1
      poi/src/test/java/org/apache/poi/hpsf/basic/TestBasic.java
  29. 4
    4
      poi/src/test/java/org/apache/poi/hpsf/basic/TestEmptyProperties.java
  30. BIN
      poi/src/test/java9/module-info.class

+ 1
- 1
poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java View File

@@ -106,7 +106,7 @@ public class TestXLSX2CSV {
}

String errorOutput = errorBytes.toString(StandardCharsets.UTF_8);
assertEquals(errorOutput.length(), 0);
assertEquals(0, errorOutput.length());

String output = outputBytes.toString(StandardCharsets.UTF_8);
assertTrue(output.contains("\"Lorem\",111,,,"), "Had: " + output);

+ 1
- 1
poi-excelant/src/test/java/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java View File

@@ -274,7 +274,7 @@ class TestExcelAntWorkbookUtil {
List<String> sheets = fixture.getSheets();

assertNotNull(sheets);
assertEquals(sheets.size(), 3);
assertEquals(3, sheets.size());
}

@Test

+ 6
- 18
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java View File

@@ -23,11 +23,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
@@ -40,7 +38,6 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFPicture;
@@ -88,10 +85,10 @@ public final class TestContentTypeManager {
ctm.addContentType(name3, "text/xml+rel");
ctm.addContentType(name4, "text/xml+rel");

assertEquals(ctm.getContentType(name1), "foo-type1");
assertEquals(ctm.getContentType(name2), "foo-type2");
assertEquals(ctm.getContentType(name3), "text/xml+rel");
assertEquals(ctm.getContentType(name3), "text/xml+rel");
assertEquals("foo-type1", ctm.getContentType(name1));
assertEquals("foo-type2", ctm.getContentType(name2));
assertEquals("text/xml+rel", ctm.getContentType(name3));
assertEquals("text/xml+rel", ctm.getContentType(name3));
}

/**
@@ -114,8 +111,8 @@ public final class TestContentTypeManager {
ctm.removeContentType(name2);
ctm.removeContentType(name3);

assertEquals(ctm.getContentType(name1), "foo-type1");
assertEquals(ctm.getContentType(name2), "foo-type1");
assertEquals("foo-type1", ctm.getContentType(name1));
assertEquals("foo-type1", ctm.getContentType(name2));
assertNull(ctm.getContentType(name3));

ctm.removeContentType(name1);
@@ -131,15 +128,6 @@ public final class TestContentTypeManager {
// TODO
}

protected byte[] toByteArray(Workbook wb) {
try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
wb.write(os);
return os.toByteArray();
} catch (IOException e) {
throw new RuntimeException("failed to write excel file.");
}
}

@Test
void bug62629CombinePictures() throws Exception {
// this file has incorrect default content-types which caused problems in Apache POI

+ 2
- 2
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java View File

@@ -608,14 +608,14 @@ class TestSignatureInfo {
String certDigestXQuery = declareNS +
"$this//xades:SigningCertificate/xades:Cert/xades:CertDigest";
XmlObject[] xoList = sigDoc.selectPath(certDigestXQuery);
assertEquals(xoList.length, 1);
assertEquals(1, xoList.length);
DigestAlgAndValueType certDigest = (DigestAlgAndValueType) xoList[0];
assertNotNull(certDigest.getDigestValue());

String qualPropXQuery = declareNS +
"$this/ds:Signature/ds:Object/xades:QualifyingProperties";
xoList = sigDoc.selectPath(qualPropXQuery);
assertEquals(xoList.length, 1);
assertEquals(1, xoList.length);
QualifyingPropertiesType qualProp = (QualifyingPropertiesType) xoList[0];
boolean qualPropXsdOk = qualProp.validate();
assertTrue(qualPropXsdOk);

+ 20
- 21
poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java View File

@@ -50,7 +50,8 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.NullPrintStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.extractor.ExtractorFactory;
@@ -79,11 +80,9 @@ import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.commons.io.output.NullPrintStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.xslf.util.DummyGraphics2d;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -114,11 +113,11 @@ class TestXSLFBugs {

XSLFSlide slide = ss1.getSlides().get(0);

assertEquals(slide.getShapes().size(), 1);
assertEquals(1,slide.getShapes().size());

XSLFPictureShape picture = (XSLFPictureShape) slide.getShapes().get(0);

assertEquals(picture.getShapeId(), 662);
assertEquals(662, picture.getShapeId());
assertFalse(picture.isExternalLinkedPicture());
assertNull(picture.getPictureData());
assertNull(picture.getPictureLink());
@@ -133,12 +132,12 @@ class TestXSLFBugs {

XSLFSlide slide0 = ss1.getSlides().get(0);

assertEquals(slide0.getShapes().size(), 4);
assertEquals(4, slide0.getShapes().size());

assertRelation(slide0, "/ppt/slides/slide1.xml", null);
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
assertEquals(slide0.getRelations().size(), 2);
assertEquals(2, slide0.getRelations().size());

List<XSLFPictureShape> pictures = new ArrayList<>();
for (XSLFShape shape : slide0.getShapes()) {
@@ -147,21 +146,21 @@ class TestXSLFBugs {
}
}

assertEquals(pictures.size(), 2);
assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
assertEquals(pictures.get(1).getPictureData().getFileName(), "image1.png");
assertEquals(2, pictures.size());
assertEquals("image1.png", pictures.get(0).getPictureData().getFileName());
assertEquals("image1.png", pictures.get(1).getPictureData().getFileName());
// blipId is rId2 of both pictures

// remove just the first picture
slide0.removeShape(pictures.get(0));

assertEquals(slide0.getShapes().size(), 3);
assertEquals(3, slide0.getShapes().size());

assertRelation(slide0, "/ppt/slides/slide1.xml", null);
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
// the bug is that the following relation is gone
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
assertEquals(slide0.getRelations().size(), 2);
assertEquals(2, slide0.getRelations().size());

// Save and re-load
try (XMLSlideShow ss2 = writeOutAndReadBack(ss1)) {
@@ -172,7 +171,7 @@ class TestXSLFBugs {
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
assertEquals(slide0.getRelations().size(), 2);
assertEquals(2, slide0.getRelations().size());

pictures.clear();
for (XSLFShape shape : slide0.getShapes()) {
@@ -181,17 +180,17 @@ class TestXSLFBugs {
}
}

assertEquals(pictures.size(), 1);
assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
assertEquals(1, pictures.size());
assertEquals("image1.png", pictures.get(0).getPictureData().getFileName());

slide0.removeShape(pictures.get(0));

assertEquals(slide0.getShapes().size(), 2);
assertEquals(2, slide0.getShapes().size());

assertRelation(slide0, "/ppt/slides/slide1.xml", null);
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
assertNull(slide0.getRelationById("rId2"));
assertEquals(slide0.getRelations().size(), 1);
assertEquals(1, slide0.getRelations().size());

// Save and re-load
try (XMLSlideShow ss3 = writeOutAndReadBack(ss2)) {
@@ -201,7 +200,7 @@ class TestXSLFBugs {

assertRelation(slide0, "/ppt/slides/slide1.xml", null);
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
assertEquals(slide0.getShapes().size(), 2);
assertEquals(2, slide0.getShapes().size());
}
}
}
@@ -919,9 +918,9 @@ class TestXSLFBugs {

XSLFSlide slide = ss1.getSlides().get(0);

assertEquals(slide.getShapes().size(), 1);
assertEquals(1, slide.getShapes().size());
XSLFGroupShape group = (XSLFGroupShape) slide.getShapes().get(0);
assertEquals(group.getShapes().size(), 2);
assertEquals(2, group.getShapes().size());
XSLFAutoShape oval = (XSLFAutoShape) group.getShapes().get(0);
XSLFAutoShape arrow = (XSLFAutoShape) group.getShapes().get(1);
assertNull(oval.getFillColor());
@@ -1067,7 +1066,7 @@ class TestXSLFBugs {
XSLFSlide targetSlide = targetPresentation.getSlides().get(0);
assertEquals(2, targetPresentation.getPictureData().size());

targetPresentation.write(new UnsynchronizedByteArrayOutputStream());
targetPresentation.write(NullOutputStream.NULL_OUTPUT_STREAM);
}
}


+ 1
- 1
poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFSheetXMLHandler.java View File

@@ -60,7 +60,7 @@ public class TestXSSFSheetXMLHandler {
public void cell(final String cellReference, final String formattedValue,
final XSSFComment comment) {
assertEquals("\uD83D\uDE1Cmore text", formattedValue);
assertEquals(cellCount++, 0);
assertEquals(0, cellCount++);
}
}, false));


+ 20
- 29
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/BaseTestXSSFPivotTable.java View File

@@ -19,7 +19,9 @@ package org.apache.poi.xssf.usermodel;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;

@@ -66,19 +68,16 @@ public abstract class BaseTestXSSFPivotTable {
*/
@Test
void testAddRowLabelToPivotTable() {
int columnIndex = 0;

assertEquals(0, pivotTable.getRowLabelColumns().size());

pivotTable.addRowLabel(columnIndex);
pivotTable.addRowLabel(0);
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();

assertEquals(defintion.getRowFields().getFieldArray(0).getX(), columnIndex);
assertEquals(defintion.getRowFields().getCount(), 1);
assertEquals(0, defintion.getRowFields().getFieldArray(0).getX());
assertEquals(1, defintion.getRowFields().getCount());
assertEquals(1, pivotTable.getRowLabelColumns().size());

columnIndex = 1;
pivotTable.addRowLabel(columnIndex);
pivotTable.addRowLabel(1);
assertEquals(2, pivotTable.getRowLabelColumns().size());

assertEquals(0, (int)pivotTable.getRowLabelColumns().get(0));
@@ -120,7 +119,7 @@ public abstract class BaseTestXSSFPivotTable {
pivotTable.addColumnLabel(DataConsolidateFunction.MIN, columnThree);
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();

assertEquals(defintion.getDataFields().getDataFieldList().size(), 3);
assertEquals(3, defintion.getDataFields().getDataFieldList().size());
}


@@ -138,7 +137,7 @@ public abstract class BaseTestXSSFPivotTable {
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnThree);
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();

assertEquals(defintion.getDataFields().getDataFieldList().size(), 3);
assertEquals(3, defintion.getDataFields().getDataFieldList().size());
}

/**
@@ -161,15 +160,13 @@ public abstract class BaseTestXSSFPivotTable {
*/
@Test
void testColumnLabelCreatesDataField() {
int columnIndex = 0;

pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnIndex);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0);

CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();

assertEquals(defintion.getDataFields().getDataFieldArray(0).getFld(), columnIndex);
assertEquals(defintion.getDataFields().getDataFieldArray(0).getSubtotal(),
STDataConsolidateFunction.Enum.forInt(DataConsolidateFunction.SUM.getValue()));
assertEquals(0, defintion.getDataFields().getDataFieldArray(0).getFld());
assertSame(STDataConsolidateFunction.Enum.forInt(DataConsolidateFunction.SUM.getValue()),
defintion.getDataFields().getDataFieldArray(0).getSubtotal());
}

/**
@@ -220,12 +217,9 @@ public abstract class BaseTestXSSFPivotTable {
*/
@Test
void testAddDataColumn() {
int columnIndex = 0;
boolean isDataField = true;

pivotTable.addDataColumn(columnIndex, isDataField);
pivotTable.addDataColumn(0, true);
CTPivotFields pivotFields = pivotTable.getCTPivotTableDefinition().getPivotFields();
assertEquals(pivotFields.getPivotFieldArray(columnIndex).getDataField(), isDataField);
assertTrue(pivotFields.getPivotFieldArray(0).getDataField());
}

/**
@@ -247,8 +241,8 @@ public abstract class BaseTestXSSFPivotTable {
CTPageFields fields = pivotTable.getCTPivotTableDefinition().getPageFields();
CTPageField field = fields.getPageFieldArray(0);
assertEquals(field.getFld(), columnIndex);
assertEquals(field.getHier(), -1);
assertEquals(fields.getCount(), 1);
assertEquals(-1, field.getHier());
assertEquals(1, fields.getCount());
}

/**
@@ -295,19 +289,16 @@ public abstract class BaseTestXSSFPivotTable {
*/
@Test
void testAddColLabelToPivotTable() {
int columnIndex = 0;

assertEquals(0, pivotTable.getColLabelColumns().size());

pivotTable.addColLabel(columnIndex);
pivotTable.addColLabel(0);
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();

assertEquals(defintion.getColFields().getFieldArray(0).getX(), columnIndex);
assertEquals(defintion.getColFields().getCount(), 1);
assertEquals(0, defintion.getColFields().getFieldArray(0).getX());
assertEquals(1, defintion.getColFields().getCount());
assertEquals(1, pivotTable.getColLabelColumns().size());

columnIndex = 1;
pivotTable.addColLabel(columnIndex);
pivotTable.addColLabel(1);
assertEquals(2, pivotTable.getColLabelColumns().size());

assertEquals(0, (int)pivotTable.getColLabelColumns().get(0));

+ 20
- 25
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java View File

@@ -121,7 +121,7 @@ class TestXSSFCellStyle {
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getBottom().getStyle());
assertSame(STBorderStyle.MEDIUM, ctBorder.getBottom().getStyle());

num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
@@ -141,7 +141,7 @@ class TestXSSFCellStyle {
//none is not the same as "not set", therefore the following doesn't work any more
//assertFalse(ctBorder.isSetBottom());
//replacement:
assertEquals(ctBorder.getBottom().getStyle(), STBorderStyle.NONE);
assertSame(STBorderStyle.NONE, ctBorder.getBottom().getStyle());
}

@Test
@@ -159,7 +159,7 @@ class TestXSSFCellStyle {
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getRight().getStyle());
assertSame(STBorderStyle.MEDIUM, ctBorder.getRight().getStyle());

num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
@@ -179,7 +179,7 @@ class TestXSSFCellStyle {
//none is not the same as "not set", therefore the following doesn't work any more
//assertFalse(ctBorder.isSetRight());
//replacement:
assertEquals(ctBorder.getRight().getStyle(), STBorderStyle.NONE);
assertSame(STBorderStyle.NONE, ctBorder.getRight().getStyle());
}

@Test
@@ -197,7 +197,7 @@ class TestXSSFCellStyle {
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getLeft().getStyle());
assertSame(STBorderStyle.MEDIUM, ctBorder.getLeft().getStyle());

num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
@@ -217,7 +217,7 @@ class TestXSSFCellStyle {
//none is not the same as "not set", therefore the following doesn't work any more
//assertFalse(ctBorder.isSetLeft());
//replacement:
assertEquals(ctBorder.getLeft().getStyle(), STBorderStyle.NONE);
assertSame(STBorderStyle.NONE, ctBorder.getLeft().getStyle());
}

@Test
@@ -235,7 +235,7 @@ class TestXSSFCellStyle {
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
assertSame(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());

num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
@@ -255,7 +255,7 @@ class TestXSSFCellStyle {
//none is not the same as "not set", therefore the following doesn't work any more
//assertFalse(ctBorder.isSetTop());
//replacement:
assertEquals(ctBorder.getTop().getStyle(), STBorderStyle.NONE);
assertSame(STBorderStyle.NONE, ctBorder.getTop().getStyle());
}

private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) {
@@ -265,7 +265,7 @@ class TestXSSFCellStyle {
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(expected, ctBorder.getTop().getStyle());
assertSame(expected, ctBorder.getTop().getStyle());
}


@@ -641,7 +641,7 @@ class TestXSSFCellStyle {
assertTrue(fillId > 0);
//check changes in the underlying xml bean
CTFill ctFill2 = stylesTable.getFillAt(fillId).getCTFill();
assertEquals(STPatternType.SOLID, ctFill2.getPatternFill().getPatternType());
assertSame(STPatternType.SOLID, ctFill2.getPatternFill().getPatternType());

//setting the same fill multiple time does not update the styles table
for (int i = 0; i < 3; i++) {
@@ -695,15 +695,15 @@ class TestXSSFCellStyle {

cellStyle.setAlignment(HorizontalAlignment.LEFT);
assertEquals(HorizontalAlignment.LEFT, cellStyle.getAlignment());
assertEquals(STHorizontalAlignment.LEFT, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
assertSame(STHorizontalAlignment.LEFT, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());

cellStyle.setAlignment(HorizontalAlignment.JUSTIFY);
assertEquals(HorizontalAlignment.JUSTIFY, cellStyle.getAlignment());
assertEquals(STHorizontalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
assertSame(STHorizontalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());

cellStyle.setAlignment(HorizontalAlignment.CENTER);
assertEquals(HorizontalAlignment.CENTER, cellStyle.getAlignment());
assertEquals(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
assertSame(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
}

@Test
@@ -728,15 +728,15 @@ class TestXSSFCellStyle {
void testGetSetVerticalAlignment() {
assertEquals(VerticalAlignment.BOTTOM, cellStyle.getVerticalAlignment());
assertFalse(cellStyle.getCellAlignment().getCTCellAlignment().isSetVertical());
assertEquals(STVerticalAlignment.BOTTOM, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
assertSame(STVerticalAlignment.BOTTOM, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());

cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
assertEquals(VerticalAlignment.CENTER, cellStyle.getVerticalAlignment());
assertEquals(STVerticalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
assertSame(STVerticalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());

cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY);
assertEquals(VerticalAlignment.JUSTIFY, cellStyle.getVerticalAlignment());
assertEquals(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
assertSame(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
}

@Test
@@ -848,8 +848,8 @@ class TestXSSFCellStyle {
assertEquals("TestingFont", clone.getFont().getFontName());
assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat());
assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##"));
assertEquals(clone.getFillPattern(), FillPatternType.SOLID_FOREGROUND);
assertEquals(clone.getFillForegroundColor(), IndexedColors.BRIGHT_GREEN.getIndex());
assertEquals(FillPatternType.SOLID_FOREGROUND, clone.getFillPattern());
assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), clone.getFillForegroundColor());

// Save it and re-check
XSSFWorkbook wbReload = XSSFTestDataSamples.writeOutAndReadBack(wbClone);
@@ -862,8 +862,8 @@ class TestXSSFCellStyle {
assertEquals("TestingFont", reload.getFont().getFontName());
assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat());
assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##"));
assertEquals(clone.getFillPattern(), FillPatternType.SOLID_FOREGROUND);
assertEquals(clone.getFillForegroundColor(), IndexedColors.BRIGHT_GREEN.getIndex());
assertEquals(FillPatternType.SOLID_FOREGROUND, clone.getFillPattern());
assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), clone.getFillForegroundColor());

XSSFWorkbook wbOrig2 = XSSFTestDataSamples.writeOutAndReadBack(wbOrig);
assertNotNull(wbOrig2);
@@ -1006,8 +1006,6 @@ class TestXSSFCellStyle {
final CellStyle targetStyle = target.createCellStyle();
targetStyle.cloneStyleFrom(referenceStyle);
}
/*System.out.println("Reference : "+reference.getNumCellStyles());
System.out.println("Target : "+target.getNumCellStyles());*/
}

@Test
@@ -1025,9 +1023,6 @@ class TestXSSFCellStyle {
cell.setCellValue("Coucou"+i);
cell.setCellStyle(target.getCellStyleAt(i));
}
/*OutputStream out = new FileOutputStream("C:\\temp\\58084.xlsx");
target.write(out);
out.close();*/

Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target);


+ 16
- 15
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java View File

@@ -17,6 +17,7 @@

package org.apache.poi.xssf.usermodel;

import static org.apache.poi.ss.usermodel.FontCharset.*;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
@@ -79,7 +80,7 @@ public final class TestXSSFFont extends BaseTestFont{


xssfFont.setBold(true);
assertEquals(ctFont.sizeOfBArray(),1);
assertEquals(1,ctFont.sizeOfBArray());
assertTrue(ctFont.getBArray(0).getVal());
}

@@ -88,27 +89,27 @@ public final class TestXSSFFont extends BaseTestFont{
void testCharSetWithDeprecatedFontCharset() throws IOException {
CTFont ctFont=CTFont.Factory.newInstance();
CTIntProperty prop=ctFont.addNewCharset();
prop.setVal(org.apache.poi.ss.usermodel.FontCharset.ANSI.getValue());
prop.setVal(ANSI.getValue());

ctFont.setCharsetArray(0,prop);
XSSFFont xssfFont=new XSSFFont(ctFont);
assertEquals(Font.ANSI_CHARSET,xssfFont.getCharSet());

xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.DEFAULT);
assertEquals(org.apache.poi.ss.usermodel.FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
xssfFont.setCharSet(DEFAULT);
assertEquals(DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());

// Try with a few less usual ones:
// Set with the Charset itself
xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.RUSSIAN);
assertEquals(org.apache.poi.ss.usermodel.FontCharset.RUSSIAN.getValue(), xssfFont.getCharSet());
xssfFont.setCharSet(RUSSIAN);
assertEquals(RUSSIAN.getValue(), xssfFont.getCharSet());
// And set with the Charset index
xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue());
assertEquals(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
xssfFont.setCharSet((byte)(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue()));
assertEquals(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
xssfFont.setCharSet(ARABIC.getValue());
assertEquals(ARABIC.getValue(), xssfFont.getCharSet());
xssfFont.setCharSet((byte)(ARABIC.getValue()));
assertEquals(ARABIC.getValue(), xssfFont.getCharSet());

// This one isn't allowed
assertNull(org.apache.poi.ss.usermodel.FontCharset.valueOf(9999));
assertNull(valueOf(9999));
assertThrows(POIXMLException.class, () -> xssfFont.setCharSet(9999),
"Shouldn't be able to set an invalid charset");

@@ -198,7 +199,7 @@ public final class TestXSSFFont extends BaseTestFont{
assertFalse(xssfFont.getItalic());

xssfFont.setItalic(true);
assertEquals(ctFont.sizeOfIArray(),1);
assertEquals(1,ctFont.sizeOfIArray());
assertTrue(ctFont.getIArray(0).getVal());
assertTrue(ctFont.getIArray(0).getVal());
}
@@ -214,7 +215,7 @@ public final class TestXSSFFont extends BaseTestFont{
assertFalse(xssfFont.getStrikeout());

xssfFont.setStrikeout(true);
assertEquals(ctFont.sizeOfStrikeArray(),1);
assertEquals(1,ctFont.sizeOfStrikeArray());
assertTrue(ctFont.getStrikeArray(0).getVal());
assertTrue(ctFont.getStrikeArray(0).getVal());
}
@@ -258,11 +259,11 @@ public final class TestXSSFFont extends BaseTestFont{
assertEquals(Font.U_SINGLE, xssfFont.getUnderline());

xssfFont.setUnderline(Font.U_DOUBLE);
assertEquals(ctFont.sizeOfUArray(),1);
assertEquals(1, ctFont.sizeOfUArray());
assertSame(STUnderlineValues.DOUBLE,ctFont.getUArray(0).getVal());

xssfFont.setUnderline(FontUnderline.DOUBLE_ACCOUNTING);
assertEquals(ctFont.sizeOfUArray(),1);
assertEquals(1, ctFont.sizeOfUArray());
assertSame(STUnderlineValues.DOUBLE_ACCOUNTING,ctFont.getUArray(0).getVal());
}


+ 781
- 811
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
File diff suppressed because it is too large
View File


+ 59
- 72
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java View File

@@ -17,11 +17,24 @@

package org.apache.poi.xssf.usermodel;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
@@ -30,20 +43,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public final class TestXSSFTable {

@Test
@@ -86,34 +85,33 @@ public final class TestXSSFTable {

@Test
void testCTTableStyleInfo() throws IOException {
XSSFWorkbook outputWorkbook = new XSSFWorkbook();
XSSFSheet sheet = outputWorkbook.createSheet();

//Create
XSSFTable outputTable = sheet.createTable(null);
outputTable.setDisplayName("Test");
CTTable outputCTTable = outputTable.getCTTable();

//Style configurations
CTTableStyleInfo outputStyleInfo = outputCTTable.addNewTableStyleInfo();
outputStyleInfo.setName("TableStyleLight1");
outputStyleInfo.setShowColumnStripes(false);
outputStyleInfo.setShowRowStripes(true);

XSSFWorkbook inputWorkbook = XSSFTestDataSamples.writeOutAndReadBack(outputWorkbook);
List<XSSFTable> tables = inputWorkbook.getSheetAt(0).getTables();
assertEquals(1, tables.size(), "Tables number");

XSSFTable inputTable = tables.get(0);
assertEquals(outputTable.getDisplayName(), inputTable.getDisplayName(), "Table display name");

CTTableStyleInfo inputStyleInfo = inputTable.getCTTable().getTableStyleInfo();
assertEquals(outputStyleInfo.getName(), inputStyleInfo.getName(), "Style name");
assertEquals(outputStyleInfo.getShowColumnStripes(), inputStyleInfo.getShowColumnStripes(), "Show column stripes");
assertEquals(outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes(), "Show row stripes");

inputWorkbook.close();
outputWorkbook.close();
try (XSSFWorkbook outputWorkbook = new XSSFWorkbook()) {
XSSFSheet sheet = outputWorkbook.createSheet();

//Create
XSSFTable outputTable = sheet.createTable(null);
outputTable.setDisplayName("Test");
CTTable outputCTTable = outputTable.getCTTable();

//Style configurations
CTTableStyleInfo outputStyleInfo = outputCTTable.addNewTableStyleInfo();
outputStyleInfo.setName("TableStyleLight1");
outputStyleInfo.setShowColumnStripes(false);
outputStyleInfo.setShowRowStripes(true);

try (XSSFWorkbook inputWorkbook = XSSFTestDataSamples.writeOutAndReadBack(outputWorkbook)) {
List<XSSFTable> tables = inputWorkbook.getSheetAt(0).getTables();
assertEquals(1, tables.size(), "Tables number");

XSSFTable inputTable = tables.get(0);
assertEquals(outputTable.getDisplayName(), inputTable.getDisplayName(), "Table display name");

CTTableStyleInfo inputStyleInfo = inputTable.getCTTable().getTableStyleInfo();
assertEquals(outputStyleInfo.getName(), inputStyleInfo.getName(), "Style name");
assertEquals(outputStyleInfo.getShowColumnStripes(), inputStyleInfo.getShowColumnStripes(), "Show column stripes");
assertEquals(outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes(), "Show row stripes");
}
}
}

@Test
@@ -269,8 +267,6 @@ public final class TestXSSFTable {

assertEquals(new CellReference("C1"), table.getStartCellReference());
assertEquals(new CellReference("M3"), table.getEndCellReference());

IOUtils.closeQuietly(wb);
}
}

@@ -292,8 +288,6 @@ public final class TestXSSFTable {
// update cell references to clear the cache
table.updateReferences();
assertEquals(11, table.getRowCount());

IOUtils.closeQuietly(wb);
}
}

@@ -311,8 +305,6 @@ public final class TestXSSFTable {

assertEquals(6, table.getRowCount());
assertEquals(5, table.getDataRowCount());

IOUtils.closeQuietly(wb);
}
}

@@ -340,8 +332,6 @@ public final class TestXSSFTable {
assertEquals(0, table.getTotalsRowCount());

assertEquals("C10:C15", table.getArea().formatAsString());

IOUtils.closeQuietly(wb);
}
}

@@ -441,10 +431,10 @@ public final class TestXSSFTable {
assertTrue (cB.getId() < cD.getId(), "Column D ID");
assertTrue (cD.getId() < cC.getId(), "Column C ID");
// generated name
assertEquals(table.getColumns().get(0).getName(), "Column 1");
assertEquals(table.getColumns().get(1).getName(), "Column B");
assertEquals(table.getColumns().get(2).getName(), "Column C");
assertEquals(table.getColumns().get(3).getName(), "Column D");
assertEquals("Column 1", table.getColumns().get(0).getName());
assertEquals("Column B", table.getColumns().get(1).getName());
assertEquals("Column C", table.getColumns().get(2).getName());
assertEquals("Column D", table.getColumns().get(3).getName());
}
}

@@ -528,23 +518,20 @@ public final class TestXSSFTable {
));

// Save and re-load
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb);
IOUtils.closeQuietly(wb);
s = wb2.getSheetAt(0);

// Check
assertEquals(1, s.getTables().size());
t = s.getTables().get(0);
assertEquals("A1", t.getStartCellReference().formatAsString());
assertEquals("C2", t.getEndCellReference().formatAsString());

// TODO Nicer column fetching
assertEquals("12", t.getCTTable().getTableColumns().getTableColumnArray(0).getName());
assertEquals("34.56", t.getCTTable().getTableColumns().getTableColumnArray(1).getName());
assertEquals("ABCD", t.getCTTable().getTableColumns().getTableColumnArray(2).getName());

// Done
IOUtils.closeQuietly(wb2);
try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
s = wb2.getSheetAt(0);

// Check
assertEquals(1, s.getTables().size());
t = s.getTables().get(0);
assertEquals("A1", t.getStartCellReference().formatAsString());
assertEquals("C2", t.getEndCellReference().formatAsString());

// TODO Nicer column fetching
assertEquals("12", t.getCTTable().getTableColumns().getTableColumnArray(0).getName());
assertEquals("34.56", t.getCTTable().getTableColumns().getTableColumnArray(1).getName());
assertEquals("ABCD", t.getCTTable().getTableColumns().getTableColumnArray(2).getName());
}
}
}


+ 2
- 2
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java View File

@@ -40,9 +40,9 @@ public final class TestXSSFCategoryAxis {
XDDFCategoryAxis axis = chart.createCategoryAxis(AxisPosition.BOTTOM);

axis.setCrosses(AxisCrosses.AUTO_ZERO);
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());

assertEquals(chart.getAxes().size(), 1);
assertEquals(1, chart.getAxes().size());
}
}
}

+ 2
- 2
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java View File

@@ -41,9 +41,9 @@ public final class TestXSSFDateAxis {
XDDFDateAxis axis = chart.createDateAxis(AxisPosition.BOTTOM);

axis.setCrosses(AxisCrosses.AUTO_ZERO);
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());

assertEquals(chart.getAxes().size(), 1);
assertEquals(1, chart.getAxes().size());
}
}
}

+ 3
- 3
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java View File

@@ -42,12 +42,12 @@ public final class TestXSSFValueAxis {
XDDFValueAxis axis = chart.createValueAxis(AxisPosition.BOTTOM);

axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY);
assertEquals(AxisCrossBetween.MIDPOINT_CATEGORY, axis.getCrossBetween());

axis.setCrosses(AxisCrosses.AUTO_ZERO);
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());

assertEquals(chart.getAxes().size(), 1);
assertEquals(1, chart.getAxes().size());
}
}
}

+ 3
- 8
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java View File

@@ -18,6 +18,7 @@
package org.apache.poi.xssf.usermodel.extensions;


import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -89,19 +90,13 @@ class TestXSSFCellFill {
XSSFCell cellWithThemeColor = wb.getSheetAt(0).getRow(10).getCell(0);
//color RGB will be extracted from theme
XSSFColor foregroundColor = cellWithThemeColor.getCellStyle().getFillForegroundXSSFColor();
byte[] rgb = foregroundColor.getRGB();
byte[] rgbWithTint = foregroundColor.getRGBWithTint();
// Dk2
assertEquals(rgb[0], 31);
assertEquals(rgb[1], 73);
assertEquals(rgb[2], 125);
assertArrayEquals(new byte[]{31, 73, 125}, foregroundColor.getRGB());
// Dk2, lighter 40% (tint is about 0.39998)
// 31 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 120.59552 => 120 (byte)
// 73 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 145.79636 => -111 (byte)
// 125 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 176.99740 => -80 (byte)
assertEquals(rgbWithTint[0], 120);
assertEquals(rgbWithTint[1], -111);
assertEquals(rgbWithTint[2], -80);
assertArrayEquals(new byte[]{120, -111, -80}, foregroundColor.getRGBWithTint());
}
}


+ 5
- 5
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java View File

@@ -53,12 +53,12 @@ class TestXWPFBugs {

run.setFontFamily("Times New Roman");
run.setFontSize(20);
assertEquals(run.getFontFamily(), "Times New Roman");
assertEquals(run.getFontFamily(FontCharRange.cs), "Times New Roman");
assertEquals(run.getFontFamily(FontCharRange.eastAsia), "Times New Roman");
assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Times New Roman");
assertEquals("Times New Roman", run.getFontFamily());
assertEquals("Times New Roman", run.getFontFamily(FontCharRange.cs));
assertEquals("Times New Roman", run.getFontFamily(FontCharRange.eastAsia));
assertEquals("Times New Roman", run.getFontFamily(FontCharRange.hAnsi));
run.setFontFamily("Arial", FontCharRange.hAnsi);
assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial");
assertEquals("Arial", run.getFontFamily(FontCharRange.hAnsi));
}
}


+ 104
- 118
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java View File

@@ -45,29 +45,19 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.xmlbeans.XmlCursor;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;

public final class TestXWPFDocument {

@Test
void testContainsMainContentType() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
OPCPackage pack = doc.getPackage();

boolean found = false;
for (PackagePart part : pack.getParts()) {
if (part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
found = true;
}
// if (false) {
// // successful tests should be silent
// System.out.println(part);
// }
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
OPCPackage pack = doc.getPackage()) {
String ct = XWPFRelation.DOCUMENT.getContentType();
boolean found = pack.getParts().stream().anyMatch(p -> ct.equals(p.getContentType()));
assertTrue(found);
}
assertTrue(found);

pack.close();
doc.close();
}

@Test
@@ -105,90 +95,92 @@ public final class TestXWPFDocument {

@Test
void testMetadataComplex() throws IOException {
XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
assertNotNull(xml.getProperties().getCoreProperties());
assertNotNull(xml.getProperties().getExtendedProperties());

assertEquals("Microsoft Office Outlook", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
assertEquals(5184, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());

assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
Optional<String> subjectProperty = xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty();
assertTrue(subjectProperty.isPresent());
assertEquals(" ", subjectProperty.get());
xml.close();
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx")) {
assertNotNull(xml.getProperties().getCoreProperties());
assertNotNull(xml.getProperties().getExtendedProperties());

CTProperties up = xml.getProperties().getExtendedProperties().getUnderlyingProperties();
assertEquals("Microsoft Office Outlook", up.getApplication());
assertEquals(5184, up.getCharacters());
assertEquals(0, up.getLines());

POIXMLProperties.CoreProperties cp = xml.getProperties().getCoreProperties();
assertEquals(" ", cp.getTitle());
Optional<String> subjectProperty = cp.getUnderlyingProperties().getSubjectProperty();
assertTrue(subjectProperty.isPresent());
assertEquals(" ", subjectProperty.get());
}
}

@Test
void testWorkbookProperties() throws Exception {
XWPFDocument doc = new XWPFDocument();
POIXMLProperties props = doc.getProperties();
assertNotNull(props);
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
doc.close();
try (XWPFDocument doc = new XWPFDocument()) {
POIXMLProperties props = doc.getProperties();
assertNotNull(props);
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
}
}

@Test
void testAddParagraph() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
assertEquals(3, doc.getParagraphs().size());
XWPFParagraph p = doc.createParagraph();
assertEquals(p, doc.getParagraphs().get(3));
assertEquals(4, doc.getParagraphs().size());
assertEquals(3, doc.getParagraphPos(3));
assertEquals(3, doc.getPosOfParagraph(p));
CTP ctp = p.getCTP();
XWPFParagraph newP = doc.getParagraph(ctp);
assertSame(p, newP);
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
XWPFParagraph cP = doc.insertNewParagraph(cursor);
assertSame(cP, doc.getParagraphs().get(0));
assertEquals(5, doc.getParagraphs().size());
doc.close();
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
assertEquals(3, doc.getParagraphs().size());
XWPFParagraph p = doc.createParagraph();
assertEquals(p, doc.getParagraphs().get(3));
assertEquals(4, doc.getParagraphs().size());
assertEquals(3, doc.getParagraphPos(3));
assertEquals(3, doc.getPosOfParagraph(p));
CTP ctp = p.getCTP();
XWPFParagraph newP = doc.getParagraph(ctp);
assertSame(p, newP);
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
XWPFParagraph cP = doc.insertNewParagraph(cursor);
assertSame(cP, doc.getParagraphs().get(0));
assertEquals(5, doc.getParagraphs().size());
}
}

@Test
void testAddPicture() throws IOException, InvalidFormatException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
String relationId = doc.addPictureData(jpeg, Document.PICTURE_TYPE_JPEG);

XWPFPictureData relationById = (XWPFPictureData) doc.getRelationById(relationId);
assertNotNull(relationById);
byte[] newJpeg = relationById.getData();
assertEquals(newJpeg.length, jpeg.length);
for (int i = 0; i < jpeg.length; i++) {
assertEquals(newJpeg[i], jpeg[i]);
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
String relationId = doc.addPictureData(jpeg, Document.PICTURE_TYPE_JPEG);

XWPFPictureData relationById = (XWPFPictureData) doc.getRelationById(relationId);
assertNotNull(relationById);
byte[] newJpeg = relationById.getData();
assertEquals(newJpeg.length, jpeg.length);
for (int i = 0; i < jpeg.length; i++) {
assertEquals(newJpeg[i], jpeg[i]);
}
}
doc.close();
}

@Test
void testAllPictureFormats() throws IOException, InvalidFormatException {
XWPFDocument doc = new XWPFDocument();
doc.addPictureData(new byte[10], Document.PICTURE_TYPE_EMF);
doc.addPictureData(new byte[11], Document.PICTURE_TYPE_WMF);
doc.addPictureData(new byte[12], Document.PICTURE_TYPE_PICT);
doc.addPictureData(new byte[13], Document.PICTURE_TYPE_JPEG);
doc.addPictureData(new byte[14], Document.PICTURE_TYPE_PNG);
doc.addPictureData(new byte[15], Document.PICTURE_TYPE_DIB);
doc.addPictureData(new byte[16], Document.PICTURE_TYPE_GIF);
doc.addPictureData(new byte[17], Document.PICTURE_TYPE_TIFF);
doc.addPictureData(new byte[18], Document.PICTURE_TYPE_EPS);
doc.addPictureData(new byte[19], Document.PICTURE_TYPE_BMP);
doc.addPictureData(new byte[20], Document.PICTURE_TYPE_WPG);
assertEquals(11, doc.getAllPictures().size());
XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
assertEquals(11, doc2.getAllPictures().size());
doc2.close();
doc.close();
try (XWPFDocument doc = new XWPFDocument()) {
doc.addPictureData(new byte[10], Document.PICTURE_TYPE_EMF);
doc.addPictureData(new byte[11], Document.PICTURE_TYPE_WMF);
doc.addPictureData(new byte[12], Document.PICTURE_TYPE_PICT);
doc.addPictureData(new byte[13], Document.PICTURE_TYPE_JPEG);
doc.addPictureData(new byte[14], Document.PICTURE_TYPE_PNG);
doc.addPictureData(new byte[15], Document.PICTURE_TYPE_DIB);
doc.addPictureData(new byte[16], Document.PICTURE_TYPE_GIF);
doc.addPictureData(new byte[17], Document.PICTURE_TYPE_TIFF);
doc.addPictureData(new byte[18], Document.PICTURE_TYPE_EPS);
doc.addPictureData(new byte[19], Document.PICTURE_TYPE_BMP);
doc.addPictureData(new byte[20], Document.PICTURE_TYPE_WPG);
assertEquals(11, doc.getAllPictures().size());
try (XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc)) {
assertEquals(11, doc2.getAllPictures().size());
}
}
}

@Test
@@ -201,8 +193,8 @@ public final class TestXWPFDocument {
assertEquals("rId7", h.getHyperlinkId());

assertEquals("https://poi.apache.org/", h.getHyperlink(doc).getURL());
assertEquals(p.getRuns().size(), 1);
assertEquals(p.getRuns().get(0), h);
assertEquals(1, p.getRuns().size());
assertEquals(h, p.getRuns().get(0));

h = p.createHyperlinkRun("https://poi.apache.org/");
h.setText("Apache POI");
@@ -426,32 +418,27 @@ public final class TestXWPFDocument {
settings.setMirrorMargins(true);
assertTrue(settings.getMirrorMargins());

XWPFDocument doc = new XWPFDocument();
assertEquals(100, doc.getZoomPercent());

doc.setZoomPercent(50);
assertEquals(50, doc.getZoomPercent());
try (XWPFDocument doc = new XWPFDocument()) {
assertEquals(100, doc.getZoomPercent());

doc.setZoomPercent(200);
assertEquals(200, doc.getZoomPercent());
doc.setZoomPercent(50);
assertEquals(50, doc.getZoomPercent());

assertFalse(doc.getEvenAndOddHeadings());
doc.setEvenAndOddHeadings(true);
assertTrue(doc.getEvenAndOddHeadings());
doc.setZoomPercent(200);
assertEquals(200, doc.getZoomPercent());

assertFalse(doc.getMirrorMargins());
doc.setMirrorMargins(true);
assertTrue(doc.getMirrorMargins());
assertFalse(doc.getEvenAndOddHeadings());
doc.setEvenAndOddHeadings(true);
assertTrue(doc.getEvenAndOddHeadings());

XWPFDocument back = XWPFTestDataSamples.writeOutAndReadBack(doc);
assertEquals(200, back.getZoomPercent());
back.close();
assertFalse(doc.getMirrorMargins());
doc.setMirrorMargins(true);
assertTrue(doc.getMirrorMargins());

// OutputStream out = new FileOutputStream("/tmp/testZoom.docx");
// doc.write(out);
// out.close();

doc.close();
try (XWPFDocument back = XWPFTestDataSamples.writeOutAndReadBack(doc)) {
assertEquals(200, back.getZoomPercent());
}
}
}

@Test
@@ -464,20 +451,19 @@ public final class TestXWPFDocument {
@Test
@Disabled("XWPF should be able to write to a new Stream when opened Read-Only")
void testWriteFromReadOnlyOPC() throws Exception {
OPCPackage opc = OPCPackage.open(
try (OPCPackage opc = OPCPackage.open(
POIDataSamples.getDocumentInstance().getFile("SampleDoc.docx"),
PackageAccess.READ
);
XWPFDocument doc = new XWPFDocument(opc);

final String origText;
try (XWPFWordExtractor ext = new XWPFWordExtractor(doc)) {
origText = ext.getText();

doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
}
try (XWPFWordExtractor ext = new XWPFWordExtractor(doc)) {
assertEquals(origText, ext.getText());
);
XWPFDocument doc = new XWPFDocument(opc);
XWPFWordExtractor ext = new XWPFWordExtractor(doc)
) {
final String origText = ext.getText();

try (XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
XWPFWordExtractor ext2 = new XWPFWordExtractor(doc2)) {
assertEquals(origText, ext2.getText());
}
}
}
}

+ 1
- 1
poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java View File

@@ -165,7 +165,7 @@ public final class TestExtractor {
assertNotNull(nText);

// Notes record were corrupt, so don't expect any
assertEquals(nText.length(), 0);
assertEquals(0, nText.length());

// Slide records were fine
assertContains(text, "Using Disease Surveillance and Response");

+ 1
- 1
poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java View File

@@ -116,7 +116,7 @@ public final class TestShapes {
String text = txtbox.getText();
assertNotNull(text);

assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
assertEquals(1, txtbox.getTextParagraphs().get(0).getTextRuns().size());
HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);

switch (text) {

+ 3
- 3
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java View File

@@ -80,9 +80,9 @@ public final class TestExControl {

ExOleObjAtom oleObj = record.getExOleObjAtom();
assertNotNull(oleObj);
assertEquals(oleObj.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);
assertEquals(oleObj.getType(), ExOleObjAtom.TYPE_CONTROL);
assertEquals(oleObj.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);
assertEquals(ExOleObjAtom.DRAW_ASPECT_VISIBLE, oleObj.getDrawAspect());
assertEquals(ExOleObjAtom.TYPE_CONTROL, oleObj.getType());
assertEquals(ExOleObjAtom.SUBTYPE_DEFAULT, oleObj.getSubType());

assertEquals("Shockwave Flash Object", record.getMenuName());
assertEquals("ShockwaveFlash.ShockwaveFlash.9", record.getProgId());

+ 7
- 6
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java View File

@@ -38,12 +38,13 @@ public final class TestExOleObjAtom {
ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType());

assertEquals(record.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);
assertEquals(record.getType(), ExOleObjAtom.TYPE_CONTROL);
assertEquals(record.getObjID(), 1);
assertEquals(record.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);
assertEquals(record.getObjStgDataRef(), 2);
assertEquals(record.getOptions(), 1283584); //ther meaning is unknown
assertEquals(ExOleObjAtom.DRAW_ASPECT_VISIBLE, record.getDrawAspect());
assertEquals(ExOleObjAtom.TYPE_CONTROL, record.getType());
assertEquals(1, record.getObjID());
assertEquals(ExOleObjAtom.SUBTYPE_DEFAULT, record.getSubType());
assertEquals(2, record.getObjStgDataRef());
// the meaning is unknown
assertEquals(1283584, record.getOptions());
}

@Test

+ 7
- 7
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java View File

@@ -55,28 +55,28 @@ public final class TestFontCollection {
void testFonts() {
FontCollection fonts = new FontCollection(data, 0, data.length);
Record[] child = fonts.getChildRecords();
assertEquals(child.length, 1);
assertEquals(1, child.length);

FontEntityAtom fnt = (FontEntityAtom)child[0];
assertEquals(fnt.getFontName(), "Times New Roman");
assertEquals("Times New Roman", fnt.getFontName());
}

@Test
void testAddFont() {
FontCollection fonts = new FontCollection(data, 0, data.length);
HSLFFontInfo fi = fonts.addFont(HSLFFontInfoPredefined.TIMES_NEW_ROMAN);
assertEquals((int)fi.getIndex(), 0);
assertEquals(0, (int)fi.getIndex());
fi = fonts.addFont(new HSLFFontInfo("Helvetica"));
assertEquals((int)fi.getIndex(), 1);
assertEquals(1, (int)fi.getIndex());
fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL);
assertEquals((int)fi.getIndex(), 2);
assertEquals(2, (int)fi.getIndex());
//the font being added twice
fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL);
assertEquals((int)fi.getIndex(), 2);
assertEquals(2, (int)fi.getIndex());

// Font collection should contain 3 fonts
Record[] child = fonts.getChildRecords();
assertEquals(child.length, 3);
assertEquals(3, child.length);

// Check we get the right font name for the indicies
fi = fonts.getFontInfo(0);

+ 2
- 2
poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java View File

@@ -45,8 +45,8 @@ public final class TestTextRulerAtom {
@Test
void testReadRuler() {
TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
assertEquals(ruler.getNumberOfLevels(), 0);
assertEquals(ruler.getDefaultTabSize(), 0);
assertEquals(0, ruler.getNumberOfLevels());
assertEquals(0, ruler.getDefaultTabSize());

List<HSLFTabStop> tabStops = ruler.getTabStops();
assertNotNull(tabStops);

+ 1
- 1
poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java View File

@@ -102,7 +102,7 @@ public class TestExtractEmbeddedMSG {
expectedMessageDate.set(Calendar.MILLISECOND, 0);
assertEquals(expectedMessageDate.getTimeInMillis(), messageDate.getTimeInMillis());
// test variable length property
assertEquals(msg.getSubject(), "Test Attachment");
assertEquals("Test Attachment", msg.getSubject());
}

private POIFSFileSystem rebuildFromAttached(MAPIMessage attachedMsg) throws IOException {

+ 37
- 39
poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestPlexOfCps.java View File

@@ -26,53 +26,51 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public final class TestPlexOfCps {
private PlexOfCps _plexOfCps;
private HWPFDocFixture _hWPFDocFixture;
private PlexOfCps _plexOfCps;
private HWPFDocFixture _hWPFDocFixture;

@Test
void testWriteRead() {
_plexOfCps = new PlexOfCps(4);
@Test
void testWriteRead() {
_plexOfCps = new PlexOfCps(4);

int last = 0;
for (int x = 0; x < 110; x++)
{
byte[] intHolder = new byte[4];
int span = (int)(110.0f * Math.random());
LittleEndian.putInt(intHolder, 0, span);
_plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder));
last += span;
}
int last = 0;
for (int x = 0; x < 110; x++) {
byte[] intHolder = new byte[4];
int span = (int) (110.0f * Math.random());
LittleEndian.putInt(intHolder, 0, span);
_plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder));
last += span;
}

byte[] output = _plexOfCps.toByteArray();
_plexOfCps = new PlexOfCps(output, 0, output.length, 4);
int len = _plexOfCps.length();
assertEquals(len, 110);
byte[] output = _plexOfCps.toByteArray();
_plexOfCps = new PlexOfCps(output, 0, output.length, 4);
int len = _plexOfCps.length();
assertEquals(110, len);

last = 0;
for (int x = 0; x < len; x++)
{
GenericPropertyNode node = _plexOfCps.getProperty(x);
assertEquals(node.getStart(), last);
last = node.getEnd();
int span = LittleEndian.getInt(node.getBytes());
assertEquals(node.getEnd()-node.getStart(), span);
last = 0;
for (int x = 0; x < len; x++) {
GenericPropertyNode node = _plexOfCps.getProperty(x);
assertEquals(node.getStart(), last);
last = node.getEnd();
int span = LittleEndian.getInt(node.getBytes());
assertEquals(node.getEnd() - node.getStart(), span);
}
}
}

@BeforeEach
void setUp() throws Exception {
/**@todo verify the constructors*/
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
@BeforeEach
void setUp() throws Exception {
/* @todo verify the constructors*/
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);

_hWPFDocFixture.setUp();
}
_hWPFDocFixture.setUp();
}

@AfterEach
void tearDown() throws Exception {
_plexOfCps = null;
_hWPFDocFixture.tearDown();
@AfterEach
void tearDown() {
_plexOfCps = null;
_hWPFDocFixture.tearDown();

_hWPFDocFixture = null;
}
_hWPFDocFixture = null;
}

}

+ 22
- 24
poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestPictures.java View File

@@ -52,9 +52,8 @@ public final class TestPictures {
List<Picture> pics = doc.getPicturesTable().getAllPictures();

assertNotNull(pics);
assertEquals(pics.size(), 2);
for (int i = 0; i < pics.size(); i++) {
Picture pic = pics.get(i);
assertEquals(2, pics.size());
for (Picture pic : pics) {
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
}
@@ -289,7 +288,6 @@ public final class TestPictures {
assertEquals(0, plain8s);
}

@SuppressWarnings("deprecation")
@Test
void testCroppedPictures() {
HWPFDocument doc = openSampleFile("testCroppedPictures.doc");
@@ -334,40 +332,40 @@ public final class TestPictures {
}

@Test
void testPictureWithAlternativeText() {
HWPFDocument document = openSampleFile("Picture_Alternative_Text.doc");
PicturesTable pictureTable = document.getPicturesTable();
Picture picture = pictureTable.getAllPictures().get(0);
void testPictureWithAlternativeText() throws IOException {
try (HWPFDocument document = openSampleFile("Picture_Alternative_Text.doc")) {
PicturesTable pictureTable = document.getPicturesTable();
Picture picture = pictureTable.getAllPictures().get(0);

assertEquals("This is the alternative text for the picture.", picture.getDescription());
assertEquals("This is the alternative text for the picture.", picture.getDescription());
}
}

@Disabled("This bug is not fixed yet")
@Test
void test58804_1() throws Exception {
HWPFDocument docA = openSampleFile("58804_1.doc");

expectImages(docA, 1);

HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
try (HWPFDocument docA = openSampleFile("58804_1.doc")) {
expectImages(docA, 1);

try (OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) {
docB.write(out);
try (HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) {
docB.write(out);
expectImages(docB, 1);
}
}

expectImages(docB, 1);
}

@Disabled("This bug is not fixed yet")
@Test
void test58804() throws Exception {
HWPFDocument docA = openSampleFile("58804.doc");

expectImages(docA, 7);
void test58804() throws IOException {
try (HWPFDocument docA = openSampleFile("58804.doc")) {
expectImages(docA, 7);

HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
try (HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA)) {
expectImages(docB, 7);
}
}

expectImages(docB, 7);
}

private void expectImages(HWPFDocument docA, int expectedCount) {

+ 19
- 21
poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRange.java View File

@@ -64,33 +64,31 @@ public final class TestRange {

@Test
void testBug46817() throws IOException {
InputStream is = SAMPLES.openResourceAsStream( "Bug46817.doc" );
HWPFDocument hwpfDocument = new HWPFDocument( is );
is.close();
try (InputStream is = SAMPLES.openResourceAsStream("Bug46817.doc");
HWPFDocument hwpfDocument = new HWPFDocument(is)) {

final List<SEPX> sections = hwpfDocument.getSectionTable()
.getSections();
assertEquals( sections.size(), 1 );
final List<SEPX> sections = hwpfDocument.getSectionTable().getSections();
assertEquals( 1, sections.size() );

// whole document, including additional text from shape
SEPX sepx = sections.get( 0 );
assertEquals( sepx.getStart(), 0 );
assertEquals( sepx.getEnd(), 1428 );
// whole document, including additional text from shape
SEPX sepx = sections.get( 0 );
assertEquals( 0, sepx.getStart() );
assertEquals( 1428, sepx.getEnd() );

// only main range
Range range = hwpfDocument.getRange();
assertEquals( range.getStartOffset(), 0 );
assertEquals( range.getEndOffset(), 766 );
// only main range
Range range = hwpfDocument.getRange();
assertEquals( 0, range.getStartOffset() );
assertEquals( 766, range.getEndOffset() );

Paragraph lastInMainRange = range.getParagraph( range.numParagraphs() - 1);
assertTrue( lastInMainRange.getEndOffset() <= 766 );
Paragraph lastInMainRange = range.getParagraph( range.numParagraphs() - 1);
assertTrue( lastInMainRange.getEndOffset() <= 766 );

Section section = range.getSection( 0 );
assertTrue( section.getEndOffset() <= 766 );
Section section = range.getSection( 0 );
assertTrue( section.getEndOffset() <= 766 );

Paragraph lastInMainSection = section.getParagraph( section
Paragraph lastInMainSection = section.getParagraph( section
.numParagraphs() - 1);
assertTrue( lastInMainSection.getEndOffset() <= 766 );
hwpfDocument.close();
assertTrue( lastInMainSection.getEndOffset() <= 766 );
}
}
}

+ 1
- 1
poi/src/test/java/org/apache/poi/hpsf/basic/TestBasic.java View File

@@ -168,7 +168,7 @@ final class TestBasic {
final SummaryInformation si = (SummaryInformation)PropertySetFactory.create(is);
final List<Section> sections = si.getSections();
final Section s = sections.get(0);
assertEquals(s.getFormatID(), SummaryInformation.FORMAT_ID);
assertEquals(SummaryInformation.FORMAT_ID, s.getFormatID());
assertNotNull(s.getProperties());
assertEquals(17, s.getPropertyCount());
assertEquals("Titel", s.getProperty(PropertyIDMap.PID_TITLE));

+ 4
- 4
poi/src/test/java/org/apache/poi/hpsf/basic/TestEmptyProperties.java View File

@@ -141,13 +141,13 @@ final class TestEmptyProperties {
assertNotNull(s.getTemplate());
assertNotNull(s.getLastAuthor());
assertNotNull(s.getRevNumber());
assertEquals(s.getEditTime(), 0);
assertEquals(0, s.getEditTime());
assertNull(s.getLastPrinted());
assertNull(s.getCreateDateTime());
assertNull(s.getLastSaveDateTime());
assertEquals(s.getPageCount(), 0);
assertEquals(s.getWordCount(), 0);
assertEquals(s.getCharCount(), 0);
assertEquals(0, s.getPageCount());
assertEquals(0, s.getWordCount());
assertEquals(0, s.getCharCount());
assertNull(s.getThumbnail());
assertNull(s.getApplicationName());
}

BIN
poi/src/test/java9/module-info.class View File


Loading…
Cancel
Save