{
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 a = createMockClassLoaderPolicy("a");
a.setPathsAndPackageNames(A.class);
RealClassLoader clA = (RealClassLoader) system.registerClassLoaderPolicy(domain.getName(), a);
MockClassLoaderPolicy b = createMockClassLoaderPolicy("b");
b.setPathsAndPackageNames(B.class);
RealClassLoader clB = (RealClassLoader) system.registerClassLoaderPolicy(domain.getName(), b);
MockClassLoaderPolicy test = createMockClassLoaderPolicy("test");
test.setImportAll(true);
test.setDelegates(Arrays.asList(a.getExported(), b.getExported()));
test.setPathsAndPackageNames(A.class, B.class);
RealClassLoader cl = (RealClassLoader) system.registerClassLoaderPolicy(domain, test);
ObjectName testObjectName = cl.getObjectName();
assertEquals(domain.getObjectName(), server.getAttribute(testObjectName, "ClassLoaderDomain"));
assertEquals("test", server.getAttribute(testObjectName, "Name"));
assertTrue((Boolean) server.getAttribute(testObjectName, "ImportAll"));
assertTrue((Boolean) server.getAttribute(testObjectName, "Valid"));
Set<String> expectedPackages = makeSet(A.class.getPackage().getName(), B.class.getPackage().getName());
assertEquals(expectedPackages, server.invoke(testObjectName, "listExportedPackages", null, null));