@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); }
@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 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 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); }
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); }
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);  }