### Question:
LeaveRequestService { @RolesAllowed("HR") public Optional<LeaveRequest> deny(UUID id) { Optional<LeaveRequest> found = repo.findById(id); found.ifPresent(lr -> lr.setStatus(Status.DENIED)); return found; }  @PreAuthorize("#employee == authentication.name or hasRole('HR')") LeaveRequest request(String employee, LocalDate from, LocalDate to); @RolesAllowed("HR") Optional<LeaveRequest> approve(UUID id); @RolesAllowed("HR") Optional<LeaveRequest> deny(UUID id); @PostAuthorize("returnObject.orElse(null)?.employee == authentication.name or hasRole('HR')") Optional<LeaveRequest> retrieve(UUID id); @PreAuthorize("#employee == authentication.name or hasRole('HR')") List<LeaveRequest> retrieveFor(String employee); @RolesAllowed("HR") List<LeaveRequest> retrieveAll();  }### Answer:
@Test @WithMockUser(roles = "HR") void testDeny() { LeaveRequest saved = repository.save(new LeaveRequest("Alice", of(2019, 11, 30), of(2019, 12, 03), PENDING)); Optional<LeaveRequest> denied = service.deny(saved.getId()); verify(repository).findById(saved.getId()); assertThat(denied).isPresent(); assertThat(denied).get().isSameAs(saved); assertThat(denied.get().getStatus()).isSameAs(DENIED); }