SignaturePolicyService { public T getPolicy(String policyName) { T policy = StringUtils.isEmpty(policyName) ? defaultPolicy : signaturePolicies.get(policyName); if (policy == null) { throw new InvalidPolicyException(policyName, signaturePolicies.keySet()); } return policy; } SignaturePolicyService(SignaturePolicyProperties<T> signaturePolicyProperties); T getPolicy(String policyName);  }
@Test public void whenSignaturePolicesDoNotContainDefaultPolicyThenThrowException() { expectedException.expect(DefaultPolicyNotDefinedException.class); ValidationPolicy pol1 = createValidationPolicy("pol1", "desc1"); SignaturePolicyService<ValidationPolicy> signaturePolicyService = createSignaturePolicyService("RANDOM_PREFIX" + "pol1", pol1); signaturePolicyService.getPolicy("pol1"); }
@Test public void gettingPolicyWithoutSpecifyingNameReturnsDefaultPolicy() { ValidationPolicy pol1 = createValidationPolicy("pol1", "desc1"); ValidationPolicy pol2 = createValidationPolicy("pol2", "desc2"); SignaturePolicyService<ValidationPolicy> signaturePolicyService = createSignaturePolicyService("pol1", pol1, pol2); assertEquals(pol1, signaturePolicyService.getDefaultPolicy()); assertEquals(pol1, signaturePolicyService.getPolicy("")); }