File tree Expand file tree Collapse file tree 4 files changed +49
-4
lines changed
main/java/com/example/solidconnection/common Expand file tree Collapse file tree 4 files changed +49
-4
lines changed Original file line number Diff line number Diff line change 88import jakarta .persistence .PrePersist ;
99import jakarta .persistence .PreUpdate ;
1010import java .time .ZonedDateTime ;
11+ import java .time .temporal .ChronoUnit ;
12+
1113import lombok .Getter ;
1214import org .hibernate .annotations .DynamicInsert ;
1315import org .hibernate .annotations .DynamicUpdate ;
@@ -33,4 +35,8 @@ public void onPrePersist() {
3335 public void onPreUpdate () {
3436 this .updatedAt = ZonedDateTime .now (UTC ).truncatedTo (MICROS );
3537 }
38+
39+ public void setCreatedAt (ZonedDateTime createdAt ) {
40+ this .createdAt = createdAt .truncatedTo (ChronoUnit .MICROS );
41+ }
3642}
Original file line number Diff line number Diff line change @@ -47,4 +47,25 @@ public class PostFixture {
4747 .siteUser (siteUser )
4848 .create ();
4949 }
50+
51+ public Post 게시글_특정_시간_이후로_저장 (
52+ String title ,
53+ String content ,
54+ Boolean isQuestion ,
55+ PostCategory postCategory ,
56+ Board board ,
57+ SiteUser siteUser ,
58+ int time
59+ ) {
60+ return postFixtureBuilder
61+ .title (title )
62+ .content (content )
63+ .isQuestion (isQuestion )
64+ .likeCount (0L )
65+ .viewCount (0L )
66+ .postCategory (postCategory )
67+ .board (board )
68+ .siteUser (siteUser )
69+ .createAfterCertainTime (time );
70+ }
5071}
Original file line number Diff line number Diff line change 88import lombok .RequiredArgsConstructor ;
99import org .springframework .boot .test .context .TestComponent ;
1010
11+ import java .time .ZoneOffset ;
12+ import java .time .ZonedDateTime ;
13+
1114@ TestComponent
1215@ RequiredArgsConstructor
1316public class PostFixtureBuilder {
@@ -74,4 +77,17 @@ public Post create() {
7477 post .setBoardAndSiteUserId (board .getCode (), siteUser .getId ());
7578 return postRepository .save (post );
7679 }
80+
81+ public Post createAfterCertainTime (int time ) {
82+ Post post = new Post (
83+ title ,
84+ content ,
85+ isQuestion ,
86+ likeCount ,
87+ viewCount ,
88+ postCategory );
89+ post .setBoardAndSiteUserId (board .getCode (), siteUser .getId ());
90+ post .setCreatedAt (ZonedDateTime .now (ZoneOffset .UTC ).plusSeconds (time ));
91+ return postRepository .save (post );
92+ }
7793}
Original file line number Diff line number Diff line change @@ -76,21 +76,23 @@ void setUp() {
7676 boardFixture .자유게시판 (),
7777 user
7878 );
79- post2 = postFixture .게시글 (
79+ post2 = postFixture .게시글_특정_시간_이후로_저장 (
8080 "제목2" ,
8181 "내용2" ,
8282 false ,
8383 PostCategory .자유 ,
8484 boardFixture .미주권 (),
85- user
85+ user ,
86+ 3
8687 );
87- post3 = postFixture .게시글 (
88+ post3 = postFixture .게시글_특정_시간_이후로_저장 (
8889 "제목3" ,
8990 "내용3" ,
9091 true ,
9192 PostCategory .질문 ,
9293 boardFixture .자유게시판 (),
93- user
94+ user ,
95+ 6
9496 );
9597 }
9698
You can’t perform that action at this time.
0 commit comments