AssertionUtils { public static void assertNotExistsInPolicyRepository( List<PolicyDto> policyDtos, Function<String, Policy> policyFindFunction) { policyDtos .stream() .map(PolicyDto::getId) .forEach( policyId -> assertNotExistsInPolicyRepository(policyId, policyFindFunction)); }  static void assertNotExistsInPolicyRepository(
			List<PolicyDto> policyDtos,
			Function<String, Policy> policyFindFunction); static void assertNotExistsInPolicyRepository(String policyId,
			Function<String, Policy> policyFindFunction); static void assertPoliciesNotEmpty(final List<Policy> policies,
			final String policyId, final String wildcard); static void assertPolicyId(String policyId); static void assertPolicyIdConsistency(String requestPolicyId,
			final String policyContentPolicyId); static void assertPolicyNotNull(final Policy policy,
			final String policyId); static void assertUniqueIds(List<PolicyDto> policyDtos);  }
@Test public void testAssertNotExistsInPolicyRepositoryListOfPolicyDtoFunctionOfStringPolicy_First_Exists_Throws_PolicyAlreadyExistsException() { thrown.expect(PolicyAlreadyExistsException.class); final String policyId1 = "policyId1"; final String policyId2 = "policyId2"; final PolicyDto p1 = new PolicyDto(); p1.setId(policyId1); final PolicyDto p2 = new PolicyDto(); p2.setId(policyId2); final Function<String, Policy> policyFindFunction = s -> s .equals(policyId2) ? null : new Policy(); final List<PolicyDto> policyDtos = Arrays.asList(p1, p2); AssertionUtils.assertNotExistsInPolicyRepository(policyDtos, policyFindFunction); }
@Test public void testAssertNotExistsInPolicyRepositoryListOfPolicyDtoFunctionOfStringPolicy_None_Exists() { final String policyId1 = "policyId1"; final String policyId2 = "policyId2"; final PolicyDto p1 = new PolicyDto(); p1.setId(policyId1); final PolicyDto p2 = new PolicyDto(); p2.setId(policyId2); final Function<String, Policy> policyFindFunction = s -> s .equals(policyId1) || s.equals(policyId2) ? null : new Policy(); final List<PolicyDto> policyDtos = Arrays.asList(p1, p2); AssertionUtils.assertNotExistsInPolicyRepository(policyDtos, policyFindFunction); }
@Test public void testAssertNotExistsInPolicyRepositoryListOfPolicyDtoFunctionOfStringPolicy_Second_Exists_Throws_PolicyAlreadyExistsException() { thrown.expect(PolicyAlreadyExistsException.class); final String policyId1 = "policyId1"; final String policyId2 = "policyId2"; final PolicyDto p1 = new PolicyDto(); p1.setId(policyId1); final PolicyDto p2 = new PolicyDto(); p2.setId(policyId2); final Function<String, Policy> policyFindFunction = s -> s .equals(policyId1) ? null : new Policy(); final List<PolicyDto> policyDtos = Arrays.asList(p1, p2); AssertionUtils.assertNotExistsInPolicyRepository(policyDtos, policyFindFunction); }
@Test public void testAssertNotExistsInPolicyRepositoryStringFunctionOfStringPolicy_Exist_Throws() { thrown.expect(PolicyAlreadyExistsException.class); final String policyId1 = "policyId1"; final String policyId2 = "policyId2"; final PolicyDto p1 = new PolicyDto(); p1.setId(policyId1); final PolicyDto p2 = new PolicyDto(); p2.setId(policyId2); final Function<String, Policy> policyFindFunction = s -> s .equals(policyId1) ? null : new Policy(); AssertionUtils.assertNotExistsInPolicyRepository(policyId2, policyFindFunction); }
@Test public void testAssertNotExistsInPolicyRepositoryStringFunctionOfStringPolicy_Not_Exists() { final String policyId1 = "policyId1"; final String policyId2 = "policyId2"; final PolicyDto p1 = new PolicyDto(); p1.setId(policyId1); final PolicyDto p2 = new PolicyDto(); p2.setId(policyId2); final Function<String, Policy> policyFindFunction = s -> s .equals(policyId1) ? null : new Policy(); AssertionUtils.assertNotExistsInPolicyRepository(policyId1, policyFindFunction); }