forked from code-differently/code-differently-24-q1
/
LibraryTest.java
57 lines (49 loc) · 1.64 KB
/
LibraryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.codedifferently.lesson9.LibraryManagementSystemTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.codedifferently.lesson9.LibraryManagementSystem.Book;
import com.codedifferently.lesson9.LibraryManagementSystem.Library;
import com.codedifferently.lesson9.LibraryManagementSystem.Patron;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class LibraryTest {
private Library library;
private Book book;
private Patron patron;
@BeforeEach
public void setUp() {
library = new Library();
book = new Book("The Pragmatic Programmer", "9780135957059", "David Thomas, Andrew Hunt", 320);
// Add the book to the library
library.addBook(book);
patron = new Patron("John Doe");
library.registerPatron(patron);
}
@Test
public void testAddBook() {
List<Book> books = library.getBooks();
assertEquals(1, books.size());
assertEquals(book, books.get(0));
}
@Test
public void testRemoveBook() {
library.removeBook(book);
List<Book> books = library.getBooks();
assertEquals(0, books.size());
}
@Test
public void testCheckOutBook() {
library.checkOutBook(book, patron);
assertTrue(book.isCheckedOut());
assertTrue(patron.getCheckedOutBooks().contains(book));
}
@Test
public void testReturnBook() {
library.checkOutBook(book, patron);
library.returnBook(book, patron);
assertFalse(book.isCheckedOut());
assertFalse(patron.getCheckedOutBooks().contains(book));
}
}