server.registerMBean(system, CLASSLOADER_SYSTEM_OBJECT_NAME);
system.getDefaultDomain().setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
MockClassLoaderPolicy test = createMockClassLoaderPolicy("test");
test.setPathsAndPackageNames(A.class, B.class);
RealClassLoader cl = (RealClassLoader) system.registerClassLoaderPolicy(test);
ObjectName testObjectName = cl.getObjectName();
Set<String> loadedClasses = (Set) server.invoke(testObjectName, "listLoadedClasses", null, null);
assertFalse(loadedClasses.contains(A.class.getName()));
Class<?> expected = ((ClassLoader) cl).loadClass(A.class.getName());
assertEquals(expected, server.invoke(testObjectName, "loadClass", new Object[] { A.class.getName() }, new String[] { String.class.getName() }));
loadedClasses = (Set) server.invoke(testObjectName, "listLoadedClasses", null, null);
assertTrue(loadedClasses.contains(A.class.getName()));
assertEquals(cl.getObjectName(), server.invoke(testObjectName, "findClassLoaderForClass", new Object[] { A.class.getName() }, new String[] { String.class.getName() }));
assertNull(server.invoke(testObjectName, "findClassLoaderForClass", new Object[] { Object.class.getName() }, new String[] { String.class.getName() }));
String resourceName = ClassLoaderUtils.classNameToPath(B.class.getName());
Set<String> loadedResourceNames = (Set) server.invoke(testObjectName, "listLoadedResourceNames", null, null);
assertFalse(loadedResourceNames.contains(resourceName));