Route53RaiderImpl implements Route53Raider { @Override public int getTrafficPolicyVersion(String trafficPolicyName) { String r53PolicyId = getR53TrafficPolicyId(trafficPolicyName); int policyVersion = route53Delegator.getAmazonRoute53().listTrafficPolicyInstances() .getTrafficPolicyInstances() .parallelStream() .filter(tpi -> tpi.getTrafficPolicyId().equalsIgnoreCase(r53PolicyId)) .map(TrafficPolicyInstance::getTrafficPolicyVersion) .collect(Collectors.toList()) .stream() .findFirst() .get(); return policyVersion; } Route53RaiderImpl(); @Override List<HealthCheck> listHealthCheckers(); @Override List<HealthCheckObservation> getHealthCheckerStatus(String healthCheckerId); @Override HealthCheckStatus getSimpleHealthCheckerStatus(String healthCheckerId); @Override void updateTrafficPolicy(String trafficPolicyName, int version); @Override int getTrafficPolicyVersion(String trafficPolicyName); String getR53PolicyId(String policyId); @Override void updateHealthCheckRegions(String healthCheckId, List<String> regions); @Override List<String> getHealthCheckRegions(String healthCheckId); @Override void updateHealthCheckToDefaultRegions(String healthCheckId);  }
@Test public void testGetTrafficPolicyVersion() { ListTrafficPolicyInstancesResult listTrafficPolicyInstancesResult = PowerMockito.mock(ListTrafficPolicyInstancesResult.class); Mockito.when(mockAmazonRoute53.listTrafficPolicyInstances()).thenReturn(listTrafficPolicyInstancesResult); TrafficPolicyInstance trafficPolicyInstance = new TrafficPolicyInstance(); trafficPolicyInstance.setName("testPolicy"); trafficPolicyInstance.setTrafficPolicyVersion(1); trafficPolicyInstance.setTrafficPolicyId("abc"); ListTrafficPoliciesResult listTrafficPoliciesResult = PowerMockito.mock(ListTrafficPoliciesResult.class); Mockito.when(mockAmazonRoute53.listTrafficPolicies()).thenReturn(listTrafficPoliciesResult); TrafficPolicySummary trafficPolicySummary = new TrafficPolicySummary(); trafficPolicySummary.setName("testPolicy"); trafficPolicySummary.setId("abc"); Mockito.when(listTrafficPoliciesResult.getTrafficPolicySummaries()).thenReturn(Arrays.asList(trafficPolicySummary)); Mockito.when(listTrafficPolicyInstancesResult.getTrafficPolicyInstances()).thenReturn(Arrays.asList(trafficPolicyInstance)); int policyVersion = route53RaiderUnderTest.getTrafficPolicyVersion("testPolicy"); Assert.assertEquals(policyVersion,1); }