@Override public InputStream getData(final String name) throws IOException { for (final ClassPathRoot each : this.roots) { final InputStream is = each.getData(name); if (is != null) { return is; } } return null; }
@Override public InputStream getData(String name) throws IOException { final Collection<String> names = classNames(); if (!names.contains(ClassName.fromString(name).asJavaName())) { return null; } return this.child.getData(name); }
@Test public void shouldReturnBytesFromClasspathInputStream() throws IOException { final InputStream stream = Mockito.mock(InputStream.class); when(this.firstComponent.getData(any(String.class))).thenReturn(stream); when(stream.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1); this.testee.getClassData("foo"); verify(stream).read(any(byte[].class), anyInt(), anyInt()); verify(stream).close(); }
@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); }
@Override public InputStream getData(final String name) throws IOException { for (final ClassPathRoot each : this.roots) { final InputStream is = each.getData(name); if (is != null) { return is; } } return null; }
@Override public InputStream getData(String name) throws IOException { final Collection<String> names = classNames(); if (!names.contains(ClassName.fromString(name).asJavaName())) { return null; } return this.child.getData(name); }