### Question:
FallbackResourceLoader implements ResourceLoader { @Override public Optional<InputStream> load(final String source) throws IOException { for (ResourceLoader loader : loaders) { final Optional<InputStream> resource = loader.load(source); if (resource.isPresent()) { return resource; } } return Optional.empty(); } FallbackResourceLoader(final ResourceLoader... loaders); @Override Optional<InputStream> load(final String source);  }### Answer:
@Test public void shouldLoadFromFirstLoaderIfBothCouldLoad() throws Exception { final InputStream result1 = new ByteArrayInputStream(new byte[1]); final InputStream result2 = new ByteArrayInputStream(new byte[2]); when(loader1.load(SOURCE)).thenReturn(Optional.of(result1)); when(loader2.load(SOURCE)).thenReturn(Optional.of(result2)); assertThat(fallbackLoader.load(SOURCE)).containsSame(result1); verifyNoInteractions(loader2); }
@Test public void shouldLoadFromSecondLoaderIfFirstCouldNotLoad() throws Exception { final InputStream result2 = new ByteArrayInputStream(new byte[2]); when(loader2.load(SOURCE)).thenReturn(Optional.of(result2)); assertThat(fallbackLoader.load(SOURCE)).containsSame(result2); }
@Test public void shouldReturnEmptyIfNoLoaderCanLoad() throws Exception { assertThat(fallbackLoader.load(SOURCE)).isEmpty(); }