CustomerService { @Transactional @PreAuthorize("hasPermission(#customer, 'SAVE')") public Customer save(Customer customer) { return repository.save(customer); }  @Transactional @PreAuthorize("hasPermission(#customer, 'SAVE')") Customer save(Customer customer);  }
@Test public void should_save_an_authorized_customer() { Customer savedCustomer = service.save(new Customer("Alice", "Smith")); assertThat(savedCustomer.getLastName()).isEqualTo("Smith"); }
@Test(expected = AccessDeniedException.class) public void should_throw_AccessDenied_when_try_to_save_an_unauthorized_customer() { service.save(new Customer("John", "Doe")); }