Added sample for invocation of JDK 8 default method on a repository.
This commit is contained in:
@@ -36,4 +36,10 @@ public interface CustomerRepository extends Repository<Customer, Long> {
|
||||
Optional<Customer> findOne(Long id);
|
||||
|
||||
<S extends Customer> S save(S customer);
|
||||
|
||||
Optional<Customer> findByLastname(String lastname);
|
||||
|
||||
default Optional<Customer> findByLastname(Customer customer) {
|
||||
return findByLastname(customer.lastname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,14 @@ public class Java8IntegrationTests {
|
||||
assertThat(customer.createdDate, is(notNullValue()));
|
||||
assertThat(customer.modifiedDate, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokesDefaultMethod() {
|
||||
|
||||
Customer customer = repository.save(new Customer("Dave", "Matthews"));
|
||||
Optional<Customer> result = repository.findByLastname(customer);
|
||||
|
||||
assertThat(result.isPresent(), is(true));
|
||||
assertThat(result.get(), is(customer));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user