diff --git a/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooper.java b/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooper.java index 1980d47b63..30e84cbaf1 100644 --- a/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooper.java +++ b/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooper.java @@ -90,7 +90,7 @@ private static boolean isByeCommand(String input) { return "bye".equalsIgnoreCase(input); } - private String processSelection(String newInput, Scanner scanner, BookList books) + String processSelection(String newInput, Scanner scanner, BookList books) throws InvalidInputException, IOException { int selection = Integer.parseInt(newInput); if (selection == books.genreList.getAvailableGenres().size() + 1) { diff --git a/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenre.java b/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenre.java index 9fad84baee..f1ca9c7b2f 100644 --- a/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenre.java +++ b/src/main/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenre.java @@ -10,7 +10,7 @@ import java.util.Scanner; public class ParserGenre { - static void parseSetGenre(BookList books, String[] inputArray) throws IOException { + static void parseSetGenre(BookList books, String[] inputArray) throws IOException, InvalidCommandArgumentException { Exceptions.validateCommandArguments(inputArray, 2, "The set-genre command requires " + "at least a book index."); diff --git a/src/main/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecks.java b/src/main/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecks.java index 19152019ac..a6671726dd 100644 --- a/src/main/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecks.java +++ b/src/main/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecks.java @@ -26,7 +26,7 @@ public static int parseInteger(String input, String errorMessage) { } // Helper method to check if a string is numeric - private static boolean isNotNumeric(String strNum) { + static boolean isNotNumeric(String strNum) { if (strNum == null) { return true; } diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserAddTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserAddTest.java new file mode 100644 index 0000000000..624278f7c3 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserAddTest.java @@ -0,0 +1,37 @@ +package seedu.bookbuddy.parser.parsercommands; + +import exceptions.InvalidCommandArgumentException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.book.Title; +import seedu.bookbuddy.booklist.BookList; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ParserAddTest { + BookList books = new BookList(); + + @BeforeEach + void setUp() { + books = new BookList(); + } + + @Test + void testValidBookAddition() { + String[] inputArray = {"add", "1984"}; + ParserAdd.executeParseAdd(books, inputArray); + assertEquals(1, books.getSize()); + assertEquals("1984", Title.getTitle(books.getBook(1))); + } + + @Test + void testInsufficientArguments() { + String[] inputArray = {"add"}; + Exception exception = assertThrows(InvalidCommandArgumentException.class, () -> { + ParserAdd.executeParseAdd(books, inputArray); + }); + assertTrue(exception.getMessage().contains("The add Command requires a book title")); + } +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserLabelTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserLabelTest.java new file mode 100644 index 0000000000..75f31bd280 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserLabelTest.java @@ -0,0 +1,47 @@ +package seedu.bookbuddy.parser.parsercommands; + +import exceptions.BookNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.book.Label; +import seedu.bookbuddy.booklist.BookList; +import seedu.bookbuddy.booklist.BookListModifier; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ParserLabelTest { + BookList books = new BookList(); + + @BeforeEach + void setUp() { + books = new BookList(); + BookListModifier.addBook(books, "Geronimo"); + } + + @Test + void testValidLabelSetting() { + String[] inputArray = {"label", "1 Good Book"}; + ParserLabel.executeParseSetLabel(books, inputArray); + assertEquals("Good Book", Label.getLabel(books.getBook(1))); + } + + @Test + void testInvalidIndexNonNumeric() { + String[] inputArray = {"label", "abc haha"}; + Exception exception = assertThrows(BookNotFoundException.class, () -> { + ParserLabel.executeParseSetLabel(books, inputArray); + }); + assertTrue(exception.getMessage().contains("Book index out of range.")); + } + + @Test + void testInvalidIndexOutOfRange() { + String[] inputArray = {"label", "2 haha"}; + Exception exception = assertThrows(BookNotFoundException.class, () -> { + ParserLabel.executeParseSetLabel(books, inputArray); }); + assertTrue(exception.getMessage().contains("Book index out of range")); + } + +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserListTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserListTest.java new file mode 100644 index 0000000000..cbc72ddbb1 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserListTest.java @@ -0,0 +1,72 @@ +package seedu.bookbuddy.parser.parsercommands; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.book.Rating; +import seedu.bookbuddy.booklist.BookList; +import seedu.bookbuddy.booklist.BookListModifier; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ParserListTest { + BookList books = new BookList(); + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + + @BeforeEach + void setUp() { + System.setOut(new PrintStream(outContent)); + books = new BookList(); + BookListModifier.addBook(books, "Geronimo"); + BookListModifier.addBook(books, "Percy Jackson"); + + } + + @AfterEach + void restoreStreams() { + System.setOut(originalOut); + } + + @Test + void testListAllBooks() { + String[] inputArray = {"list"}; + ParserList.executeParseList(books, inputArray, "list"); + assertTrue(outContent.toString().contains("Geronimo")); + } + + @Test + void testListBooksByRating() { + String[] inputArray = {"list-rated"}; + // Assuming book ratings are set and expected to be sorted by ratings + Rating.setRating(books.getBook(2), 5); + ParserList.executeParseList(books, inputArray, "list-rated"); + String expectedOutput = "_____________\n" + + "okii added [Geronimo] to the list.\n" + + "remember to read it soon....\n" + + "_____________\n" + + "_____________\n" + + "okii added [Percy Jackson] to the list.\n" + + " remember to read it soon....\n" + + "_____________\n" + + "Books sorted by rating:\n" + + "Percy Jackson - 5\n" + + "Geronimo - Not Rated"; + + assertEquals(expectedOutput.trim().replaceAll("\\s+", "|"), + outContent.toString().trim().replaceAll("\\s+", "|")); + } + @Test + void testListGenres() { + String[] inputArray = {"list-genre"}; + // Assuming genres are set up + books.genreList.getAvailableGenres().add("Fiction"); + ParserList.executeParseList(books, inputArray, "list-genre"); + assertTrue(outContent.toString().contains("Fiction")); + } + +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserRemoveGenreTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserRemoveGenreTest.java new file mode 100644 index 0000000000..07d94f6655 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/ParserRemoveGenreTest.java @@ -0,0 +1,54 @@ +package seedu.bookbuddy.parser.parsercommands; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.booklist.BookList; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ParserRemoveGenreTest { + BookList books = new BookList(); + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + @BeforeEach + void setUp() { + books = new BookList(); + // To add 3 genres to the arraylist in addition to the default + for (int i = 1; i <= 3; i++) { + books.genreList.getAvailableGenres().add("Genre " + i); + } + System.setOut(new PrintStream(outContent)); + } + @AfterEach + void restoreStreams() { + System.setOut(originalOut); + } + + @Test + void testValidGenreRemoval() { + String[] inputArray = {"remove-genre", "6"}; + ParserRemoveGenre.executeParseRemove(books, inputArray); + assertFalse(books.genreList.getAvailableGenres().contains("Genre 1")); + } + + @Test + void testNonNumericIndex() { + String[] inputArray = {"remove-genre", "abc"}; + ParserRemoveGenre.executeParseRemove(books, inputArray); + String expectedOutput = "abc is not a valid index format"; + assertTrue(outContent.toString().contains(expectedOutput)); + } + @Test + void testIndexOutOfBounds() { + String[] inputArray = {"remove-genre", "11"}; + ParserRemoveGenre.executeParseRemove(books, inputArray); + String expectedOutput = "Genre list is out of bounds"; + assertTrue(outContent.toString().contains(expectedOutput)); + } + +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooperTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooperTest.java new file mode 100644 index 0000000000..122ffa3508 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/InputLooperTest.java @@ -0,0 +1,122 @@ +package seedu.bookbuddy.parser.parsercommands.parsegenre; + +import exceptions.InvalidInputException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.booklist.BookList; +import seedu.bookbuddy.booklist.BookListModifier; + +import java.util.ArrayList; +import java.util.List; + + +import java.io.ByteArrayInputStream; +import java.util.Scanner; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + + +class InputLooperTest { + BookList books = new BookList(); + Scanner scanner = new Scanner(System.in); + private InputLooper inputLooper; + + @BeforeEach + void setUp() { + inputLooper = new InputLooper(); + books = new BookList(); + scanner = new Scanner(System.in); + } + + @Test + void testValidSelection() throws Exception { + String input = "1"; + scanner = new Scanner(new ByteArrayInputStream(input.getBytes())); + String result = inputLooper.processSelection(input, scanner, books); + assertEquals("Fiction", result); + } + + @Test + void testInvalidSelection() { + String input = "20"; // Beyond available genres size + scanner = new Scanner(new ByteArrayInputStream(input.getBytes())); + + Exception exception = assertThrows(InvalidInputException.class, () -> { + inputLooper.processSelection(input, scanner, books); + }); + + assertTrue(exception.getMessage().contains("is an invalid selection")); + } + + @Test + void testEmptyInputHandling() throws Exception { + String input = "\n\n1"; + ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes()); + Scanner scanner = new Scanner(bais); + books.genreList.setAvailableGenres(new ArrayList<>(List.of("Fiction"))); + assertEquals("", inputLooper.inputLooper("", scanner, books)); + } + + @Test + void testExitCommand() throws Exception { + String input = "exit\n"; + System.setIn(new ByteArrayInputStream(input.getBytes())); + Scanner scanner = new Scanner(System.in); + + assertNull(inputLooper.inputLooper(null, scanner, books)); + } + + @Test + void testByeCommand() throws Exception { + String input = "bye\n"; + System.setIn(new ByteArrayInputStream(input.getBytes())); + Scanner scanner = new Scanner(System.in); + + assertNull(inputLooper.inputLooper(null, scanner, books)); + } + + @Test + void testSetGenreToFiction() throws Exception { + String input = "1\n"; + System.setIn(new ByteArrayInputStream(input.getBytes())); + Scanner scanner = new Scanner(System.in); + + assertEquals("Fiction", inputLooper.inputLooper(null, scanner, books)); + } + @Test + void testAddNewGenre() throws Exception { + String initialInput = "3"; + String genreInput = "Mystery"; + String combinedInput = genreInput + "\n"; + System.setIn(new ByteArrayInputStream(combinedInput.getBytes())); + Scanner scanner = new Scanner(System.in); + books.genreList.setAvailableGenres(new ArrayList<>(List.of("Fantasy", "Science Fiction"))); + assertEquals("Mystery", inputLooper.processSelection(initialInput, scanner, books)); + assertTrue(books.genreList.getAvailableGenres().contains("Mystery")); + } + + @Test + void setGenreBookSelectIndexOutOfBounds() { + BookList books = new BookList(); + BookListModifier.addBook(books, "Don Quixote"); + try { + ParserGenre.executeParseSetGenre(books, new String[]{"set-genre", "1"}); + fail(); + } catch (Exception ignored) { + System.out.println("Test in progress"); + } + try { + ParserGenre.executeParseSetGenre(books, new String[]{"set-genre", "-1"}); + fail(); + } catch (Exception ignored) { + System.out.println("Test in progress"); + } + } + + +} + diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/NewGenreModifierTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/NewGenreModifierTest.java new file mode 100644 index 0000000000..76a9459dd3 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/NewGenreModifierTest.java @@ -0,0 +1,52 @@ +package seedu.bookbuddy.parser.parsercommands.parsegenre; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.booklist.BookList; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class NewGenreModifierTest { + BookList books = new BookList(); + private ByteArrayOutputStream outContent; + + @BeforeEach + void setUp() { + books = new BookList(); + books.genreList.setAvailableGenres(new ArrayList<>()); + outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + } + + @Test + void testGenreSelectionPrinterEmptyList() { + NewGenreModifier.genreSelectionPrinter(books); + String expectedOutput = "Available genres:\n1. Add a new genre\n"; + assertEquals(expectedOutput, outContent.toString()); + } + + @Test + void testDuplicateCheckerWithNewGenre() { + String newGenre = "Mystery"; + assertEquals(newGenre, NewGenreModifier.duplicateChecker(newGenre, books)); + assertTrue(books.genreList.getAvailableGenres().contains(newGenre)); + } + + @Test + void testDuplicateCheckerWithExistingGenre() { + String existingGenre = "Fantasy"; + books.genreList.getAvailableGenres().add(existingGenre); + assertEquals(existingGenre, NewGenreModifier.duplicateChecker("fantasy", books)); + } + + @Test + void testDuplicateCheckerWithNullInput() { + assertNull(NewGenreModifier.duplicateChecker(null, books)); + } +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenreTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenreTest.java new file mode 100644 index 0000000000..0482192053 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/parsegenre/ParserGenreTest.java @@ -0,0 +1,98 @@ +package seedu.bookbuddy.parser.parsercommands.parsegenre; + +import exceptions.InvalidCommandArgumentException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.book.Genre; +import seedu.bookbuddy.booklist.BookList; +import seedu.bookbuddy.booklist.BookListModifier; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ParserGenreTest { + BookList books = new BookList(); + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + + @BeforeEach + void setUp() { + books = new BookList(); + System.setOut(new PrintStream(outContent)); + } + + @Test + void testValidSingleStepGenreSetting() throws Exception { + BookListModifier.addBook(books, "Geronimo"); + String[] inputArray = {"set-genre", "1 Mystery"}; + ParserGenre.executeParseSetGenre(books, inputArray); + assertEquals("Mystery", Genre.getGenre(books.getBook(1))); + } + + @Test + void testInvalidBookIndex() { + String[] inputArray = {"set-genre", "2 Mystery"}; + Exception exception = assertThrows(InvalidCommandArgumentException.class, () -> { + ParserGenre.executeParseSetGenre(books, inputArray); + }); + assertTrue(exception.getMessage().contains("Invalid book index")); + } + + @Test + void testInvalidInputFormat() throws IOException { + String[] inputArray = {"set-genre", "abc Mystery"}; + ParserGenre.executeParseSetGenre(books, inputArray); + assertTrue(outContent.toString().contains("Invalid book index format")); + } + + @Test + void testValidMultiStepGenreSetting() throws Exception { + BookListModifier.addBook(books, "Geronimo"); + String genreInput = "1\n"; + System.setIn(new ByteArrayInputStream(genreInput.getBytes())); + String[] inputArray = {"set-genre", "1"}; + ParserGenre.executeParseSetGenre(books, inputArray); + assertEquals("Fiction", Genre.getGenre(books.getBook(1))); + } + + @Test + void testEmptyInputArray() { + String[] inputArray = {}; + Exception exception = assertThrows(InvalidCommandArgumentException.class, () -> { + ParserGenre.executeParseSetGenre(books, inputArray); + }); + assertTrue(exception.getMessage().contains("The set-genre command requires at least a book index.")); + } + + @Test + void testBoundaryBookIndexZero() { + String[] inputArray = {"set-genre", "0 Mystery"}; + Exception exception = assertThrows(InvalidCommandArgumentException.class, () -> { + ParserGenre.executeParseSetGenre(books, inputArray); + }); + assertTrue(exception.getMessage().contains("Invalid book index")); + } + + @Test + void testBoundaryBookIndexMaxPlusOne() { + BookListModifier.addBook(books, "Geronimo"); + String[] inputArray = {"set-genre", "2 Mystery"}; + Exception exception = assertThrows(InvalidCommandArgumentException.class, () -> { + ParserGenre.executeParseSetGenre(books, inputArray); + }); + assertTrue(exception.getMessage().contains("Invalid book index")); + } + + @Test + void testExtraSpacesInInput() throws IOException { + BookListModifier.addBook(books, "Geronimo"); + String[] inputArray = {"set-genre", " 1 Mystery "}; + ParserGenre.executeParseSetGenre(books, inputArray); + assertEquals("Mystery", Genre.getGenre(books.getBook(1))); + } +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/parserating/ParserRatingTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/parserating/ParserRatingTest.java new file mode 100644 index 0000000000..73965f58ac --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/parserating/ParserRatingTest.java @@ -0,0 +1,55 @@ +package seedu.bookbuddy.parser.parsercommands.parserating; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import seedu.bookbuddy.book.Rating; +import seedu.bookbuddy.booklist.BookList; +import seedu.bookbuddy.booklist.BookListModifier; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ParserRatingTest { + BookList books = new BookList(); + + @BeforeEach + void setUp() { + books = new BookList(); + BookListModifier.addBook(books, "Geronimo"); + } + + @Test + void testValidInput() { + String[] inputArray = {"rate", "1 5"}; + ParserRating.executeParseSetRating(books, inputArray); + assertEquals(5, Rating.getRating(books.getBook(1))); // Assuming Book has getRating method + } + + @Test + void testInvalidIndex() { + String[] inputArray = {"rate", "5 3"}; + Exception exception = assertThrows(IndexOutOfBoundsException.class, () -> { + ParserRating.executeParseSetRating(books, inputArray); + }); + assertTrue(exception.getMessage().contains("Invalid book index selection")); + } + + @Test + void testInvalidRating() { + String[] inputArray = {"rate", "1 10"}; + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + ParserRating.executeParseSetRating(books, inputArray); + }); + assertTrue(exception.getMessage().contains("Rating must be between 1 and 5")); + } + + @Test + void testInsufficientArguments() { + String[] inputArray = {"rate"}; + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + ParserRating.executeParseSetRating(books, inputArray); + }); + assertTrue(exception.getMessage().contains("The rating command requires a book index.")); + } +} diff --git a/src/test/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecksTest.java b/src/test/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecksTest.java new file mode 100644 index 0000000000..7d563fb471 --- /dev/null +++ b/src/test/java/seedu/bookbuddy/parser/parsercommands/parserating/RatingChecksTest.java @@ -0,0 +1,68 @@ +package seedu.bookbuddy.parser.parsercommands.parserating; + +import exceptions.InvalidCommandArgumentException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class RatingChecksTest { + + @Test + void testGetRatingPartsValidInput() { + String[] inputArray = {"rate", "1 5"}; + String[] parts = RatingChecks.getRatingParts(inputArray); + assertArrayEquals(new String[]{"1", "5"}, parts); + } + + @Test + void testGetRatingPartsInvalidInput() { + String[] inputArray = {"rate", "one five"}; + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + RatingChecks.getRatingParts(inputArray); + }); + assertTrue(exception.getMessage().contains("one and five are not valid integers")); + } + + @Test + void testGetRatingPartsIncompleteArguments() { + String[] inputArray = {"rate", "1"}; + Exception exception = assertThrows(InvalidCommandArgumentException.class, () -> { + RatingChecks.getRatingParts(inputArray); + }); + assertTrue(exception.getMessage().contains("You need to have a book index and a rating")); + } + + @Test + void testParseIntegerValid() { + assertEquals(5, RatingChecks.parseInteger("5", "Error parsing integer")); + } + + @Test + void testParseIntegerInvalid() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + RatingChecks.parseInteger("abc", "abc is not a valid integer"); + }); + assertTrue(exception.getMessage().contains("abc is not a valid integer")); + } + + @Test + void testIsNotNumericFalse() { + assertFalse(RatingChecks.isNotNumeric("123")); + } + + @Test + void testIsNotNumericTrue() { + assertTrue(RatingChecks.isNotNumeric("abc")); + } + + @Test + void testIsNotNumericNull() { + assertTrue(RatingChecks.isNotNumeric(null)); + } + + +}