File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ public abstract class AuditingEntity {
1515
1616 @ PrePersist
1717 protected void onCreate () {
18- this .createdAt = LocalDateTime .now ();
18+ if (createdAt == null ) {
19+ this .createdAt = LocalDateTime .now ();
20+ }
1921 }
2022}
Original file line number Diff line number Diff line change 1+ package eatda .util ;
2+
3+ import eatda .domain .AuditingEntity ;
4+ import java .time .LocalDateTime ;
5+ import org .springframework .test .util .ReflectionTestUtils ;
6+
7+ public final class DomainUtils {
8+
9+ private static final String CREATED_AT_FIELD = "createdAt" ;
10+
11+ private DomainUtils () {
12+ }
13+
14+ public static <T extends AuditingEntity > void setCreatedAt (T entity , LocalDateTime createdAt ) {
15+ try {
16+ ReflectionTestUtils .setField (entity , CREATED_AT_FIELD , createdAt );
17+ } catch (Exception e ) {
18+ throw new IllegalArgumentException ("Failed to set createdAt field" , e );
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments