forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentFixtureBuilder.java
More file actions
53 lines (43 loc) · 1.61 KB
/
CommentFixtureBuilder.java
File metadata and controls
53 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.solidconnection.community.comment.fixture;
import com.example.solidconnection.community.comment.domain.Comment;
import com.example.solidconnection.community.comment.repository.CommentRepository;
import com.example.solidconnection.community.post.domain.Post;
import com.example.solidconnection.siteuser.domain.SiteUser;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.test.context.TestComponent;
@TestComponent
@RequiredArgsConstructor
public class CommentFixtureBuilder {
private final CommentRepository commentRepository;
private String content;
private Post post;
private SiteUser siteUser;
private Comment parentComment;
public CommentFixtureBuilder content(String content) {
this.content = content;
return this;
}
public CommentFixtureBuilder post(Post post) {
this.post = post;
return this;
}
public CommentFixtureBuilder siteUser(SiteUser siteUser) {
this.siteUser = siteUser;
return this;
}
public CommentFixtureBuilder parentComment(Comment parentComment) {
this.parentComment = parentComment;
return this;
}
public Comment createParent() {
Comment comment = new Comment(content);
comment.setPostAndSiteUser(post, siteUser);
return commentRepository.save(comment);
}
public Comment createChild() {
Comment comment = new Comment(content);
comment.setPostAndSiteUser(post, siteUser);
comment.setParentCommentAndPostAndSiteUser(parentComment, post, siteUser);
return commentRepository.save(comment);
}
}