diff --git a/data-jpa-audit/README.adoc b/data-jpa-audit/README.adoc index 9a7c4623..8b3e46fa 100644 --- a/data-jpa-audit/README.adoc +++ b/data-jpa-audit/README.adoc @@ -147,10 +147,7 @@ class UserAuditTests { @Test @DisplayName("When a user is saved Then created and modified fields are set And createdBy and modifiedBy fields are set to Mr. Auditor") void create() { - var user = new User(); - - user.setName("Rashidi Zin"); - user.setUsername("rashidi"); + var user = new User("Rashidi Zin", "rashidi"); var createdUser = repository.save(user); diff --git a/data-jpa-audit/src/main/java/zin/rashidi/boot/data/user/User.java b/data-jpa-audit/src/main/java/zin/rashidi/boot/data/user/User.java index 648ac772..0f2c9bc6 100644 --- a/data-jpa-audit/src/main/java/zin/rashidi/boot/data/user/User.java +++ b/data-jpa-audit/src/main/java/zin/rashidi/boot/data/user/User.java @@ -1,7 +1,5 @@ package zin.rashidi.boot.data.user; -import java.time.Instant; - import jakarta.persistence.*; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; @@ -9,6 +7,8 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.time.Instant; + /** * @author Rashidi Zin */ @@ -36,60 +36,16 @@ class User { @LastModifiedDate private Instant modified; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } + protected User() {} - public void setName(String name) { + User(String name, String username) { this.name = name; - } - - public String getUsername() { - return username; + this.username = username; } public void setUsername(String username) { this.username = username; } - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public Instant getCreated() { - return created; - } - - public void setCreated(Instant created) { - this.created = created; - } - - public String getModifiedBy() { - return modifiedBy; - } - - public void setModifiedBy(String modifiedBy) { - this.modifiedBy = modifiedBy; - } - - public Instant getModified() { - return modified; - } - - public void setModified(Instant modified) { - this.modified = modified; - } } diff --git a/data-jpa-audit/src/test/java/zin/rashidi/boot/data/user/UserAuditTests.java b/data-jpa-audit/src/test/java/zin/rashidi/boot/data/user/UserAuditTests.java index c3b2ad2c..3448502f 100644 --- a/data-jpa-audit/src/test/java/zin/rashidi/boot/data/user/UserAuditTests.java +++ b/data-jpa-audit/src/test/java/zin/rashidi/boot/data/user/UserAuditTests.java @@ -16,13 +16,12 @@ import java.time.Instant; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.context.annotation.FilterType.ANNOTATION; /** * @author Rashidi Zin */ @Testcontainers -@DataJpaTest(properties = "spring.jpa.hibernate.ddl-auto=create-drop", includeFilters = @Filter(type = ANNOTATION, classes = EnableJpaAuditing.class)) +@DataJpaTest(properties = "spring.jpa.hibernate.ddl-auto=create-drop", includeFilters = @Filter(EnableJpaAuditing.class)) class UserAuditTests { @Container @@ -35,10 +34,7 @@ class UserAuditTests { @Test @DisplayName("When a user is saved Then created and modified fields are set And createdBy and modifiedBy fields are set to Mr. Auditor") void create() { - var user = new User(); - - user.setName("Rashidi Zin"); - user.setUsername("rashidi"); + var user = new User("Rashidi Zin", "rashidi"); var createdUser = repository.save(user); diff --git a/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Author.java b/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Author.java index 398342f2..572b1c6d 100644 --- a/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Author.java +++ b/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Author.java @@ -33,36 +33,8 @@ enum Status { } - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public Status getStatus() { return status; } - public void setStatus(Status status) { - this.status = status; - } - - public Set getBooks() { - return books; - } - - public void setBooks(Set books) { - this.books = books; - } - } diff --git a/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Book.java b/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Book.java index 13beb147..71f1ddf6 100644 --- a/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Book.java +++ b/data-rest-validation/src/main/java/zin/rashidi/boot/data/rest/book/Book.java @@ -1,12 +1,8 @@ package zin.rashidi.boot.data.rest.book; -import java.util.UUID; +import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import java.util.UUID; /** * @author Rashidi Zin @@ -25,27 +21,7 @@ class Book { @ManyToOne(optional = false) private Author author; - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - public Author getAuthor() { return author; } - - public void setAuthor(Author author) { - this.author = author; - } }