Skip to content

Commit

Permalink
Fix system support error for JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yeozongyao committed Apr 12, 2024
1 parent 932c633 commit 72c68bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/bookbuddy/booklist/BookList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public BookList() {
this.books = new ArrayList<BookMain>(); // Use ArrayList instead of array
}
public static List<String> getAvailableGenres() {
return availableGenres;
return BookList.availableGenres;
}
public static void setAvailableGenres(List<String> availableGenres) {
BookList.availableGenres = new ArrayList<>(availableGenres);
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/seedu/bookbuddy/ParserMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void parseListCommand() {
System.setOut(new PrintStream(outContent));

ParserMain.parseCommand("list", books);
String actualOutput = outContent.toString();
String actualOutput = outContent.toString().replace("\r\n", "\n");

String expectedOutput = "___________________________________\nAll books:\n1. [U] The Great Gatsby\n2. " +
"[U] Geronimo Stilton\n3. [U] Percy Jackson\n_____________\n";
Expand All @@ -94,7 +94,7 @@ void parseListRatedCommand() {

ParserMain.parseCommand("list-rated", books);

String actualOutput = outContent.toString();
String actualOutput = outContent.toString().replace("\r\n", "\n");
String expectedOutput = "Books sorted by rating:\n" +
"The Great Gatsby - 5\n" +
"Geronimo Stilton - 3\n" +
Expand Down Expand Up @@ -151,13 +151,15 @@ void parseLabelCommand() {
@Test
void parseGenreCommand() {
BookList books = new BookList();
BookListModifier.addBook(books, "The Great Gatsby");
//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
ParserMain.parseCommand("add The Great Gatsby", books); // Changed to fit your updated command-handling logic
int genreSize = BookList.getAvailableGenres().size();
String simulatedUserInput = genreSize + 1 + "\nClassic\n";
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
assertEquals("Classic", Genre.getGenre(books.getBook(1)));

BookListModifier.addBook(books, "Geronimo");
String nextSimulatedUserInput = "3\n";
Expand Down

0 comments on commit 72c68bf

Please sign in to comment.