Skip to content

Commit c56263d

Browse files
DATAMONGO-1876 - Verify desired behavior.
1 parent 1bcb56e commit c56263d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,16 @@ public void setUp() throws InterruptedException {
9494
oliver = new Person("Oliver August", "Matthews", 4);
9595
carter = new Person("Carter", "Beauford", 49);
9696
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals"));
97+
9798
Thread.sleep(10);
99+
98100
boyd = new Person("Boyd", "Tinsley", 45);
99101
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
100102
stefan = new Person("Stefan", "Lessard", 34);
101103
leroi = new Person("Leroi", "Moore", 41);
102104

105+
Thread.sleep(10);
106+
103107
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE);
104108

105109
person = new QPerson("person");
@@ -1166,4 +1170,18 @@ public void deletesPersonsByFirstname() {
11661170

11671171
assertThat(repository.countByThePersonsFirstname("Dave"), is(0L));
11681172
}
1173+
1174+
@Test // DATAMONGO-1867
1175+
public void findInDateRange() {
1176+
1177+
assertThat(repository.findByCreatedAtBetween(carter.createdAt, alicia.createdAt),
1178+
containsInAnyOrder(boyd, stefan, leroi));
1179+
}
1180+
1181+
@Test // DATAMONGO-1867
1182+
public void findInDateRangeWithAnnotatedQuery() {
1183+
1184+
assertThat(repository.findByCreatedAtBetweenManually(carter.createdAt, alicia.createdAt),
1185+
containsInAnyOrder(boyd, stefan, leroi));
1186+
}
11691187
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
208208
// DATAMONGO-427
209209
List<Person> findByCreatedAtAfter(Date date);
210210

211+
// DATAMONGO-1867
212+
List<Person> findByCreatedAtBetween(Date from, Date to);
213+
214+
// DATAMONGO-1867
215+
@Query("{ 'createdAt' : { '$gt' : ?0, '$lt' : ?1 }}")
216+
List<Person> findByCreatedAtBetweenManually(Date from, Date to);
217+
211218
// DATAMONGO-472
212219
List<Person> findByLastnameNot(String lastname);
213220

0 commit comments

Comments
 (0)