Skip to content

Commit

Permalink
Update Set-Genre junit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yeozongyao committed Apr 4, 2024
1 parent 9c47da6 commit 63ffe2d
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/test/java/seedu/bookbuddy/ParserMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import seedu.bookbuddy.book.Genre;
import seedu.bookbuddy.book.Label;
import seedu.bookbuddy.book.Read;
import seedu.bookbuddy.book.Title;
Expand All @@ -11,12 +12,12 @@
import seedu.bookbuddy.booklist.BookListModifier;
import seedu.bookbuddy.parser.ParserMain;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;

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 static org.junit.jupiter.api.Assertions.*;


public class ParserMainTest {
Expand Down Expand Up @@ -92,24 +93,28 @@ void parseLabelCommand() {
assertEquals("Great Book", Label.getLabel(books.getBook(1)));
}

// @Test
// void parseGenreCommand() {
// BookList books = new BookList();
// BookListModifier.addBook(books, "The Great Gatsby");
// // Simulate user input for genre selection "Classic"
// String simulatedUserInput = "6\nClassic\n"; // Assuming '3' is the option to add a new genre
// InputStream savedStandardInputStream = System.in;
// System.setIn(new ByteArrayInputStream(simulatedUserInput.getBytes()));
// ParserMain.parseCommand("set-genre 1", books); // Changed to fit your updated command-handling logic
// assertEquals("Classic", Genre.getGenre(books.getBook(1))); // Indexes are typically 0-based in lists
//
// BookListModifier.addBook(books, "Geronimo");
// String nextSimulatedUserInput = "3\n";
// System.setIn(new ByteArrayInputStream(nextSimulatedUserInput.getBytes()));
// ParserMain.parseCommand("set-genre 2", books);
// assertEquals("Mystery", Genre.getGenre(books.getBook(2)));
// System.setIn(savedStandardInputStream);
// }
@Test
void parseGenreCommand() {
BookList books = new BookList();
BookListModifier.addBook(books, "The Great Gatsby");
// Simulate user input for genre selection "Classic"
String simulatedUserInput = "6\nClassic\n"; // Assuming '3' is the option to add a new genre
InputStream savedStandardInputStream = System.in;
System.setIn(new ByteArrayInputStream(simulatedUserInput.getBytes()));
ParserMain.parseCommand("set-genre 1", books); // Changed to fit your updated command-handling logic
assertEquals("Classic", Genre.getGenre(books.getBook(1))); // Indexes are typically 0-based in lists

BookListModifier.addBook(books, "Geronimo");
String nextSimulatedUserInput = "3\n";
System.setIn(new ByteArrayInputStream(nextSimulatedUserInput.getBytes()));
ParserMain.parseCommand("set-genre 2", books);
assertEquals("Mystery", Genre.getGenre(books.getBook(2)));
System.setIn(savedStandardInputStream);

BookListModifier.addBook(books, "Tom And Jerry");
ParserMain.parseCommand("set-genre 3 Fantasy", books);
assertEquals("Fantasy", Genre.getGenre(books.getBook(3)));
}

@Test
void parseInvalidAddCommandThrowsException() {
Expand Down

0 comments on commit 63ffe2d

Please sign in to comment.