DefaultCustomerService implements CustomerService { public List<Customer> findCustomersByName(String firstName, String lastName) { final Customer probe = new Customer(); probe.setFirstName(firstName); probe.setLastName(lastName); final ExampleMatcher matcher = ExampleMatcher.matching() .withMatcher("firstName", ignoreCase()) .withMatcher("lastName", ignoreCase()); final Example<Customer> example = Example.of(probe, matcher); return repository.findByExample(example); } DefaultCustomerService(CustomerRepository repository); long register(String firstName, String lastName, Date birthday); Customer findCustomer(long id); List<Customer> findCustomersByBirthday(Date from, Date to); List<Customer> findCustomersByName(String firstName, String lastName); List<Customer> findCustomersByFirstNames(Collection<String> firstNames); @Override List<Customer> findByFirstNamePart(final String part);  }
@Test public void testLoadingCustomersByFirstNameAndLastName() { final Customer customer = createCustomer("Milad", "Naseri", date(1988, 1, 1)); createCustomer("Zohreh", "Sadeghi", date(1989, 9, 22)); createCustomer("Hassan", "Naseri", date(1962, 4, 15)); final List<Customer> list = service.findCustomersByName("Milad", "Naseri"); assertThat(list, is(notNullValue())); assertThat(list, hasSize(1)); assertThat(list.get(0), is(customer)); }