compile 'commons-logging:commons-logging:1.2'
compile 'org.apache.commons:commons-collections4:4.2'
compile 'org.apache.commons:commons-math3:3.6.1'
+ compile 'javax.xml.bind:jaxb-api:2.3.0'
+ compile 'com.sun.xml.bind:jaxb-impl:2.3.0.1'
+ compile 'com.sun.xml.bind:jaxb-core:2.3.0.1'
+ compile 'javax.activation:activation:1.1.1'
testCompile 'junit:junit:4.12'
}
compile files('../../ooxml-lib/ooxml-security-1.1.jar')
testCompile 'junit:junit:4.12'
- testCompile 'org.mockito:mockito-core:2.13.0'
+ testCompile 'org.mockito:mockito-core:2.21.0'
testCompile 'org.xmlunit:xmlunit-core:2.5.1'
testCompile project(path: ':main', configuration: 'tests')
testCompile 'org.openjdk.jmh:jmh-core:1.19'
<property name="main.commons-math3.jar" location="${main.lib}/commons-math3-3.6.1.jar"/>
<property name="main.commons-math3.url"
value="${repository.m2}/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar"/>
+ <property name="main.xmlbind.jar" location="${main.lib}/jaxb-api-2.3.0.jar"/>
+ <property name="main.xmlbind.url"
+ value="${repository.m2}/maven2/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar"/>
+ <property name="main.xmlbind-impl.jar" location="${main.lib}/jaxb-impl-2.3.0.1.jar"/>
+ <property name="main.xmlbind-impl.url"
+ value="${repository.m2}/maven2/com/sun/xml/bind/jaxb-impl/2.3.0.1/jaxb-impl-2.3.0.1.jar"/>
+ <property name="main.xmlbind-core.jar" location="${main.lib}/jaxb-core-2.3.0.1.jar"/>
+ <property name="main.xmlbind-core.url"
+ value="${repository.m2}/maven2/com/sun/xml/bind/jaxb-core/2.3.0.1/jaxb-core-2.3.0.1.jar"/>
+ <property name="main.activation.jar" location="${main.lib}/activation-1.1.1.jar"/>
+ <property name="main.activation.url"
+ value="${repository.m2}/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar"/>
<!-- xml signature libs -->
<property name="dsig.xmlsec.jar" location="${compile.lib}/xmlsec-2.1.0.jar"/>
<pathelement location="${main.commons-codec.jar}"/>
<pathelement location="${main.commons-collections4.jar}"/>
<pathelement location="${main.commons-math3.jar}"/>
+ <pathelement location="${main.xmlbind.jar}"/>
+ <pathelement location="${main.xmlbind-impl.jar}"/>
+ <pathelement location="${main.xmlbind-core.jar}"/>
+ <pathelement location="${main.activation.jar}"/>
</path>
<!-- some libraries should only be required for compiling/running tests -->
<available file="${dsig.sl4j-api.jar}"/>
<available file="${main.commons-collections4.jar}"/>
<available file="${main.commons-math3.jar}"/>
+ <available file="${main.xmlbind.jar}"/>
+ <available file="${main.xmlbind-impl.jar}"/>
+ <available file="${main.xmlbind-core.jar}"/>
+ <available file="${main.activation.jar}"/>
<!-- we had some CI failures when the extracted files for JaCoCo were missing somehow... -->
<available file="${main.lib}/jacocoagent.jar"/>
<downloadfile src="${jacoco.url}" dest="${jacoco.zip}"/>
<downloadfile src="${main.commons-collections4.url}" dest="${main.commons-collections4.jar}"/>
<downloadfile src="${main.commons-math3.url}" dest="${main.commons-math3.jar}"/>
+ <downloadfile src="${main.xmlbind.url}" dest="${main.xmlbind.jar}"/>
+ <downloadfile src="${main.xmlbind-impl.url}" dest="${main.xmlbind-impl.jar}"/>
+ <downloadfile src="${main.xmlbind-core.url}" dest="${main.xmlbind-core.jar}"/>
+ <downloadfile src="${main.activation.url}" dest="${main.activation.jar}"/>
<unzip src="${jacoco.zip}" dest=".">
<patternset>
<include name="lib/*.jar"/>
<include name="commons-logging-*.jar"/>
<include name="commons-collections4-*.jar"/>
<include name="commons-math3-*.jar"/>
+ <include name="jaxb-api-*.jar"/>
+ <include name="jaxb-impl-*.jar"/>
+ <include name="jaxb-core-*.jar"/>
+ <include name="activation-*.jar"/>
<include name="junit-*.jar"/>
<include name="log4j-*.jar"/>
</fileset>
<auxClasspath path="${main.jmh.jar}"/>
<auxClasspath path="${main.jmhAnnotation.jar}"/>
<auxClasspath path="${main.ant.jar}" />
+ <auxClasspath path="${main.xmlbind.jar}" />
+ <auxClasspath path="${main.xmlbind-impl.jar}" />
+ <auxClasspath path="${main.xmlbind-core.jar}" />
+ <auxClasspath path="${main.activation.jar}" />
<sourcePath path="src/java" />
<sourcePath path="src/ooxml/java" />
<sourcePath path="src/scratchpad/src" />
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.3.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-core</artifactId>
+ <version>2.3.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.1.1</version>
+ </dependency>
</dependencies>
</project>
package org.apache.poi.openxml4j.opc;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
-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 static org.junit.Assert.fail;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PushbackInputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.TreeMap;
-import java.util.function.BiConsumer;
-import java.util.regex.Pattern;
-
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
+import org.apache.poi.UnsupportedFileFormatException;
import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.ooxml.POIXMLException;
-import org.apache.poi.UnsupportedFileFormatException;
import org.apache.poi.ooxml.extractor.ExtractorFactory;
+import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.mockito.Mockito;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PushbackInputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.TreeMap;
+import java.util.function.BiConsumer;
+import java.util.regex.Pattern;
+
+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 static org.junit.Assert.fail;
+
public final class TestPackage {
private static final POILogger logger = POILogFactory.getLogger(TestPackage.class);
*/
@Test
public void zipBombCreateAndHandle()
- throws IOException, EncryptedDocumentException, InvalidFormatException {
+ throws IOException, EncryptedDocumentException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(2500000);
try (ZipFile zipFile = ZipHelper.openZipFile(OpenXML4JTestDataSamples.getSampleFile("sample.xlsx"));
}
@Test
- public void zipBombCheckSizesWithinLimits() throws IOException, EncryptedDocumentException, InvalidFormatException {
+ public void zipBombCheckSizesWithinLimits() throws IOException, EncryptedDocumentException {
getZipStatsAndConsume((max_size, min_ratio) -> {
// use values close to, but within the limits
ZipSecureFile.setMinInflateRatio(min_ratio - 0.002);
}
@Test
- public void zipBombCheckSizesRatioTooSmall() throws IOException, EncryptedDocumentException, InvalidFormatException {
+ public void zipBombCheckSizesRatioTooSmall() throws IOException, EncryptedDocumentException {
expectedEx.expect(POIXMLException.class);
expectedEx.expectMessage("You can adjust this limit via ZipSecureFile.setMinInflateRatio()");
getZipStatsAndConsume((max_size, min_ratio) -> {
}
@Test
- public void zipBombCheckSizesSizeTooBig() throws IOException, EncryptedDocumentException, InvalidFormatException {
+ public void zipBombCheckSizesSizeTooBig() throws IOException, EncryptedDocumentException {
expectedEx.expect(POIXMLException.class);
expectedEx.expectMessage("You can adjust this limit via ZipSecureFile.setMaxEntrySize()");
getZipStatsAndConsume((max_size, min_ratio) -> {
});
}
- private void getZipStatsAndConsume(BiConsumer<Long,Double> ratioCon) throws IOException, InvalidFormatException {
+ private void getZipStatsAndConsume(BiConsumer<Long,Double> ratioCon) throws IOException {
// use a test file with a xml file bigger than 100k (ZipArchiveThresholdInputStream.GRACE_ENTRY_SIZE)
final File file = XSSFTestDataSamples.getSampleFile("poc-shared-strings.xlsx");
// bug 61381
@Test
- public void testTooShortFilterStreams() throws IOException, InvalidFormatException {
+ public void testTooShortFilterStreams() throws IOException {
File xssf = OpenXML4JTestDataSamples.getSampleFile("sample.xlsx");
File hssf = POIDataSamples.getSpreadSheetInstance().getFile("SampleSS.xls");
@Test(expected = InvalidFormatException.class)
public void testBug62592() throws Exception {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("62592.thmx");
- OPCPackage p = OPCPackage.open(is);
+ /*OPCPackage p =*/ OPCPackage.open(is);
}
@Test
@Test
public void testDoNotCloseStream() throws IOException {
- OutputStream os = Mockito.mock(OutputStream.class);
+ // up to JDK 10 we did use Mockito here, but OutputStream is
+ // an abstract class and fails mocking with some changes in JDK 11
+ // so we use a simple empty output stream implementation instead
+ OutputStream os = new OutputStream() {
+ @Override
+ public void write(int b) {
+ }
+
+ @Override
+ public void close() {
+ throw new IllegalStateException("close should not be called here");
+ }
+ };
+
try (XSSFWorkbook wb = new XSSFWorkbook()) {
wb.createSheet();
wb.write(os);
}
- verify(os, never()).close();
try (SXSSFWorkbook wb = new SXSSFWorkbook()) {
wb.createSheet();
wb.write(os);
}
- verify(os, never()).close();
}
package org.apache.poi.xslf.usermodel;
-import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import org.apache.poi.sl.draw.SLGraphics;
+import org.junit.Test;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
-import org.junit.Test;
-import org.mockito.AdditionalAnswers;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
+import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
+import static org.junit.Assert.assertEquals;
public class TestXSLFFreeformShape {
BufferedImage img = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics();
try {
- Graphics2D graphicsMock = Mockito.mock(Graphics2D.class, AdditionalAnswers.delegatesTo(graphics));
+ // previously we used Mockito here, but since JDK 11 mocking the Graphics2D does
+ // not work any longer
+ Graphics2D graphicsMock = new SLGraphics(new XSLFGroupShape(CTGroupShape.Factory.newInstance(), slide)) {
+ boolean called;
+
+ @Override
+ public void draw(Shape shape) {
+ if(called) {
+ throw new IllegalStateException("Should only be called once, but was called a second time");
+ }
+ called = true;
+
+ if(!(shape instanceof Path2D.Double)) {
+ throw new IllegalStateException("Expecting a shape of type Path2D.Double, but had " + shape.getClass());
+ }
+
+ Path2D.Double actual = (Path2D.Double) shape;
+ PathIterator pi = actual.getPathIterator(new AffineTransform());
+ comparePoint(pi, PathIterator.SEG_MOVETO, 100, 150);
+ pi.next();
+ comparePoint(pi, PathIterator.SEG_LINETO, 100, 300);
+
+ super.draw(shape);
+ }
+ };
slide.draw(graphicsMock);
-
- ArgumentCaptor<Path2D.Double> captor = ArgumentCaptor.forClass(Path2D.Double.class);
- verify(graphicsMock, times(1)).draw(captor.capture());
-
- Path2D.Double actual = captor.getValue();
- PathIterator pi = actual.getPathIterator(new AffineTransform());
- comparePoint(pi, PathIterator.SEG_MOVETO, 100, 150);
- pi.next();
- comparePoint(pi, PathIterator.SEG_LINETO, 100, 300);
} finally {
graphics.dispose();
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import java.awt.Color;
import java.io.IOException;
import org.apache.poi.sl.draw.DrawTextParagraph;
import org.junit.Test;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
/**
* @author Yegor Kozlov
}
@Test
- public void testCopyNullFontSize() throws IOException {
+ public void testCopyNullFontSize() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
XSLFTextShape sh = slide.createAutoShape();
XSLFTextRun r = sh.addNewTextParagraph().addNewTextRun();
- XSLFTextRun s = mock(XSLFTextRun.class);
- when(s.getFontSize()).thenReturn(null);
+
+ XSLFTextRun s = new XSLFTextRun(CTTextLineBreak.Factory.newInstance(),
+ new XSLFTextParagraph(CTTextParagraph.Factory.newInstance(),
+ new XSLFTextBox(CTShape.Factory.newInstance(), slide)));
r.copy(s);
}
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.TempFile;
+import org.junit.Ignore;
+import org.junit.Test;
-public final class TestDateFormatConverter extends TestCase {
+public final class TestDateFormatConverter {
private void outputLocaleDataFormats( Date date, boolean dates, boolean times, int style, String styleName ) throws Exception {
-
try (Workbook workbook = new HSSFWorkbook()) {
String sheetName;
if (dates) {
row.createCell(5).setCellValue(javaDateFormatPattern);
row.createCell(6).setCellValue(excelFormatPattern);
} catch (Exception e) {
- throw new RuntimeException("Failed for locale: " + locale + ", having locales: " +
- Arrays.toString(DateFormat.getAvailableLocales()), e);
+ // this can be removed after https://bugs.openjdk.java.net/browse/JDK-8209047 is available
+ // in JDK 11 ea > 26
+ if(locale.toString().startsWith("my") &&
+ e.getMessage().contains("Illegal pattern character 'B'") &&
+ System.getProperty("java.version").startsWith("11")) {
+ System.out.println("DateFormat.getDateTimeInstance() fails for Malaysian Locale on JDK 11, submitted bug report to Oracle");
+ continue;
+ }
+
+ throw new RuntimeException(
+ "Failed for locale: " + locale + " and style " + style + "\n" +
+ "Having locales: " + Arrays.toString(DateFormat.getAvailableLocales()), e);
}
}
}
}
+ @Test
public void testJavaDateFormatsInExcel() throws Exception {
Date date = new Date();
outputLocaleDataFormats(date, false, true, DateFormat.LONG, "Long" );
outputLocaleDataFormats(date, false, true, DateFormat.FULL, "Full" );
}
-
+
+ @Test
public void testJDK8EmptyLocale() {
// JDK 8 seems to add an empty locale-string to the list returned via DateFormat.getAvailableLocales()
// therefore we now cater for this special locale as well
DateFormatConverter.getPrefixForLocale(new Locale(""));
}
+ @Ignore("Fails on JDK 11, submitted as ID : 9056763")
+ @Test
+ public void testJDK11MyLocale() {
+ DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.forLanguageTag("my"));
+ }
}