@Test(expected = NoSuchElementException.class) public void testMultipleParentEnumerationNotFound() throws Exception { ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build(); Enumeration<URL> enumeration = classLoader.getResources(BAZ); assertThat(enumeration.hasMoreElements(), is(false)); enumeration.nextElement(); }
@Test @IntegrationRule.Enforce public void testMultipleParentEnumerationURL() throws Exception { ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build(); Enumeration<URL> foo = classLoader.getResources(FOO); assertThat(foo.hasMoreElements(), is(true)); assertThat(foo.nextElement(), is(fooUrl)); assertThat(foo.hasMoreElements(), is(false)); Enumeration<URL> bar = classLoader.getResources(BAR); assertThat(bar.hasMoreElements(), is(true)); assertThat(bar.nextElement(), is(barFirstUrl)); assertThat(bar.hasMoreElements(), is(true)); assertThat(bar.nextElement(), is(barSecondUrl)); assertThat(bar.hasMoreElements(), is(false)); Enumeration<URL> qux = classLoader.getResources(QUX); assertThat(qux.hasMoreElements(), is(true)); assertThat(qux.nextElement(), is(quxUrl)); assertThat(qux.hasMoreElements(), is(false)); }
@Before public void setUp() throws Exception { doReturn(Foo.class).when(first).loadClass(FOO); doReturn(BarFirst.class).when(first).loadClass(BAR); when(first.loadClass(QUX)).thenThrow(new ClassNotFoundException()); when(first.loadClass(BAZ)).thenThrow(new ClassNotFoundException()); doReturn(BarSecond.class).when(second).loadClass(BAR); doReturn(Qux.class).when(second).loadClass(QUX); when(second.loadClass(BAZ)).thenThrow(new ClassNotFoundException()); fooUrl = new URL(SCHEME + FOO); barFirstUrl = new URL(SCHEME + BAR); barSecondUrl = new URL(SCHEME + BAZ); quxUrl = new URL(SCHEME + QUX); when(first.getResource(FOO)).thenReturn(fooUrl); when(first.getResource(BAR)).thenReturn(barFirstUrl); when(second.getResource(BAR)).thenReturn(barSecondUrl); when(second.getResource(QUX)).thenReturn(quxUrl); when(first.getResources(FOO)).thenReturn(new SingleElementEnumeration(fooUrl)); when(first.getResources(BAR)).thenReturn(new SingleElementEnumeration(barFirstUrl)); when(second.getResources(BAR)).thenReturn(new SingleElementEnumeration(barSecondUrl)); when(second.getResources(QUX)).thenReturn(new SingleElementEnumeration(quxUrl)); }