add test coverage for WorkbookFactory.create(File file, String password, Boolean readOnly) when file does not exists

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737917 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-06 05:15:15 +00:00
parent bed6a46d10
commit f9c74888e3

View File

@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.FileNotFoundException;
import org.apache.poi.EmptyFileException; import org.apache.poi.EmptyFileException;
import org.apache.poi.EncryptedDocumentException; import org.apache.poi.EncryptedDocumentException;
@ -364,4 +365,21 @@ public final class TestWorkbookFactory {
} catch (final EmptyFileException expected) {} } catch (final EmptyFileException expected) {}
emptyFile.delete(); emptyFile.delete();
} }
/**
* Check that a helpful exception is raised on a non-existing file
*/
@Test
public void testNonExistantFile() throws Exception {
File nonExistantFile = new File("notExistantFile");
assertFalse(nonExistantFile.exists());
try {
WorkbookFactory.create(nonExistantFile, "password", true);
fail("Should not be able to create for a non-existant file");
} catch (final FileNotFoundException e) {
// expected
}
}
} }