diff --git a/src/test/java/seedu/bookbuddy/BookBuddyTest.java b/src/test/java/seedu/bookbuddy/BookBuddyTest.java index 1b96cd7edf..659ce88bce 100644 --- a/src/test/java/seedu/bookbuddy/BookBuddyTest.java +++ b/src/test/java/seedu/bookbuddy/BookBuddyTest.java @@ -30,15 +30,24 @@ public void sampleTest() { @Test public void testPrintWelcomeMessage() { BookBuddy.printWelcomeMessage(); - String expectedOutput = "Hello! We are BookBuddy!\nHow can I help you today?\n"; - assertEquals(expectedOutput, outContent.toString()); + String actualOutput = outContent.toString(); + + // Normalize line endings to \n in both expected and actual output + String normalizedExpectedOutput = "Hello! We are BookBuddy!\nHow can I help you today?\n".replace("\r\n", "\n"); + String normalizedActualOutput = actualOutput.replace("\r\n", "\n"); + + // Assert that the normalized outputs are equal + assertEquals(normalizedExpectedOutput, normalizedActualOutput); } + + + @Test public void testPrintExitMessage() { BookBuddy.printExitMessage(); String expectedOutput = "Thank you for using BookBuddy! Hope to see you again!\n"; - assertEquals(expectedOutput, outContent.toString()); + assertEquals(expectedOutput.trim(), outContent.toString().trim()); } -} \ No newline at end of file +} diff --git a/src/test/java/seedu/bookbuddy/BookListTest.java b/src/test/java/seedu/bookbuddy/BookListTest.java index 8473bd95e0..5f5be930b6 100644 --- a/src/test/java/seedu/bookbuddy/BookListTest.java +++ b/src/test/java/seedu/bookbuddy/BookListTest.java @@ -5,7 +5,9 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + class BookListTest { @@ -34,7 +36,8 @@ void printAllBooks() { testBookList.printAllBooks(); String expectedOutput = "All books:\n1. [U] Harry Potter\n"; - assertEquals(expectedOutput, outContent.toString()); + String normalizedActualOutput = outContent.toString().replace("\r\n", "\n"); + assertEquals(expectedOutput.trim(), normalizedActualOutput.trim()); System.setOut(System.out); } diff --git a/src/test/java/seedu/bookbuddy/ParserTest.java b/src/test/java/seedu/bookbuddy/ParserTest.java index 90a0d674fe..57139669f6 100644 --- a/src/test/java/seedu/bookbuddy/ParserTest.java +++ b/src/test/java/seedu/bookbuddy/ParserTest.java @@ -5,13 +5,12 @@ import exceptions.InvalidCommandArgumentException; import exceptions.UnsupportedCommandException; import org.junit.jupiter.api.Test; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; + public class ParserTest { @Test void testParser() {