a1.setPathsAndPackageNames(A.class);
KernelControllerContext contextA1 = install(a1);
try
{
ClassLoader clA1 = assertClassLoader(contextA1);
Module moduleA1 = assertModule(contextA1);
assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a", "2.0.0");
a2.getCapabilities().addCapability(factory.createModule("ModuleA", "2.0.0"));
a2.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
a2.setPathsAndPackageNames(A.class);
KernelControllerContext contextA2 = install(a2);
try
{
ClassLoader clA2 = assertClassLoader(contextA2);
Module moduleA2 = assertModule(contextA2);
assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
assertEquals(moduleA2, ClassLoading.getModuleForClassLoader(clA2));
MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
b.getRequirements().addRequirement(factory.createRequireModule("ModuleA", new VersionRange("2.0.0")));
b.setPathsAndPackageNames(B.class);
KernelControllerContext contextB = install(b);
try
{
ClassLoader clB = assertClassLoader(contextB);
Module moduleB = assertModule(contextB);
Class<?> result = moduleB.loadClass(A.class.getName());
assertEquals(clA2, result.getClassLoader());
Module other = moduleB.getModuleForClass(A.class.getName());
assertEquals(moduleA2, other);
assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
assertEquals(moduleA2, ClassLoading.getModuleForClassLoader(clA2));
assertEquals(moduleB, ClassLoading.getModuleForClassLoader(clB));