### Question:
ClassManager { public Class<?> getServiceClass(ServiceNameVersion service) throws ClassLoaderException { ServiceClassLoader cl = registeredLoaders.get(service); if (cl == null) { try { registerService(service); cl = registeredLoaders.get(service); } catch (LibraryNotFoundException e) { System.err.println("No library found for " + service + "! Trying default classpath. This should not happen in a productive environment!"); try { return this.platformLoader.loadClass(service.getName()); } catch (ClassNotFoundException e2) { throw e; } } } try { return cl.loadClass(service.getName()); } catch (ClassNotFoundException e) { throw new LibraryNotFoundException( "The library for " + service + " could be loaded, but the class is not available!", e); } } ClassManager(Repository repository, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(Repository[] repositories, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(List<Repository> repositories, ClassLoader platformLoader, ClassLoaderPolicy policy); void registerService(ServiceNameVersion serviceIdentifier); void unregisterService(ServiceNameVersion service); Class<?> getServiceClass(ServiceNameVersion service); static final String getPackageName(String className); void addRepository(Repository repository);  }### Answer:
@Test public void testServiceClassLoading() throws ClassLoaderException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { ClassManager testee = new ClassManager(new FileSystemRepository("export/jars/"), ClassLoader.getSystemClassLoader(), new DefaultPolicy()); Class<?> cl = testee.getServiceClass(ServiceNameVersion.fromString("i5.las2peer.classLoaders.testPackage2.UsingCounter@1.0")); assertFalse(cl.getClassLoader().equals(ClassLoader.getSystemClassLoader())); Method m = cl.getDeclaredMethod("countCalls"); Object result = m.invoke(null); result = m.invoke(null); assertEquals(-2, ((Integer) result).intValue()); Class<?> cl1 = testee.getServiceClass(new ServiceNameVersion("i5.las2peer.testServices.testPackage1.TestService", "1.0")); Class<?> cl2 = testee.getServiceClass(new ServiceNameVersion("i5.las2peer.testServices.testPackage1.TestService", "1.1")); Method m1 = cl1.getDeclaredMethod("getVersionStatic"); Method m2 = cl2.getDeclaredMethod("getVersionStatic"); assertEquals(m1.invoke(null), 100); assertEquals(m2.invoke(null), 110); }
@Test public void testMultipleServiceClassLoading() throws ClassLoaderException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { ClassManager testee = new ClassManager(new FileSystemRepository("export/jars/"), ClassLoader.getSystemClassLoader(), new DefaultPolicy()); Class<?> cl1 = testee.getServiceClass(new ServiceNameVersion("i5.las2peer.classLoaders.testPackage2.UsingCounter", "1.0")); Class<?> cl2 = testee.getServiceClass(new ServiceNameVersion("i5.las2peer.classLoaders.testPackage2.UsingCounter", "1.0")); assertFalse(cl1.getClassLoader().equals(ClassLoader.getSystemClassLoader())); assertFalse(cl2.getClassLoader().equals(ClassLoader.getSystemClassLoader())); assertSame(cl1, cl2); }