Skip to content

Instantly share code, notes, and snippets.

@martkoehler
Last active October 26, 2015 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martkoehler/f9e45ab5d69f7d5d5b77 to your computer and use it in GitHub Desktop.
Save martkoehler/f9e45ab5d69f7d5d5b77 to your computer and use it in GitHub Desktop.
@Test
public void findCustomer() {
Customer customer = mock(Customer.class);
CustomerRepository repository = mock(CustomerRepository.class);
CustomerService service = new CustomerService(repository);
when(repository.find(anyLong())).thenReturn(customer);
service.find(1L);
verify(repository, times(1)).find(anyLong());
verifyNoMoreInteractions(repository);
}
@Test(expected = NoResultException.class)
public void findCustomerWithoutResult() {
CustomerRepository repository = mock(CustomerRepository.class);
CustomerService service = new CustomerService(repository);
doThrow(NoResultException.class).when(repository).find(anyLong());
service.find(1L);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment