DirectoryManagerFactory { public static DirectoryManager createDirectoryManager(Path path, boolean readOnly) throws IOException { try { return dmClass.getConstructor(Path.class, Boolean.class) .newInstance(path, readOnly); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException e) { throw new RuntimeException(e.toString(), e); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof IOException) { throw (IOException) e.getTargetException(); } else { throw new RuntimeException(e.getTargetException().toString(), e.getTargetException()); } } }  static void setDirectoryManagerClass(
			Class<? extends DirectoryManager> clazz); static DirectoryManager createDirectoryManager(Path path,
			boolean readOnly); static DirectoryManager createDirectoryManager(String directory,
			boolean readOnly);  }
@Test public void createDirectoryManagerString() throws IOException { Path path = Paths.get(System.getProperty("user.dir")); DirectoryManager dm = DirectoryManagerFactory.createDirectoryManager( System.getProperty("user.dir"), true); assertTrue(dm instanceof DirectoryManagerImpl); DirectoryManagerImpl dmi = (DirectoryManagerImpl) dm; assertTrue(dmi.readOnly); assertEquals(path, dmi.directory); }
@Test public void createDefaultDirectoryManagerPath() throws IOException { Path path = Paths.get(System.getProperty("user.dir")); DirectoryManager dm = DirectoryManagerFactory.createDirectoryManager( path, true); assertTrue(dm instanceof DirectoryManagerImpl); DirectoryManagerImpl dmi = (DirectoryManagerImpl) dm; assertTrue(dmi.readOnly); assertEquals(path, dmi.directory); }
@Test(expected = IOException.class) public void createDirectoryManagerIoException() throws IOException { DirectoryManagerFactory.createDirectoryManager( "/nonexisting-directory/123456789/hopefully", true); }