diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/config/Initializer.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/config/Initializer.java index 8f4e671f9..1b9eb1932 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/config/Initializer.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/config/Initializer.java @@ -28,59 +28,51 @@ public void run(String... args) { .forEach( i -> { PostCommentEntity post1Comment = - PostCommentEntity.builder() - .title("Sample Review" + i) - .content("Sample Content" + i) - .published(true) - .build(); + new PostCommentEntity() + .setTitle("Sample Review" + i) + .setContent("Sample Content" + i) + .setPublished(true); PostCommentEntity post1Comment2 = - PostCommentEntity.builder() - .title("Complicated Review" + i) - .content("Complicated Content" + i) - .published(false) - .build(); + new PostCommentEntity() + .setTitle("Complicated Review" + i) + .setContent("Complicated Content" + i) + .setPublished(false); PostDetailsEntity post1Details = - PostDetailsEntity.builder() - .createdBy("user" + i) - .detailsKey("key" + i) - .build(); + new PostDetailsEntity() + .setCreatedBy("user" + i) + .setDetailsKey("key" + i); PostEntity postEntity = - PostEntity.builder() - .title("Title" + i) - .content("content" + 1) - .published(true) - .build(); + new PostEntity() + .setTitle("Title" + i) + .setContent("content" + 1) + .setPublished(true); postEntity.setDetails(post1Details); postEntity.addComment(post1Comment); postEntity.addComment(post1Comment2); PostEntity postEntity1 = - PostEntity.builder() - .title("Second Title" + i) - .content("Second Content" + 1) - .published(false) - .build(); + new PostEntity() + .setTitle("Second Title" + i) + .setContent("Second Content" + 1) + .setPublished(false); PostCommentEntity post2Comment = - PostCommentEntity.builder() - .title("Complicated Title" + i) - .content("Complicated Content" + i) - .published(true) - .publishedAt(OffsetDateTime.now()) - .build(); + new PostCommentEntity() + .setTitle("Complicated Title" + i) + .setContent("Complicated Content" + i) + .setPublished(true) + .setPublishedAt(OffsetDateTime.now()); PostDetailsEntity post2Details = - PostDetailsEntity.builder() - .createdBy("user" + i) - .detailsKey("keys" + i) - .build(); + new PostDetailsEntity() + .setCreatedBy("user" + i) + .setDetailsKey("keys" + i); postEntity1.setDetails(post2Details); postEntity1.addComment(post2Comment); AuthorEntity authorEntity = - AuthorEntity.builder() - .email("user" + i + "@example.com") - .firstName("first name" + i) - .lastName("last name" + i) - .mobile(9848922338L) - .build(); + new AuthorEntity() + .setEmail("user" + i + "@example.com") + .setFirstName("first name" + i) + .setLastName("last name" + i) + .setMobile(9848922338L); authorEntity.addPost(postEntity); authorEntity.addPost(postEntity1); this.authorRepository.save(authorEntity); diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/AuthorEntity.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/AuthorEntity.java index 68ea868e1..0d24af9df 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/AuthorEntity.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/AuthorEntity.java @@ -14,18 +14,14 @@ import java.util.ArrayList; import java.util.List; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Table(name = "authors") @Getter -@Setter @NoArgsConstructor @AllArgsConstructor -@Builder public class AuthorEntity implements Serializable { @Id @@ -52,9 +48,56 @@ public class AuthorEntity implements Serializable { @Version private Long version; @OneToMany(mappedBy = "authorEntity", cascade = CascadeType.ALL, orphanRemoval = true) - @Builder.Default private List postEntities = new ArrayList<>(); + public AuthorEntity setId(Long id) { + this.id = id; + return this; + } + + public AuthorEntity setFirstName(String firstName) { + this.firstName = firstName; + return this; + } + + public AuthorEntity setMiddleName(String middleName) { + this.middleName = middleName; + return this; + } + + public AuthorEntity setLastName(String lastName) { + this.lastName = lastName; + return this; + } + + public AuthorEntity setMobile(Long mobile) { + this.mobile = mobile; + return this; + } + + public AuthorEntity setEmail(String email) { + this.email = email; + return this; + } + + public AuthorEntity setRegisteredAt(LocalDateTime registeredAt) { + this.registeredAt = registeredAt; + return this; + } + + public AuthorEntity setVersion(Long version) { + this.version = version; + return this; + } + + public AuthorEntity setPostEntities(List postEntities) { + if (postEntities == null) { + postEntities = new ArrayList<>(); + } + this.postEntities = postEntities; + return this; + } + public void addPost(PostEntity postEntity) { this.postEntities.add(postEntity); postEntity.setAuthorEntity(this); diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostCommentEntity.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostCommentEntity.java index 064b7a3dc..daf4ccd25 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostCommentEntity.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostCommentEntity.java @@ -13,17 +13,13 @@ import java.time.OffsetDateTime; import java.util.Objects; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.Hibernate; @Entity @Table(name = "post_comments") @Getter -@Setter -@Builder @NoArgsConstructor @AllArgsConstructor public class PostCommentEntity extends Auditable implements Serializable { @@ -45,6 +41,36 @@ public class PostCommentEntity extends Auditable implements Serializable { @JoinColumn(name = "post_id") private PostEntity postEntity; + public PostCommentEntity setId(Long id) { + this.id = id; + return this; + } + + public PostCommentEntity setTitle(String title) { + this.title = title; + return this; + } + + public PostCommentEntity setContent(String content) { + this.content = content; + return this; + } + + public PostCommentEntity setPublished(boolean published) { + this.published = published; + return this; + } + + public PostCommentEntity setPublishedAt(OffsetDateTime publishedAt) { + this.publishedAt = publishedAt; + return this; + } + + public PostCommentEntity setPostEntity(PostEntity postEntity) { + this.postEntity = postEntity; + return this; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostDetailsEntity.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostDetailsEntity.java index c39480797..b7974b5bc 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostDetailsEntity.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostDetailsEntity.java @@ -11,17 +11,13 @@ import java.io.Serializable; import java.util.Objects; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Table(name = "post_details") @Getter -@Setter @AllArgsConstructor -@Builder @NoArgsConstructor public class PostDetailsEntity extends Auditable implements Serializable { @@ -37,8 +33,24 @@ public class PostDetailsEntity extends Auditable implements Serializable { @JoinColumn(name = "id") private PostEntity postEntity; - public PostDetailsEntity(String createdBy) { + public PostDetailsEntity setId(Long id) { + this.id = id; + return this; + } + + public PostDetailsEntity setDetailsKey(String detailsKey) { + this.detailsKey = detailsKey; + return this; + } + + public PostDetailsEntity setCreatedBy(String createdBy) { this.createdBy = createdBy; + return this; + } + + public PostDetailsEntity setPostEntity(PostEntity postEntity) { + this.postEntity = postEntity; + return this; } @Override diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostEntity.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostEntity.java index 185abd8a0..e82c8a13f 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostEntity.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/PostEntity.java @@ -18,18 +18,14 @@ import java.util.List; import java.util.Objects; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.Hibernate; @Entity @Table(name = "posts") @Getter -@Setter @AllArgsConstructor -@Builder @NoArgsConstructor public class PostEntity extends Auditable implements Serializable { @@ -47,20 +43,64 @@ public class PostEntity extends Auditable implements Serializable { private LocalDateTime publishedAt; @OneToMany(cascade = CascadeType.ALL, mappedBy = "postEntity", orphanRemoval = true) - @Builder.Default private List comments = new ArrayList<>(); @OneToOne(mappedBy = "postEntity", cascade = CascadeType.ALL, optional = false) private PostDetailsEntity details; @OneToMany(mappedBy = "postEntity", cascade = CascadeType.ALL, orphanRemoval = true) - @Builder.Default private List tags = new ArrayList<>(); @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "author_id") private AuthorEntity authorEntity; + public PostEntity setId(Long id) { + this.id = id; + return this; + } + + public PostEntity setTitle(String title) { + this.title = title; + return this; + } + + public PostEntity setContent(String content) { + this.content = content; + return this; + } + + public PostEntity setPublished(boolean published) { + this.published = published; + return this; + } + + public PostEntity setPublishedAt(LocalDateTime publishedAt) { + this.publishedAt = publishedAt; + return this; + } + + public PostEntity setComments(List comments) { + if (comments == null) { + comments = new ArrayList<>(); + } + this.comments = comments; + return this; + } + + public PostEntity setTags(List tags) { + if (tags == null) { + tags = new ArrayList<>(); + } + this.tags = tags; + return this; + } + + public PostEntity setAuthorEntity(AuthorEntity authorEntity) { + this.authorEntity = authorEntity; + return this; + } + public void addComment(PostCommentEntity comment) { this.comments.add(comment); comment.setPostEntity(this); diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/TagEntity.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/TagEntity.java index 0423d52e5..e7e048eb2 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/TagEntity.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/entities/TagEntity.java @@ -35,9 +35,19 @@ public class TagEntity implements Serializable { private String tagDescription; - public TagEntity(String tagName, String tagDescription) { + public TagEntity setId(Long id) { + this.id = id; + return this; + } + + public TagEntity setTagName(String tagName) { this.tagName = tagName; + return this; + } + + public TagEntity setTagDescription(String tagDescription) { this.tagDescription = tagDescription; + return this; } @Override diff --git a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java index a7c4b9206..e0dd25df1 100644 --- a/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java +++ b/graphql/boot-graphql-webmvc/src/main/java/com/example/graphql/mapper/NewPostRequestToPostEntityMapper.java @@ -46,8 +46,8 @@ default TagEntity getTagEntity(TagRepository tagRepository, TagsRequest tagsRequ .orElseGet( () -> tagRepository.save( - new TagEntity( - tagsRequest.tagName(), - tagsRequest.tagDescription()))); + new TagEntity() + .setTagName(tagsRequest.tagName()) + .setTagDescription(tagsRequest.tagDescription()))); } } diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerIT.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerIT.java index d22dbeaf7..db0215b03 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerIT.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerIT.java @@ -34,26 +34,23 @@ void setUp() { authorEntityList = new ArrayList<>(); authorEntityList.add( - AuthorEntity.builder() - .firstName("First Author") - .lastName("lastName") - .email("junit1@email.com") - .mobile(9848022338L) - .build()); + new AuthorEntity() + .setFirstName("First Author") + .setLastName("lastName") + .setEmail("junit1@email.com") + .setMobile(9848022338L)); authorEntityList.add( - AuthorEntity.builder() - .firstName("Second Author") - .lastName("lastName") - .email("junit2@email.com") - .mobile(9848022339L) - .build()); + new AuthorEntity() + .setFirstName("Second Author") + .setLastName("lastName") + .setEmail("junit2@email.com") + .setMobile(9848022339L)); authorEntityList.add( - AuthorEntity.builder() - .firstName("Third Author") - .lastName("lastName") - .email("junit3@email.com") - .mobile(9848022340L) - .build()); + new AuthorEntity() + .setFirstName("Third Author") + .setLastName("lastName") + .setEmail("junit3@email.com") + .setMobile(9848022340L)); authorEntityList = authorRepository.saveAll(authorEntityList); } diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerTest.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerTest.java index 8be58bb96..430273d4f 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerTest.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/AuthorEntityControllerTest.java @@ -92,12 +92,11 @@ void shouldFetchAllAuthors() throws Exception { void shouldFindAuthorById() throws Exception { Long authorId = 1L; AuthorEntity authorEntity = - AuthorEntity.builder() - .id(authorId) - .firstName("First Author") - .lastName("lastName") - .email("junit1@email.com") - .build(); + new AuthorEntity() + .setId(authorId) + .setFirstName("First Author") + .setLastName("lastName") + .setEmail("junit1@email.com"); AuthorResponse authorResponse = new AuthorResponse( 1L, @@ -193,12 +192,11 @@ void shouldReturn400WhenCreateNewAuthorWithoutValidData() throws Exception { void shouldUpdateAuthor() throws Exception { Long authorId = 1L; AuthorEntity authorEntity = - AuthorEntity.builder() - .id(authorId) - .firstName("First Author") - .lastName("lastName") - .email("junit1@email.com") - .build(); + new AuthorEntity() + .setId(authorId) + .setFirstName("First Author") + .setLastName("lastName") + .setEmail("junit1@email.com"); AuthorRequest authorRequest = new AuthorRequest( diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerIT.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerIT.java index dba3a60b7..bda0ecd9c 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerIT.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerIT.java @@ -34,17 +34,17 @@ class PostCommentEntityControllerIT extends AbstractIntegrationTest { void setUp() { postRepository.deleteAll(); - postEntity = PostEntity.builder().content("First Post").content("First Content").build(); + postEntity = new PostEntity().setContent("First Post").setTitle("First Title"); PostDetailsEntity postDetailsEntity = - PostDetailsEntity.builder().detailsKey("First Details").build(); + new PostDetailsEntity().setDetailsKey("First Details"); postEntity.setDetails(postDetailsEntity); List postCommentEntityList = new ArrayList<>(); postCommentEntityList.add( - PostCommentEntity.builder().title("First PostComment").published(true).build()); + new PostCommentEntity().setTitle("First PostComment").setPublished(true)); postCommentEntityList.add( - PostCommentEntity.builder().title("Second PostComment").published(false).build()); - postCommentEntityList.add(PostCommentEntity.builder().title("Third PostComment").build()); + new PostCommentEntity().setTitle("Second PostComment").setPublished(false)); + postCommentEntityList.add(new PostCommentEntity().setTitle("Third PostComment")); postCommentEntityList.forEach( postCommentEntity -> postEntity.addComment(postCommentEntity)); postRepository.save(postEntity); diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerTest.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerTest.java index 2a25c31b3..902b91a23 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerTest.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostCommentEntityControllerTest.java @@ -180,7 +180,7 @@ void shouldReturn404WhenUpdatingNonExistingPostComment() throws Exception { Long postCommentId = 1L; given(postCommentService.findPostCommentById(postCommentId)).willReturn(Optional.empty()); PostCommentEntity postCommentEntity = - PostCommentEntity.builder().id(postCommentId).title("Updated PostComment").build(); + new PostCommentEntity().setId(postCommentId).setTitle("Updated PostComment"); this.mockMvc .perform( diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerIT.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerIT.java index 1dea74a5c..cf3339ae3 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerIT.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerIT.java @@ -26,10 +26,9 @@ class PostDetailsEntityControllerIT extends AbstractIntegrationTest { void setUp() { postRepository.deleteAll(); - post = PostEntity.builder().content("First Post").title("First Title").build(); + post = new PostEntity().setContent("First Post").setTitle("First Title"); - PostDetailsEntity postDetailsEntity = - PostDetailsEntity.builder().detailsKey("Junit1").build(); + PostDetailsEntity postDetailsEntity = new PostDetailsEntity().setDetailsKey("Junit1"); post.setDetails(postDetailsEntity); post = postRepository.save(post); diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerTest.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerTest.java index 2057cded4..bf6c36ec9 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerTest.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostDetailsEntityControllerTest.java @@ -41,7 +41,7 @@ class PostDetailsEntityControllerTest { @BeforeEach void setUp() { this.postDetailsList = new ArrayList<>(); - this.postDetailsList.add(PostDetailsEntity.builder().id(1L).createdBy("Junit1").build()); + this.postDetailsList.add(new PostDetailsEntity().setId(1L).setCreatedBy("Junit1")); } @Test @@ -81,7 +81,7 @@ void shouldReturn404WhenFetchingNonExistingPostDetails() throws Exception { void shouldUpdatePostDetails() throws Exception { Long postDetailsId = 1L; PostDetailsEntity postDetails = - PostDetailsEntity.builder().id(postDetailsId).createdBy("updated").build(); + new PostDetailsEntity().setId(postDetailsId).setCreatedBy("updated"); PostDetailsRequest postDetailsRequest = new PostDetailsRequest("junitDetailsKey"); given(postDetailsService.findDetailsById(postDetailsId)) .willReturn(Optional.of(postDetails)); @@ -102,7 +102,7 @@ void shouldReturn404WhenUpdatingNonExistingPostDetails() throws Exception { Long postDetailsId = 1L; given(postDetailsService.findPostDetailsById(postDetailsId)).willReturn(Optional.empty()); PostDetailsEntity postDetails = - PostDetailsEntity.builder().id(postDetailsId).createdBy("Junit1").build(); + new PostDetailsEntity().setId(postDetailsId).setCreatedBy("Junit1"); this.mockMvc .perform( diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerIT.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerIT.java index bfe06a715..cea63f7be 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerIT.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerIT.java @@ -33,14 +33,14 @@ void setUp() { postRepository.deleteAll(); postEntityList = new ArrayList<>(); - PostEntity firstPost = PostEntity.builder().content("First Post").build(); - firstPost.setDetails(PostDetailsEntity.builder().detailsKey("Junit1").build()); + PostEntity firstPost = new PostEntity().setContent("First Post"); + firstPost.setDetails(new PostDetailsEntity().setDetailsKey("Junit1")); postEntityList.add(firstPost); - PostEntity secondPost = PostEntity.builder().content("Second Post").build(); - secondPost.setDetails(PostDetailsEntity.builder().detailsKey("Junit2").build()); + PostEntity secondPost = new PostEntity().setContent("Second Post"); + secondPost.setDetails(new PostDetailsEntity().setDetailsKey("Junit2")); postEntityList.add(secondPost); - PostEntity thirdPost = PostEntity.builder().content("Third Post").build(); - thirdPost.setDetails(PostDetailsEntity.builder().detailsKey("Junit3").build()); + PostEntity thirdPost = new PostEntity().setContent("Third Post"); + thirdPost.setDetails(new PostDetailsEntity().setDetailsKey("Junit3")); postEntityList.add(thirdPost); postEntityList = postRepository.saveAll(postEntityList); } diff --git a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerTest.java b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerTest.java index 060989b9a..ad0a5eaae 100644 --- a/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerTest.java +++ b/graphql/boot-graphql-webmvc/src/test/java/com/example/graphql/web/controllers/PostEntityControllerTest.java @@ -54,9 +54,10 @@ class PostEntityControllerTest { @BeforeEach void setUp() { this.postEntityList = new ArrayList<>(); - this.postEntityList.add(PostEntity.builder().id(1L).content("First Post").build()); - this.postEntityList.add(PostEntity.builder().id(2L).content("Second Post").build()); - this.postEntityList.add(PostEntity.builder().id(3L).content("Third Post").build()); + + this.postEntityList.add(new PostEntity().setId(1L).setContent("First Post")); + this.postEntityList.add(new PostEntity().setId(2L).setContent("Second Post")); + this.postEntityList.add(new PostEntity().setId(3L).setContent("Third Post")); } @Test @@ -172,7 +173,7 @@ void shouldUpdatePost() throws Exception { void shouldReturn404WhenUpdatingNonExistingPost() throws Exception { Long postId = 1L; given(postService.findPostById(postId)).willReturn(Optional.empty()); - PostEntity postEntity = PostEntity.builder().id(postId).content("Updated Post").build(); + PostEntity postEntity = new PostEntity().setId(postId).setContent("Updated Post"); this.mockMvc .perform( @@ -194,7 +195,7 @@ void shouldReturn404WhenUpdatingNonExistingPost() throws Exception { @Test void shouldDeletePost() throws Exception { Long postId = 1L; - PostEntity postEntity = PostEntity.builder().id(postId).content("First Post").build(); + PostEntity postEntity = new PostEntity().setId(postId).setContent("First Post"); given(postService.findPostById(postId)).willReturn(Optional.of(postResponseList.get(0))); doNothing().when(postService).deletePostById(postEntity.getId());