Skip to content

Commit

Permalink
junit update
Browse files Browse the repository at this point in the history
  • Loading branch information
yeozongyao committed Mar 21, 2024
1 parent 5f09440 commit 3aa4aad
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/test/java/seedu/bookbuddy/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
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;
Expand Down Expand Up @@ -68,11 +72,21 @@ void parseInvalidAddCommandThrowsException() {
}

@Test
void parseInvalidRemoveCommandThrowsException() {
void parseInvalidRemoveCommandPrintsError() {
// Set up
BookList books = new BookList();
String input = "remove notAnIndex"; // Invalid index provided
assertThrows(NumberFormatException.class,
() -> Parser.parseCommand(input, books), "Book index must be an integer.");
String input = "remove notAnIndex";
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent)); // Redirect standard out to capture console output
// Act
Parser.parseCommand(input, books);

// Assert
String output = outContent.toString();
assertTrue(output.contains("not a valid number"), "Error message should contain 'not a valid number'");

// Cleanup
System.setOut(System.out); // Reset standard out
}

@Test
Expand Down

0 comments on commit 3aa4aad

Please sign in to comment.