diff options
author | Dominik Stadler <centic@apache.org> | 2018-08-23 20:23:20 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2018-08-23 20:23:20 +0000 |
commit | 3fea637adaa389f84a241fd395088aa206568920 (patch) | |
tree | d5d510113b2361fc125f9477115ff7b3b9658af9 /src/ooxml | |
parent | bcc68c5f2003d10485f837a1e9442511656882b3 (diff) | |
download | poi-3fea637adaa389f84a241fd395088aa206568920.tar.gz poi-3fea637adaa389f84a241fd395088aa206568920.zip |
Adjust for JDK 11 ea-26 build, need to add jaxb via normal jar dependency now as it was removed from the JDK
Also needed to remove a few uses of Mockito which fail now with certain abstract classes
Update to Mockito 2.21
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1838763 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
3 files changed, 89 insertions, 66 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java index ad7fe80c84..d649c515a7 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -17,46 +17,17 @@ 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; @@ -73,7 +44,6 @@ import org.apache.poi.sl.usermodel.SlideShow; 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; @@ -89,13 +59,39 @@ import org.junit.Ignore; 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); @@ -784,7 +780,7 @@ public final class TestPackage { */ @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")); @@ -884,7 +880,7 @@ public final class TestPackage { } @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); @@ -895,7 +891,7 @@ public final class TestPackage { } @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) -> { @@ -905,7 +901,7 @@ public final class TestPackage { } @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) -> { @@ -915,7 +911,7 @@ public final class TestPackage { }); } - 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"); @@ -980,7 +976,7 @@ public final class TestPackage { // 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"); @@ -1093,7 +1089,7 @@ public final class TestPackage { @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 @@ -1107,18 +1103,29 @@ public final class TestPackage { @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(); } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java index 1e3700aa3c..226368d149 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java @@ -17,13 +17,13 @@ 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; @@ -33,10 +33,8 @@ import java.awt.geom.Rectangle2D; 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 { @@ -78,17 +76,32 @@ 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(); } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java index 8e77f59f28..90f07e29c3 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java @@ -22,14 +22,15 @@ import static org.apache.poi.sl.TestCommonSL.sameColor; 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 @@ -104,14 +105,16 @@ public class TestXSLFTextRun { } @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); } |