- // Restore the original system property
- if (oldProperty != null) {
- System.setProperty(systemKey, oldProperty);
- } else {
- System.clearProperty(systemKey);
- }
+ }
+
+ @Test
+ public void testException() throws FactoryException, PAPException, IOException {
+ Properties props = new Properties();
+ File myFolder = folder.newFolder("idontexist");
+ props.setProperty(StdEngine.PROP_PAP_REPO, myFolder.getAbsolutePath());
+ StdEngineFactory factory = new StdEngineFactory();
+ assertNotNull(factory.newEngine(props));
+
+ //
+ //
+ //
+ myFolder.setReadOnly();
+ assertThatExceptionOfType(PAPException.class).isThrownBy(() ->
+ factory.newEngine(props)
+ );
+
+ //
+ //
+ //
+ File myFile = folder.newFile("iamafile");
+ props.setProperty(StdEngine.PROP_PAP_REPO, myFile.getAbsolutePath());
+ assertThatExceptionOfType(PAPException.class).isThrownBy(() ->
+ factory.newEngine(props)
+ );
+
+ //
+ //
+ //
+ props.setProperty(StdEngine.PROP_PAP_REPO, myFolder.getAbsolutePath() + "/badparent/dontexist");
+ assertNull(factory.newEngine(props));
+
+ //
+ //
+ //
+ System.setProperty(StdEngine.PROP_PAP_REPO, myFolder.getAbsolutePath() + "/badparent/dontexist");
+
+ assertNull(factory.newEngine());
+