Skip to content

Commit 81f2d34

Browse files
committed
Adapted latest changes in Spring Data Commons.
Extend CrudRepository instead of JpaRepository. Use QueryDslPredicateExecutor from Spring Data Commons.
1 parent 14463ce commit 81f2d34

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

spring-data-jpa-showcase/src/main/java/org/springframework/data/jpa/showcase/after/CustomerRepository.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
import org.springframework.data.domain.Page;
44
import org.springframework.data.domain.Pageable;
5-
import org.springframework.data.jpa.repository.JpaRepository;
65
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
76
import org.springframework.data.jpa.showcase.core.Customer;
8-
7+
import org.springframework.data.repository.CrudRepository;
98

109
/**
1110
* Repository to manage {@link Customer} instances.
1211
*
1312
* @author Oliver Gierke
1413
*/
15-
public interface CustomerRepository extends JpaRepository<Customer, Long>,
16-
JpaSpecificationExecutor<Customer> {
14+
public interface CustomerRepository extends CrudRepository<Customer, Long>, JpaSpecificationExecutor<Customer> {
1715

18-
/**
19-
* Returns a page of {@link Customer}s with the given lastname.
20-
*
21-
* @param lastname
22-
* @param pageable
23-
* @return
24-
*/
25-
Page<Customer> findByLastname(String lastname, Pageable pageable);
16+
/**
17+
* Returns a page of {@link Customer}s with the given lastname.
18+
*
19+
* @param lastname
20+
* @param pageable
21+
* @return
22+
*/
23+
Page<Customer> findByLastname(String lastname, Pageable pageable);
2624
}

spring-data-jpa-showcase/src/test/java/org/springframework/data/jpa/showcase/after/CustomerRepositoryIntegrationTest.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import static org.hamcrest.Matchers.*;
44
import static org.junit.Assert.*;
55

6-
import java.util.List;
7-
86
import org.junit.Test;
97
import org.springframework.beans.factory.annotation.Autowired;
108
import org.springframework.data.domain.Page;
@@ -13,44 +11,39 @@
1311
import org.springframework.data.jpa.showcase.core.Customer;
1412
import org.springframework.test.context.ContextConfiguration;
1513

16-
1714
/**
1815
* @author Oliver Gierke
1916
*/
2017
@ContextConfiguration("classpath:application-context-after.xml")
2118
public class CustomerRepositoryIntegrationTest extends AbstractShowcaseTest {
2219

23-
@Autowired
24-
CustomerRepository repository;
25-
26-
27-
@Test
28-
public void findsAllCustomers() throws Exception {
29-
30-
List<Customer> result = repository.findAll();
20+
@Autowired
21+
CustomerRepository repository;
3122

32-
assertThat(result, is(notNullValue()));
33-
assertFalse(result.isEmpty());
34-
}
23+
@Test
24+
public void findsAllCustomers() throws Exception {
3525

26+
Iterable<Customer> result = repository.findAll();
3627

37-
@Test
38-
public void findsFirstPageOfMatthews() throws Exception {
28+
assertThat(result, is(notNullValue()));
29+
assertTrue(result.iterator().hasNext());
30+
}
3931

40-
Page<Customer> customers =
41-
repository.findByLastname("Matthews", new PageRequest(0, 2));
32+
@Test
33+
public void findsFirstPageOfMatthews() throws Exception {
4234

43-
assertThat(customers.getContent().size(), is(2));
44-
assertFalse(customers.hasPreviousPage());
45-
}
35+
Page<Customer> customers = repository.findByLastname("Matthews", new PageRequest(0, 2));
4636

37+
assertThat(customers.getContent().size(), is(2));
38+
assertFalse(customers.hasPreviousPage());
39+
}
4740

48-
@Test
49-
public void findsCustomerById() throws Exception {
41+
@Test
42+
public void findsCustomerById() throws Exception {
5043

51-
Customer customer = repository.findOne(2L);
44+
Customer customer = repository.findOne(2L);
5245

53-
assertThat(customer.getFirstname(), is("Carter"));
54-
assertThat(customer.getLastname(), is("Beauford"));
55-
}
46+
assertThat(customer.getFirstname(), is("Carter"));
47+
assertThat(customer.getLastname(), is("Beauford"));
48+
}
5649
}

0 commit comments

Comments
 (0)