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; } } }
@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 shouldReturnNullWhenNoChildCanSupplyData() throws IOException { assertThat(this.testee.getData("unknown")).isNull(); }
@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); }
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; } } }