Skip to content

Commit

Permalink
Merge pull request #290 from XavierLiau34/master
Browse files Browse the repository at this point in the history
Increased Test Coverage
  • Loading branch information
XavierLiau34 authored Apr 15, 2024
2 parents a84f7ce + e3ee86e commit 34dd453
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/test/java/seedu/binbash/command/ProfitCommandTest.java
Original file line number Diff line number Diff line change
@@ -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<Item> 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());
}
}
17 changes: 17 additions & 0 deletions src/test/java/seedu/binbash/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 34dd453

Please sign in to comment.