From 065537fb020edc945f3568625f5b7cfe022afe99 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 13 Dec 2021 17:48:47 +0000 Subject: [PATCH] add some tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895911 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ooxml/TestPOIXMLProperties.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLProperties.java b/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLProperties.java index c55ad25de4..b0c15b1340 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLProperties.java +++ b/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestPOIXMLProperties.java @@ -33,6 +33,7 @@ import java.util.Optional; import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; @@ -370,4 +371,28 @@ public final class TestPOIXMLProperties { assertEquals(propValue, wbBack.getProperties().getCustomProperties().getProperty(propName + "1").getLpwstr(), "Third prop check1"); } } + + @Test + void testSetInvalidCreatedDate() throws IOException { + try (XWPFDocument doc = new XWPFDocument()) { + CoreProperties cp = doc.getProperties().getCoreProperties(); + assertThrows(InvalidFormatException.class, () -> cp.setCreated("not a date")); + } + } + + @Test + void testSetInvalidLastPrintedDate() throws IOException { + try (XWPFDocument doc = new XWPFDocument()) { + CoreProperties cp = doc.getProperties().getCoreProperties(); + assertThrows(InvalidFormatException.class, () -> cp.setLastPrinted("not a date")); + } + } + + @Test + void testSetInvalidModifiedDate() throws IOException { + try (XWPFDocument doc = new XWPFDocument()) { + CoreProperties cp = doc.getProperties().getCoreProperties(); + assertThrows(InvalidFormatException.class, () -> cp.setModified("not a date")); + } + } }