@Test public void testMultipleParentClassLoading() throws Exception { ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build(); assertThat(classLoader.loadClass(FOO), CoreMatchers.<Class<?>>is(Foo.class)); assertThat(classLoader.loadClass(BAR), CoreMatchers.<Class<?>>is(BarFirst.class)); assertThat(classLoader.loadClass(QUX), CoreMatchers.<Class<?>>is(Qux.class)); verify(first).loadClass(FOO); verify(first).loadClass(BAR); verify(first).loadClass(QUX); verifyNoMoreInteractions(first); verify(second).loadClass(QUX); verifyNoMoreInteractions(second); }
@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)); }