ClassPath(List<ClassPathRoot> roots) { this.root = new CompoundClassPathRoot(roots); }
public Collection<String> classNames() { return this.root.classNames(); }
public byte[] getClassData(final String classname) throws IOException { try (InputStream is = this.root.getData(classname)) { if (is != null) { return StreamUtil.streamToByteArray(is); } else { return null; } } }
public URL findResource(final String name) { try { return this.root.getResource(name); } catch (final IOException exception) { return null; } }
@Override public URL getResource(String name) throws MalformedURLException { try { return findRootForResource(name); } catch (final IOException exception) { return null; } }
public CompoundClassPathRoot(final List<ClassPathRoot> roots) { this.roots.addAll(wrapToAvoidIOOperations(roots)); }
public String getLocalClassPath() { return this.root.cacheLocation().get(); }
@Test public void shouldReturnResourcesFromChildren() throws IOException { when(this.child1.getResource(any(String.class))).thenReturn(null); final URL url = new URL("http://localhost"); when(this.child1.getResource(any(String.class))).thenReturn(url); assertThat(this.testee.getResource("Foo")).isSameAs(url); }
@Override public URL getResource(String name) throws MalformedURLException { try { return findRootForResource(name); } catch (final IOException exception) { return null; } }
public CompoundClassPathRoot(final List<ClassPathRoot> roots) { this.roots.addAll(wrapToAvoidIOOperations(roots)); }
public String getLocalClassPath() { return this.root.cacheLocation().get(); }
@Test public void shouldNotQueryHeavyRootsForClassesTheyDoNotContain() throws IOException { when(this.child1.classNames()).thenReturn(Collections.singletonList("Foo")); when(this.heavyChild.classNames()).thenReturn(Collections.singletonList("Heavy")); when(this.child2.classNames()).thenReturn(Collections.singletonList("Bar")); this.testee.getData("Bar"); verify(this.heavyChild,never()).getData("Bar"); this.testee.getData("Heavy"); verify(this.heavyChild).getData("Heavy"); }
@Test public void shouldReturnNullWhenNoChildCanSupplyResource() throws IOException { assertThat(this.testee.getResource("unknown")).isNull(); }
@Test public void shouldReturnNamesOfAllClassesKnownByChildren() { when(this.child1.classNames()).thenReturn(Collections.singletonList("Foo")); when(this.child2.classNames()).thenReturn(Collections.singletonList("Bar")); when(this.heavyChild.classNames()).thenReturn(Collections.singletonList("Heavy")); assertThat(this.testee.classNames()).containsOnly("Foo", "Bar", "Heavy"); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); this.testee = new CompoundClassPathRoot(Arrays.asList(this.child1,this.heavyChild, this.child2)); }
@Test public void shouldReturnNullWhenNoChildCanSupplyData() throws IOException { assertThat(this.testee.getData("unknown")).isNull(); }
public URL findResource(final String name) { try { return this.root.getResource(name); } catch (final IOException exception) { return null; } }
public Collection<String> classNames() { return this.root.classNames(); }
ClassPath(List<ClassPathRoot> roots) { this.root = new CompoundClassPathRoot(roots); }
@Test public void shouldReturnClassDataFromChildren() throws IOException { when(this.child1.getData(any(String.class))).thenReturn(null); final InputStream is = Mockito.mock(InputStream.class); when(this.child1.getData(any(String.class))).thenReturn(is); assertThat(this.testee.getData("Foo")).isSameAs(is); }