@org.junit.Test
	public void testLoadDirScan()
		throws ClassNotFoundException, java.io.IOException, java.net.URISyntaxException, NoSuchMethodException,
			IllegalAccessException, java.lang.reflect.InvocationTargetException
	{
		boolean hackflag = DynLoader.CLDHACK;
		DynLoader.setField(DynLoader.class, "CLDHACK", Boolean.valueOf(false), null);

		// populate a directory tree which we've ensured was previously empty
		FileOps.deleteDirectory(workdir);
		java.io.File dh = new java.io.File(workdir);
		org.junit.Assert.assertFalse(dh.exists());
		FileOps.ensureDirExists(workdir+"/dir1");
		FileOps.ensureDirExists(workdir+"/dir2");
		FileOps.ensureDirExists(workdir+"/dir3");
		FileOps.ensureDirExists(workdir+"/dir4");
		FileOps.writeTextFile(workdir+"/file1.jar", "jar1");
		FileOps.writeTextFile(workdir+"/file2.txt", "txt2");
		FileOps.writeTextFile(workdir+"/dir1/file11.jar", "jar11");
		FileOps.writeTextFile(workdir+"/dir2/file21.jar", "jar21");
		FileOps.writeTextFile(workdir+"/dir2/file22.jar", "jar22");
		FileOps.writeTextFile(workdir+"/dir2/file23.txt", "txt23");
		FileOps.writeTextFile(workdir+"/dir2/file24", "notype24");
		FileOps.writeTextFile(workdir+"/dir3/file31.jar", "jar31");
		FileOps.writeTextFile(workdir+"/dir4/file41.txt", "jar41");

		// Construct a path which consists of a mixture of simple directory paths, directories to be scanned
		// and individual files.
		// Then load it into the classpath - the subsequent tests have no dependence on the hack-flag setting.
		String loadpath = workdir+"/"+DynLoader.CPDLM
				+workdir+"/dir1"+DynLoader.CPDLM
				+workdir+"/dir2/"+DynLoader.CPDLM
				+workdir+"/dir3/file31.jar"+DynLoader.CPDLM
				+workdir+"/dir4/"+DynLoader.CPDLM
				+".";
		java.util.List<java.net.URL> newcp = DynLoader.load(loadpath);
		org.junit.Assert.assertTrue(newcp != null && newcp.size() == 6);
		String pos2 = workdir+"/dir2/file21.jar";
		String pos3 = workdir+"/dir2/file22.jar";
		if (!comparePath(pos2, newcp.get(2))) {
			// dir2 contents are arbitrarily sorted, so if the 2 JARs aren't in the one order, they will be in the other
			String tmp = pos2;
			pos2 = pos3;
			pos3 = tmp;
		}
		assertPath(workdir+"/file1.jar", newcp.get(0));
		assertPath(workdir+"/dir1", newcp.get(1));
		assertPath(pos2, newcp.get(2));
		assertPath(pos3, newcp.get(3));
		assertPath(workdir+"/dir3/file31.jar", newcp.get(4));
		assertPath(".", newcp.get(5));

		if (!hackflag) {
			DynLoader.unload(DynLoader.getClassLoader());
			// now test scanning a specific directory only
			newcp = DynLoader.loadFromDir(workdir+"/");
			org.junit.Assert.assertTrue(newcp==null?"Null":newcp.toString(), newcp != null && newcp.size() == 1);
			assertPath(workdir+"/file1.jar", newcp.get(0));
			if (!hackflag) DynLoader.unload(DynLoader.getClassLoader());
		}

		// we're now finished with out temp work area
		FileOps.deleteDirectory(workdir);
		org.junit.Assert.assertFalse(dh.exists());

		// now test loading from non-existent directory - disable hack so we can test classloader state as well
		boolean prevhack = DynLoader.CLDHACK;
		DynLoader.setField(DynLoader.class, "CLDHACK", Boolean.valueOf(false), null);
		ClassLoader cld = DynLoader.getClassLoader();
		newcp = DynLoader.loadFromDir(workdir);
		org.junit.Assert.assertTrue(newcp == null || newcp.size() == 0);
		org.junit.Assert.assertTrue(DynLoader.getClassLoader() == cld);

		// not actually a directory-scan, but this is a good place to test loading a file we know can't exist
		newcp = DynLoader.load(workdir+"/nonsuch.jar");
		org.junit.Assert.assertTrue(newcp == null || newcp.size() == 0);
		org.junit.Assert.assertTrue(DynLoader.getClassLoader() == cld);
		DynLoader.setField(DynLoader.class, "CLDHACK", Boolean.valueOf(prevhack), null);
	}