Skip to content

Commit

Permalink
BookListTest jUnit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yeozongyao committed Mar 19, 2024
1 parent c30e0d1 commit 5b7287e
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions src/test/java/seedu/bookbuddy/BookListTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package seedu.bookbuddy;

import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import static org.junit.jupiter.api.Assertions.*;


class BookListTest {
Expand All @@ -15,10 +17,56 @@ public void sampleTest() {

@Test
void addBook() {
BookList bookList = new BookList();
bookList.addBook("Harry Potter");
assertEquals(1, bookList.getSize());
assertEquals("[U] Harry Potter", bookList.getBook(0).toString());
BookList testBookList = new BookList();
testBookList.addBook("Harry Potter");
assertEquals(1, testBookList.getSize());
assertEquals("[U] Harry Potter", testBookList.getBook(0).toString());
}


@Test
void deleteBook() {
BookList testBookList = new BookList();
testBookList.addBook("Harry Potter");
testBookList.addBook("The Hobbit");
assertEquals(2, testBookList.getSize());

testBookList.deleteBook(1); // Delete the first book
assertEquals(1, testBookList.getSize());
assertEquals("The Hobbit", testBookList.getBook(0).getTitle());
}

@Test
void markDoneAndUndoneByIndex() {
BookList testBookList = new BookList();
testBookList.addBook("Harry Potter");

testBookList.markDoneByIndex(1); // Mark the first book as read
assertTrue(testBookList.getBook(0).isRead());

testBookList.markUndoneByIndex(1); // Mark the first book as unread
assertFalse(testBookList.getBook(0).isRead());
}



@Test
void printAllBooks() {
BookList testBookList = new BookList();
testBookList.addBook("Harry Potter");

ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));

testBookList.printAllBooks();

String expectedOutput = "All books:\n1. [U] Harry Potter\n";
assertEquals(expectedOutput, outContent.toString());

System.setOut(System.out);
}




}

0 comments on commit 5b7287e

Please sign in to comment.