Skip to content

Commit

Permalink
Increase code coverage to minimum of 80% (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
rashidi authored Dec 22, 2024
1 parent 85a33f3 commit ea83a36
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 113 deletions.
5 changes: 1 addition & 4 deletions data-jpa-audit/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 5 additions & 49 deletions data-jpa-audit/src/main/java/zin/rashidi/boot/data/user/User.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.Instant;

/**
* @author Rashidi Zin
*/
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Book> getBooks() {
return books;
}

public void setBooks(Set<Book> books) {
this.books = books;
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}

0 comments on commit ea83a36

Please sign in to comment.