### Question:
PolicyServiceImpl implements PolicyService, Constants { @Override public String updatePolicies(final UpdatePolicyDetails policyDetails) throws Exception { boolean isPolicyExits = policyRepository.existsById(policyDetails.getPolicyId()); if(isPolicyExits) { Policy policyToUpdate = policyRepository.findById(policyDetails.getPolicyId()).get(); policyToUpdate.setPolicyDesc(policyDetails.getPolicyDesc()); policyToUpdate.setPolicyUrl(policyDetails.getPolicyUrl()); policyToUpdate.setPolicyVersion(policyDetails.getPolicyVersion()); policyToUpdate.setResolution(policyDetails.getResolution()); policyToUpdate.setModifiedDate(new Date()); policyRepository.save(policyToUpdate); return "Updated Successfully"; } else { return "Policy does not exits!!"; } }  @Override Page<Object[]> getPolicies(final int page, final int size, final String searchTerm); @Override Collection<String> getAllPolicyIds(); @Override String updatePolicies(final UpdatePolicyDetails policyDetails); @Override String createPolicies(final CreatePolicyDetails policyDetails); @Override Policy getByPolicyId(String policyId);  }### Answer:
@Test public void updatePoliciesTest() throws Exception { UpdatePolicyDetails policiesDetails = getUpdatePolicyDetails(); Optional<Policy> policyToUpdate = Optional.of(getPolicy()); when(policyRepository.existsById(policiesDetails.getPolicyId())).thenReturn(true); when(policyRepository.findById(policiesDetails.getPolicyId())).thenReturn(policyToUpdate); when(policyRepository.save(policyToUpdate.get())).thenReturn(policyToUpdate.get()); assertThat(policyService.updatePolicies(policiesDetails), is("Updated Successfully")); }
@Test public void updatePoliciesNotFoundTest() throws Exception { UpdatePolicyDetails policiesDetails = getUpdatePolicyDetails(); when(policyRepository.existsById(policiesDetails.getPolicyId())).thenReturn(false); assertThat(policyService.updatePolicies(policiesDetails), is("Policy does not exits!!")); }