From 197458b30cb890da3ba92727da2d03c291da5043 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 15 Mar 2016 12:37:01 +0000 Subject: [PATCH] One final invalid file type check git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735071 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/openxml4j/opc/TestPackage.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 9cde41486..0834ad223 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -41,6 +41,8 @@ import java.util.List; import java.util.TreeMap; import java.util.regex.Pattern; import java.util.zip.ZipEntry; +import java.util.zip.ZipError; +import java.util.zip.ZipException; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -731,7 +733,20 @@ public final class TestPackage { } // Plain Text - Stream + try { + OPCPackage.open(files.openResourceAsStream("SampleSS.txt")); + fail("Shouldn't be able to open Plain Text"); + } catch (NotOfficeXmlFileException e) { + assertTrue(e.getMessage().indexOf("No valid entries or contents found") > -1); + assertTrue(e.getMessage().indexOf("not a valid OOXML") > -1); + } // Plain Text - File + try { + OPCPackage.open(files.getFile("SampleSS.txt")); + fail("Shouldn't be able to open Plain Text"); + } catch (InvalidOperationException e) { + // Unhelpful low-level error, sorry + } } @Test(expected=IOException.class)