### Question:
BundleClassLoaderAccessor { public static ClassLoader getClassLoader(final Bundle bundle, final AlternativeResourceLoader alternativeResourceLoader) { return new BundleClassLoader(bundle, alternativeResourceLoader); }  static ClassLoader getClassLoader(final Bundle bundle, final AlternativeResourceLoader alternativeResourceLoader); static Class<T> loadClass(final Bundle bundle, final String name);  }### Answer:
@Test public void testGetResource() throws IOException { Bundle bundle = mock(Bundle.class); when(bundle.getResource("foo.txt")).thenReturn(getClass().getClassLoader().getResource("foo.txt")); URL url = BundleClassLoaderAccessor.getClassLoader(bundle, null).getResource("foo.txt"); assertNotNull(url); }
@Test public void testGetResourceAsStream() throws IOException { Bundle bundle = mock(Bundle.class); when(bundle.getResource("foo.txt")).thenReturn(getClass().getClassLoader().getResource("foo.txt")); InputStream in = BundleClassLoaderAccessor.getClassLoader(bundle, null).getResourceAsStream("foo.txt"); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out); assertTrue(out.toByteArray().length > 0); }
@Test public void testGetResources() throws IOException { Bundle bundle = mock(Bundle.class); when(bundle.getResources("foo.txt")).thenReturn(getClass().getClassLoader().getResources("foo.txt")); Enumeration<URL> e = BundleClassLoaderAccessor.getClassLoader(bundle, null).getResources("foo.txt"); assertNotNull(e); assertTrue(e.hasMoreElements()); }
@Test public void testGetResourcesIfNull() throws IOException { Bundle bundle = mock(Bundle.class); when(bundle.getResources("foo.txt")).thenReturn(null); Enumeration<URL> e = BundleClassLoaderAccessor.getClassLoader(bundle, null).getResources("foo.txt"); assertNotNull(e); assertFalse(e.hasMoreElements()); }