PolicyValidationUtils { public static PolicyDto validateAndReturn(PolicyDto policyDto) { policyDto.setValid(validate(policyDto.getPolicy())); return policyDto; }  static boolean validate(final byte[] policy); static PolicyDto validateAndReturn(PolicyDto policyDto);  }
@Test public void testValidateAndReturn() throws UnsupportedEncodingException { final PolicyDto policyDto = new PolicyDto(); policyDto.setId(POLICY_ID); policyDto.setPolicy(POLICY_STRING.getBytes(DOMUtils.DEFAULT_ENCODING)); policyDto.setValid(false); final PolicyDto response = PolicyValidationUtils .validateAndReturn(policyDto); assertEquals(true, response.isValid()); assertEquals(policyDto, response); assertEquals(policyDto.getPolicy(), response.getPolicy()); assertEquals(policyDto.getId(), response.getId()); }
@Test public void testValidateAndReturn_Not_Valid() throws UnsupportedEncodingException { final PolicyDto policyDto = new PolicyDto(); policyDto.setId(POLICY_ID); policyDto.setPolicy(POLICY_STRING_NOT_VALID_XACML .getBytes(DOMUtils.DEFAULT_ENCODING)); policyDto.setValid(true); final PolicyDto response = PolicyValidationUtils .validateAndReturn(policyDto); assertEquals(false, response.isValid()); assertEquals(policyDto, response); assertEquals(policyDto.getPolicy(), response.getPolicy()); assertEquals(policyDto.getId(), response.getId()); }