ConvertUtils.register((Converter)newFloatConverter, Float.TYPE);
// After registering a custom converter, lookup should return
// it back to us. We'll try this lookup again with a different
// context-classloader set, and shouldn't see it
Converter componentConverter = ConvertUtils.lookup(Float.TYPE);
assertTrue(componentConverter.getClass().getClassLoader() == componentLoader);
newFloatConverter = null;
}
Thread.currentThread().setContextClassLoader(origContextClassLoader);
// Because the context classloader has been reset, we shouldn't
// see the custom registered converter here...
Converter sharedConverter = ConvertUtils.lookup(Float.TYPE);
assertFalse(sharedConverter.getClass().getClassLoader() == componentLoader);
// and here we should see it again
Thread.currentThread().setContextClassLoader(componentLoader);
{
Converter componentConverter = ConvertUtils.lookup(Float.TYPE);
assertTrue(componentConverter.getClass().getClassLoader() == componentLoader);
}
Thread.currentThread().setContextClassLoader(origContextClassLoader);
// Emulate a container "undeploying" the component. This should
// make component loader available for garbage collection (we hope)
WeakReference weakRefToComponent = new WeakReference(componentLoader);