Modules { public void add(AddModuleRequest addModuleRequest) throws Exception { validate(addModuleRequest); final String moduleName = addModuleRequest.getModuleName(); final File moduleDir = getModulePath(moduleName, addModuleRequest.getSlot()); if (!moduleDir.mkdirs()) { throw new IllegalStateException("Failed to create directory [" + moduleDir.getAbsolutePath() + "]"); } File moduleXmlPath = new File(moduleDir, "module.xml"); try (Writer w = new OutputStreamWriter(new FileOutputStream(moduleXmlPath), "utf-8")) { writeModuleXml(w, addModuleRequest); } copyResources(addModuleRequest, moduleDir); } Modules(File modulesDir); static File findModulesDir(); void add(AddModuleRequest addModuleRequest); void remove(String moduleName, String slot);  }
@Test public void testAddBadModulesDir() throws Exception { File jbossHome = createTempDir("testValidate.jbossHome"); File modulesDir = new File(jbossHome, "modules"); Modules modules = new Modules(modulesDir); AddModuleRequest minimal = createMinimal(); Assert.assertFalse(modulesDir.exists()); try { modules.add(minimal); Assert.fail("Exception expected"); } catch (IllegalArgumentException expected) { } }