Update Loan.java and LoanTest.java

develop
@Territory91 5 years ago
parent b9dfb8e48b
commit 3e2f8b49cd
  1. 14
      mivan/src/main/java/mivan/model/Loan.java
  2. 100
      mivan/src/test/java/mivan/LoanTest.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;
}

@ -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<Loan> 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<Loan> 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);
}
}
Loading…
Cancel
Save