diff --git a/src/test/java/seedu/binbash/command/ProfitCommandTest.java b/src/test/java/seedu/binbash/command/ProfitCommandTest.java new file mode 100644 index 0000000000..c24bb0e74e --- /dev/null +++ b/src/test/java/seedu/binbash/command/ProfitCommandTest.java @@ -0,0 +1,39 @@ +package seedu.binbash.command; + +import org.junit.jupiter.api.Test; + +import seedu.binbash.item.Item; +import seedu.binbash.inventory.ItemList; + +import java.time.LocalDate; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ProfitCommandTest { + + @Test + void execute_calculateTotalProfit() { + ArrayList emptyItemList = new ArrayList<>(); + ItemList itemList = new ItemList(emptyItemList); + + AddCommand addCommand1 = new AddCommand("retail", "Item 1", "Description 1", 1, + LocalDate.now(), 5, 3, 1); + addCommand1.execute(itemList); + + AddCommand addCommand2 = new AddCommand("retail", "Item 2", "Description 2", 1, + LocalDate.now(), 10, 7, 1); + addCommand2.execute(itemList); + + SellCommand sellCommand1 = new SellCommand("Item 1", 1); + sellCommand1.execute(itemList); + + SellCommand sellCommand2 = new SellCommand("Item 2", 1); + sellCommand2.execute(itemList); + + ProfitCommand profitCommand = new ProfitCommand(); + assertTrue(profitCommand.execute(itemList)); + assertEquals("Total profit: $5.00", profitCommand.getExecutionUiOutput().trim()); + } +} diff --git a/src/test/java/seedu/binbash/parser/ParserTest.java b/src/test/java/seedu/binbash/parser/ParserTest.java index 447d66347f..e167d20e6d 100644 --- a/src/test/java/seedu/binbash/parser/ParserTest.java +++ b/src/test/java/seedu/binbash/parser/ParserTest.java @@ -20,6 +20,8 @@ import org.apache.commons.cli.ParseException; import org.junit.jupiter.api.Assertions; +import seedu.binbash.quotes.Quotes; + import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -80,6 +82,21 @@ public void testParseCommand_repeatedQuoteCommand_returnsQuoteCommand() { } } + + @Test + void getRandomQuote_returnsValidQuote() { + String quote = Quotes.getRandomQuote(); + + boolean quoteFound = false; + for (String predefinedQuote : Quotes.CUSTOM_MESSAGES) { + if (predefinedQuote.equals(quote)) { + quoteFound = true; + break; + } + } + assertTrue(quoteFound, "Returned quote is not one of the predefined quotes."); + } + @Test public void testParseCommand_invalidCommand_throwsInvalidCommandException() { assertThrows(InvalidCommandException.class, () -> parser.parseCommand("invalid"));