use of org.mule.runtime.module.artifact.api.classloader.ParentOnlyLookupStrategy.PARENT_ONLY in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentOnlyLookupAndFails.
@Test
public void usesParentOnlyLookupAndFails() throws Exception {
ClassLoader parent = mock(ClassLoader.class);
final ClassNotFoundException thrownException = new ClassNotFoundException("ERROR");
when(parent.loadClass(TEST_CLASS_NAME)).thenThrow(thrownException);
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_ONLY);
expected.expect(CompositeClassNotFoundException.class);
expected.expectMessage(startsWith("Cannot load class '" + TEST_CLASS_NAME + "': [" + lineSeparator() + "\t" + "ERROR]"));
expected.expect(expressionMatches((e) -> ((CompositeClassNotFoundException) e).getExceptions(), contains(sameInstance(thrownException))));
FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
ext.loadClass(TEST_CLASS_NAME);
}
Aggregations