From 3e2f8b49cded1f2dce83689070f64b31d7177f7c Mon Sep 17 00:00:00 2001 From: "@Territory91" Date: Mon, 13 Jan 2020 01:34:23 +0100 Subject: [PATCH] Update Loan.java and LoanTest.java --- mivan/src/main/java/mivan/model/Loan.java | 14 +-- mivan/src/test/java/mivan/LoanTest.java | 100 ++++++++++++++++++++++ 2 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 mivan/src/test/java/mivan/LoanTest.java diff --git a/mivan/src/main/java/mivan/model/Loan.java b/mivan/src/main/java/mivan/model/Loan.java index 0e2b844..5c03d4b 100644 --- a/mivan/src/main/java/mivan/model/Loan.java +++ b/mivan/src/main/java/mivan/model/Loan.java @@ -15,10 +15,10 @@ public class Loan { private long id; @Column(name = "date_start", nullable = false) - private String date_start; + private long date_start; @Column(name = "date_end", nullable = false) - private String date_end; + private long date_end; @Column(name = "state", nullable = false) private String state; @@ -35,7 +35,7 @@ public class Loan { @JoinColumn(name = "user") private User user; - public Loan(String date_start, String date_end, String state, Item item, Staff staff, User user) { + public Loan(long date_start, long date_end, String state, Item item, Staff staff, User user) { this.date_start = date_start; this.date_end = date_end; this.state = state; @@ -48,11 +48,11 @@ public class Loan { return id; } - public String getDate_start() { + public long getDate_start() { return date_start; } - public String getDate_end() { + public long getDate_end() { return date_end; } @@ -76,11 +76,11 @@ public class Loan { this.id = id; } - public void setDate_start(String date_start) { + public void setDate_start(long date_start) { this.date_start = date_start; } - public void setDate_end(String date_end) { + public void setDate_end(long date_end) { this.date_end = date_end; } diff --git a/mivan/src/test/java/mivan/LoanTest.java b/mivan/src/test/java/mivan/LoanTest.java new file mode 100644 index 0000000..a3c2778 --- /dev/null +++ b/mivan/src/test/java/mivan/LoanTest.java @@ -0,0 +1,100 @@ +package mivan; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; + +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +import mivan.model.Item; +import mivan.model.Loan; +import mivan.model.Staff; +import mivan.model.User; +import mivan.repository.LoanRepository; +import mivan.repository.LoanRepositoryImpl; + +public class LoanTest { + + private LoanRepository loanRepository = new LoanRepositoryImpl(); + + @Test + @Order(1) + void testAddBook() { + + long date_start = 1234; + long date_end = 2345; + String state = "loaning"; + + Item item = null; + Staff staff = null; + User user = null; + + Loan loan = new Loan(date_start, date_end, state, item, staff, user); + + loanRepository.addLoan(loan); + + int size = loanRepository.getSize(); + + assertEquals(size, 1); + + } + + @Test + @Order(2) + void testUpdateBook() { + + long date_start = 1234; + long date_end = 2345; + String state = "loaning"; + + Item item = null; + Staff staff = null; + User user = null; + + Loan loan = new Loan(date_start, date_end, state, item, staff, user); + + loanRepository.addLoan(loan); + + String update_state = "returned"; + + loanRepository.updateLoan(1L,update_state); + + Optional opt_loan = loanRepository.findById(1L); + + Loan loan2 = opt_loan.get(); + assertTrue(update_state.equals(loan2.getState())); + + } + + @Test + @Order(3) + void testDeleteBook() { + + + long date_start = 1234; + long date_end = 2345; + String state = "loaning"; + + Item item = null; + Staff staff = null; + User user = null; + + Loan loan = new Loan(date_start, date_end, state, item, staff, user); + + loanRepository.addLoan(loan); + + Optional opt_loan2 = loanRepository.findById(1L); + + Loan book2 = opt_loan2.get(); + long ID = book2.getId(); + + int start_size = loanRepository.getSize(); + loanRepository.deleteLoanById(ID); + + int size = loanRepository.getSize(); + + assertEquals(start_size, size); + } +}