@Test public void testGetUniqueTransitGateways() { TransitGateway tgw1 = mock(TransitGateway.class); when(tgw1.getId()).thenReturn("id1"); when(tgw1.getOwnerId()).thenReturn("account1"); TransitGateway tgw2 = mock(TransitGateway.class); when(tgw2.getId()).thenReturn("id1"); when(tgw2.getOwnerId()).thenReturn("account1"); TransitGateway tgw3 = mock(TransitGateway.class); when(tgw3.getId()).thenReturn("id2"); when(tgw3.getOwnerId()).thenReturn("account3"); TransitGatewayWithMetadata t1 = new TransitGatewayWithMetadata(tgw1, new Region("r1"), "account1"); TransitGatewayWithMetadata t2 = new TransitGatewayWithMetadata(tgw2, new Region("r1"), "account2"); TransitGatewayWithMetadata t3 = new TransitGatewayWithMetadata(tgw3, new Region("r1"), "account3"); assertThat( TransitGatewayConverter.getUniqueTransitGateways( ImmutableList.of(t1, t2, t3), new Warnings()), containsInAnyOrder(t1, t3)); }
@VisibleForTesting static Collection<TransitGatewayWithMetadata> getUniqueTransitGateways( Collection<TransitGatewayWithMetadata> gateways, Warnings warnings) { Map<String, List<TransitGatewayWithMetadata>> byId = gateways.stream() .collect( Collectors.groupingBy( TransitGatewayWithMetadata::getTransitGatewayId, Collectors.toList())); List<TransitGatewayWithMetadata> result = byId.values().stream() .map(TransitGatewayConverter::findOriginalGateway) .filter(Objects::nonNull) .collect(ImmutableList.toImmutableList()); if (result.size() < byId.size()) { Set<String> missing = Sets.difference( byId.keySet(), result.stream() .map(TransitGatewayWithMetadata::getTransitGatewayId) .collect(Collectors.toSet())); warnings.redFlag( String.format( "Could not find authoritative representation for transit gateways: %s", String.join(" ", missing))); } return result; }
TransitGatewayConverter { @VisibleForTesting static Collection<TransitGatewayWithMetadata> getUniqueTransitGateways( Collection<TransitGatewayWithMetadata> gateways, Warnings warnings) { Map<String, List<TransitGatewayWithMetadata>> byId = gateways.stream() .collect( Collectors.groupingBy( TransitGatewayWithMetadata::getTransitGatewayId, Collectors.toList())); List<TransitGatewayWithMetadata> result = byId.values().stream() .map(TransitGatewayConverter::findOriginalGateway) .filter(Objects::nonNull) .collect(ImmutableList.toImmutableList()); if (result.size() < byId.size()) { Set<String> missing = Sets.difference( byId.keySet(), result.stream() .map(TransitGatewayWithMetadata::getTransitGatewayId) .collect(Collectors.toSet())); warnings.redFlag( String.format( "Could not find authoritative representation for transit gateways: %s", String.join(" ", missing))); } return result; } }
TransitGatewayConverter { @VisibleForTesting static Collection<TransitGatewayWithMetadata> getUniqueTransitGateways( Collection<TransitGatewayWithMetadata> gateways, Warnings warnings) { Map<String, List<TransitGatewayWithMetadata>> byId = gateways.stream() .collect( Collectors.groupingBy( TransitGatewayWithMetadata::getTransitGatewayId, Collectors.toList())); List<TransitGatewayWithMetadata> result = byId.values().stream() .map(TransitGatewayConverter::findOriginalGateway) .filter(Objects::nonNull) .collect(ImmutableList.toImmutableList()); if (result.size() < byId.size()) { Set<String> missing = Sets.difference( byId.keySet(), result.stream() .map(TransitGatewayWithMetadata::getTransitGatewayId) .collect(Collectors.toSet())); warnings.redFlag( String.format( "Could not find authoritative representation for transit gateways: %s", String.join(" ", missing))); } return result; } private  TransitGatewayConverter(); }
TransitGatewayConverter { @VisibleForTesting static Collection<TransitGatewayWithMetadata> getUniqueTransitGateways( Collection<TransitGatewayWithMetadata> gateways, Warnings warnings) { Map<String, List<TransitGatewayWithMetadata>> byId = gateways.stream() .collect( Collectors.groupingBy( TransitGatewayWithMetadata::getTransitGatewayId, Collectors.toList())); List<TransitGatewayWithMetadata> result = byId.values().stream() .map(TransitGatewayConverter::findOriginalGateway) .filter(Objects::nonNull) .collect(ImmutableList.toImmutableList()); if (result.size() < byId.size()) { Set<String> missing = Sets.difference( byId.keySet(), result.stream() .map(TransitGatewayWithMetadata::getTransitGatewayId) .collect(Collectors.toSet())); warnings.redFlag( String.format( "Could not find authoritative representation for transit gateways: %s", String.join(" ", missing))); } return result; } private  TransitGatewayConverter(); static List<Configuration> convertTransitGateways(
      AwsConfiguration awsConfiguration, ConvertedConfiguration configs); }
TransitGatewayConverter { @VisibleForTesting static Collection<TransitGatewayWithMetadata> getUniqueTransitGateways( Collection<TransitGatewayWithMetadata> gateways, Warnings warnings) { Map<String, List<TransitGatewayWithMetadata>> byId = gateways.stream() .collect( Collectors.groupingBy( TransitGatewayWithMetadata::getTransitGatewayId, Collectors.toList())); List<TransitGatewayWithMetadata> result = byId.values().stream() .map(TransitGatewayConverter::findOriginalGateway) .filter(Objects::nonNull) .collect(ImmutableList.toImmutableList()); if (result.size() < byId.size()) { Set<String> missing = Sets.difference( byId.keySet(), result.stream() .map(TransitGatewayWithMetadata::getTransitGatewayId) .collect(Collectors.toSet())); warnings.redFlag( String.format( "Could not find authoritative representation for transit gateways: %s", String.join(" ", missing))); } return result; } private  TransitGatewayConverter(); static List<Configuration> convertTransitGateways(
      AwsConfiguration awsConfiguration, ConvertedConfiguration configs);  }