### Question:
ContextClassLoaderSwitchingUtil { public static void runInContext(ClassLoader newClassLoader, Runnable runnable) { ClassLoaderStack.push(newClassLoader); try { runnable.run(); } finally { ClassLoaderStack.pop(); } }  static void runInContext(ClassLoader newClassLoader, Runnable runnable);  }### Answer:
@Test public void testSwitchClassLoader() { ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); ContextClassLoaderSwitchingUtil.runInContext(newLoader, new Runnable() { public void run() { assertEquals(newLoader, Thread.currentThread().getContextClassLoader()); newLoader.getResource("test"); } }); assertEquals(currentLoader, Thread.currentThread().getContextClassLoader()); verify(newLoader).getResource("test"); }
@Test public void testSwitchClassLoaderMultiple() { ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); ContextClassLoaderSwitchingUtil.runInContext(newLoader, new Runnable() { public void run() { assertEquals(newLoader, Thread.currentThread().getContextClassLoader()); newLoader.getResource("test"); final ClassLoader innerLoader = mock(ClassLoader.class); ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); ContextClassLoaderSwitchingUtil.runInContext(innerLoader, new Runnable() { public void run() { assertEquals(innerLoader, Thread.currentThread().getContextClassLoader()); innerLoader.getResource("test"); } }); assertEquals(currentLoader, Thread.currentThread().getContextClassLoader()); verify(newLoader).getResource("test"); } }); assertEquals(currentLoader, Thread.currentThread().getContextClassLoader()); verify(newLoader).getResource("test"); }