}
@SuppressWarnings("unchecked")
public void testClassLoaderDomainClassLoaders() throws Exception
{
ClassLoaderSystem system = createClassLoaderSystemWithModifiedBootstrap();
MBeanServer server = MBeanServerFactory.newMBeanServer();
server.registerMBean(system, CLASSLOADER_SYSTEM_OBJECT_NAME);
ClassLoaderDomain defaultDomain = system.getDefaultDomain();
ClassLoaderDomain domain = system.createAndRegisterDomain("test", ParentPolicy.BEFORE_BUT_JAVA_ONLY, defaultDomain);
MockClassLoaderPolicy a1 = createMockClassLoaderPolicy("a1");
a1.setPathsAndPackageNames(A.class);
RealClassLoader clA1 = (RealClassLoader) system.registerClassLoaderPolicy(domain, a1);
MockClassLoaderPolicy a2 = createMockClassLoaderPolicy("a2");
a2.setPathsAndPackageNames(A.class);
RealClassLoader clA2 = (RealClassLoader) system.registerClassLoaderPolicy(domain, a2);
MockClassLoaderPolicy b1 = createMockClassLoaderPolicy("b1");
b1.setPathsAndPackageNames(B.class);
RealClassLoader clB1 = (RealClassLoader) system.registerClassLoaderPolicy(domain, b1);
MockClassLoaderPolicy b2 = createMockClassLoaderPolicy("b2");
b2.setPaths(B.class);
RealClassLoader clB2 = (RealClassLoader) system.registerClassLoaderPolicy(domain, b2);
ObjectName testDomain = domain.getObjectName();
List<ObjectName> classLoaders = (List) server.invoke(testDomain, "listClassLoaders", null, null);
List<ObjectName> expected = Arrays.asList(clA1.getObjectName(), clA2.getObjectName(), clB1.getObjectName(), clB2.getObjectName());
assertEquals(expected, classLoaders);