PolicyConflictService { public Map<String, List<PdpPolicyDefinition>> conflicts(List<PdpPolicyDefinition> policies) { Set<PdpPolicyDefinition> conflicts = new HashSet<>(); range(0, policies.size()).forEach(i -> range(i + 1, policies.size()).forEach(j -> { PdpPolicyDefinition one = policies.get(i); PdpPolicyDefinition two = policies.get(j); if (conflict(one, two)) { conflicts.addAll(asList(one, two)); } })); return conflicts.stream() .filter(conflict -> !conflict.isServiceProviderInvalidOrMissing()) .collect(groupingBy(PdpPolicyDefinition::getServiceProviderName)); }  Map<String, List<PdpPolicyDefinition>> conflicts(List<PdpPolicyDefinition> policies);  }
@Test public void testConflicts() throws Exception { Map<String, List<PdpPolicyDefinition>> conflicts = subject.conflicts(asList( policyDefinition("sp1", asList("idp1", "idp2")), policyDefinition("sp1", asList("idp2", "idp3")), policyDefinition("sp1", asList("idp3")), policyDefinition("sp2", Collections.emptyList()), policyDefinition("sp2", asList("idp1")), policyDefinition("sp3", asList("idp1")), policyDefinition("sp3", asList("idp2")), policyDefinition("sp4", asList("idp2")) )); assertEquals(2, conflicts.size()); assertEquals(new HashSet<>(asList("sp1", "sp2")), conflicts.keySet()); List<PdpPolicyDefinition> sp1 = conflicts.get("sp1"); assertEquals(3, sp1.size()); sp1.forEach(def -> assertEquals("sp1", def.getServiceProviderId())); List<PdpPolicyDefinition> sp2 = conflicts.get("sp2"); assertEquals(2, sp2.size()); sp2.forEach(def -> assertEquals("sp2", def.getServiceProviderId())); }