mirror of https://github.com/apache/poi.git
IDE warnings, slightly more tests and fix test to not leave a modified file behind
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1844894 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a8fd70ec7f
commit
960cbb7714
|
@ -83,9 +83,7 @@ public final class TestOPCComplianceCoreProperties {
|
||||||
try {
|
try {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
||||||
pkg = OPCPackage.open(is);
|
pkg = OPCPackage.open(is);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException | IOException e) {
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
pkg.revert();
|
pkg.revert();
|
||||||
|
@ -151,9 +149,7 @@ public final class TestOPCComplianceCoreProperties {
|
||||||
OPCPackage pkg;
|
OPCPackage pkg;
|
||||||
try {
|
try {
|
||||||
pkg = OPCPackage.open(is);
|
pkg = OPCPackage.open(is);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException | IOException e) {
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
URI partUri = createURI("/docProps/core2.xml");
|
URI partUri = createURI("/docProps/core2.xml");
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.poi.EmptyFileException;
|
import org.apache.poi.EmptyFileException;
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
|
@ -109,6 +110,13 @@ public final class TestWorkbookFactory {
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
assertCloseDoesNotModifyFile(xls, wb);
|
assertCloseDoesNotModifyFile(xls, wb);
|
||||||
|
|
||||||
|
wb = WorkbookFactory.create(
|
||||||
|
new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)).getRoot()
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
|
assertCloseDoesNotModifyFile(xls, wb);
|
||||||
|
|
||||||
// Package -> xssf
|
// Package -> xssf
|
||||||
wb = XSSFWorkbookFactory.create(
|
wb = XSSFWorkbookFactory.create(
|
||||||
OPCPackage.open(
|
OPCPackage.open(
|
||||||
|
@ -403,15 +411,15 @@ public final class TestWorkbookFactory {
|
||||||
assertTrue(altXLS.exists());
|
assertTrue(altXLS.exists());
|
||||||
assertTrue(altXLSX.exists());
|
assertTrue(altXLSX.exists());
|
||||||
|
|
||||||
try (Workbook wb = WorkbookFactory.create(altXLS)) {
|
Workbook wb = WorkbookFactory.create(altXLS);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
}
|
closeOrRevert(wb);
|
||||||
|
|
||||||
try (Workbook wb = WorkbookFactory.create(altXLSX)) {
|
wb = WorkbookFactory.create(altXLSX);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
}
|
closeOrRevert(wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestFile extends File {
|
private static class TestFile extends File {
|
||||||
|
@ -425,12 +433,24 @@ public final class TestWorkbookFactory {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEmpty() throws Exception {
|
public void testCreateEmpty() throws Exception {
|
||||||
try (Workbook wb = WorkbookFactory.create(false)) {
|
Workbook wb = WorkbookFactory.create(false);
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
}
|
closeOrRevert(wb);
|
||||||
|
|
||||||
try (Workbook wb = WorkbookFactory.create(true)) {
|
wb = WorkbookFactory.create(true);
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
closeOrRevert(wb);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidFormatException() {
|
||||||
|
String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
|
||||||
|
try {
|
||||||
|
WorkbookFactory.create(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename));
|
||||||
|
fail("Expecting an Exception for this document");
|
||||||
|
} catch (IOException e) {
|
||||||
|
// expected here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue