Skip to content

Commit db65778

Browse files
committed
Modified User and UserRepositoryTest to reproduce error
1 parent 61877bc commit db65778

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/test/java/org/springframework/data/jpa/domain/sample/User.java

+46-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616
package org.springframework.data.jpa.domain.sample;
1717

18-
import java.util.Arrays;
19-
import java.util.Date;
20-
import java.util.HashSet;
21-
import java.util.Set;
18+
import org.springframework.lang.Nullable;
19+
20+
import java.time.LocalDateTime;
21+
import java.time.ZoneId;
22+
import java.util.*;
2223

2324
import javax.persistence.*;
2425

@@ -114,6 +115,13 @@ public class User {
114115

115116
@Temporal(TemporalType.DATE) private Date dateOfBirth;
116117

118+
@Temporal(TemporalType.TIMESTAMP) //
119+
private @Nullable
120+
Date createdDate;
121+
122+
// @ManyToOne //
123+
// private @Nullable User createdBy;
124+
117125
/**
118126
* Creates a new empty instance of {@code User}.
119127
*/
@@ -141,6 +149,40 @@ public User(String firstname, String lastname, String emailAddress, Role... role
141149
this.createdAt = new Date();
142150
}
143151

152+
// /*
153+
// * (non-Javadoc)
154+
// * @see org.springframework.data.domain.Auditable#getCreatedBy()
155+
// */
156+
// public Optional<User> getCreatedBy() {
157+
// return Optional.ofNullable(createdBy);
158+
// }
159+
160+
// /*
161+
// * (non-Javadoc)
162+
// * @see org.springframework.data.domain.Auditable#setCreatedBy(java.lang.Object)
163+
// */
164+
// public void setCreatedBy(User createdBy) {
165+
// this.createdBy = createdBy;
166+
// }
167+
168+
/*
169+
* (non-Javadoc)
170+
* @see org.springframework.data.domain.Auditable#getCreatedDate()
171+
*/
172+
public Optional<LocalDateTime> getCreatedDate() {
173+
return null == createdDate ? Optional.empty()
174+
: Optional.of(LocalDateTime.ofInstant(createdDate.toInstant(), ZoneId.systemDefault()));
175+
}
176+
177+
/*
178+
* (non-Javadoc)
179+
* @see org.springframework.data.domain.Auditable#setCreatedDate(java.time.temporal.TemporalAccessor)
180+
*/
181+
public void setCreatedDate(LocalDateTime createdDate) {
182+
this.createdDate = Date.from(createdDate.atZone(ZoneId.systemDefault()).toInstant());
183+
}
184+
185+
144186
/**
145187
* @return the id
146188
*/

src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,19 @@ void findAllByExampleWithEmptyProbe() {
17541754
assertThat(users).hasSize(4);
17551755
}
17561756

1757+
@Test
1758+
void findAllByExampleWithEmptyProbeAndIgnoringNullValues () {
1759+
flushTestUsers();
1760+
1761+
User prototype = new User();
1762+
prototype.setCreatedAt(null);
1763+
1764+
List<User> users = repository
1765+
.findAll(of(prototype, ExampleMatcher.matching().withIgnoreNullValues().withIgnorePaths("age", "createdAt", "active")));
1766+
1767+
assertThat(users).hasSize(4);
1768+
}
1769+
17571770
@Test // DATAJPA-218
17581771
void findAllByNullExample() {
17591772
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)

0 commit comments

Comments
 (0)