@Test void provide_with_one_of_provider_throws_exception_test() { MetadataStatementsProvider providerA = mock(MetadataStatementsProvider.class); Map<AAGUID, Set<MetadataStatement>> mapA = new HashMap<>(); mapA.put(new AAGUID("df495bdc-223a-429d-9f0e-ebfa29155812"), new HashSet<>()); when(providerA.provide()).thenReturn(mapA); MetadataStatementsProvider providerB = mock(MetadataStatementsProvider.class); when(providerB.provide()).thenThrow(new RuntimeException("unexpected error")); AggregatingMetadataStatementsProvider target = new AggregatingMetadataStatementsProvider(Arrays.asList(providerA, providerB)); assertThat(target.provide()).containsOnlyKeys(new AAGUID("df495bdc-223a-429d-9f0e-ebfa29155812")); }
@SuppressWarnings("Duplicates") @Override public Map<AAGUID, Set<MetadataStatement>> provide() { return metadataStatementsProviders.stream() .flatMap(provider -> { try { return provider.provide().entrySet().stream(); } catch (RuntimeException e) { logger.warn("Failed to load metadata from one of metadataStatementsProviders", e); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
AggregatingMetadataStatementsProvider implements MetadataStatementsProvider { @SuppressWarnings("Duplicates") @Override public Map<AAGUID, Set<MetadataStatement>> provide() { return metadataStatementsProviders.stream() .flatMap(provider -> { try { return provider.provide().entrySet().stream(); } catch (RuntimeException e) { logger.warn("Failed to load metadata from one of metadataStatementsProviders", e); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } }
AggregatingMetadataStatementsProvider implements MetadataStatementsProvider { @SuppressWarnings("Duplicates") @Override public Map<AAGUID, Set<MetadataStatement>> provide() { return metadataStatementsProviders.stream() .flatMap(provider -> { try { return provider.provide().entrySet().stream(); } catch (RuntimeException e) { logger.warn("Failed to load metadata from one of metadataStatementsProviders", e); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } AggregatingMetadataStatementsProvider(List<MetadataStatementsProvider> metadataStatementsProviders); }
AggregatingMetadataStatementsProvider implements MetadataStatementsProvider { @SuppressWarnings("Duplicates") @Override public Map<AAGUID, Set<MetadataStatement>> provide() { return metadataStatementsProviders.stream() .flatMap(provider -> { try { return provider.provide().entrySet().stream(); } catch (RuntimeException e) { logger.warn("Failed to load metadata from one of metadataStatementsProviders", e); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } AggregatingMetadataStatementsProvider(List<MetadataStatementsProvider> metadataStatementsProviders); @SuppressWarnings("Duplicates") @Override Map<AAGUID, Set<MetadataStatement>> provide(); }
AggregatingMetadataStatementsProvider implements MetadataStatementsProvider { @SuppressWarnings("Duplicates") @Override public Map<AAGUID, Set<MetadataStatement>> provide() { return metadataStatementsProviders.stream() .flatMap(provider -> { try { return provider.provide().entrySet().stream(); } catch (RuntimeException e) { logger.warn("Failed to load metadata from one of metadataStatementsProviders", e); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } AggregatingMetadataStatementsProvider(List<MetadataStatementsProvider> metadataStatementsProviders); @SuppressWarnings("Duplicates") @Override Map<AAGUID, Set<MetadataStatement>> provide();  }