@Test public void callerContextDifferentFromRequestedClassLoaderReturnsCurrentClassLoader() { ServletContext context = mock(ServletContext.class); when(context.getMajorVersion()).thenReturn(3); when(context.getClassLoader()).thenThrow(new SecurityException("getClassLoader")); WebBasedClasspathResolver resolver = new WebBasedClasspathResolver(context); assertEquals(resolver.getClassLoader(), Thread.currentThread().getContextClassLoader()); }
public ClassLoader getClassLoader() { if (servletContext.getMajorVersion() == 3) { try { return servletContext.getClassLoader(); } catch (SecurityException e) { logger.error("Could not get class loader from servlet context. " + "Using current thread class loader...", e); } } return Thread.currentThread().getContextClassLoader(); }
WebBasedClasspathResolver implements ClasspathResolver { public ClassLoader getClassLoader() { if (servletContext.getMajorVersion() == 3) { try { return servletContext.getClassLoader(); } catch (SecurityException e) { logger.error("Could not get class loader from servlet context. " + "Using current thread class loader...", e); } } return Thread.currentThread().getContextClassLoader(); } }
WebBasedClasspathResolver implements ClasspathResolver { public ClassLoader getClassLoader() { if (servletContext.getMajorVersion() == 3) { try { return servletContext.getClassLoader(); } catch (SecurityException e) { logger.error("Could not get class loader from servlet context. " + "Using current thread class loader...", e); } } return Thread.currentThread().getContextClassLoader(); } WebBasedClasspathResolver(ServletContext servletContext); }
WebBasedClasspathResolver implements ClasspathResolver { public ClassLoader getClassLoader() { if (servletContext.getMajorVersion() == 3) { try { return servletContext.getClassLoader(); } catch (SecurityException e) { logger.error("Could not get class loader from servlet context. " + "Using current thread class loader...", e); } } return Thread.currentThread().getContextClassLoader(); } WebBasedClasspathResolver(ServletContext servletContext); ClassLoader getClassLoader(); URL findWebInfClassesLocation(); List<String> findBasePackages(); }
WebBasedClasspathResolver implements ClasspathResolver { public ClassLoader getClassLoader() { if (servletContext.getMajorVersion() == 3) { try { return servletContext.getClassLoader(); } catch (SecurityException e) { logger.error("Could not get class loader from servlet context. " + "Using current thread class loader...", e); } } return Thread.currentThread().getContextClassLoader(); } WebBasedClasspathResolver(ServletContext servletContext); ClassLoader getClassLoader(); URL findWebInfClassesLocation(); List<String> findBasePackages();  }