forked from AY2425S1-CS2113-W14-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,161 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package seedu.pill.command; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import seedu.pill.exceptions.PillException; | ||
import seedu.pill.util.ItemMap; | ||
import seedu.pill.util.Storage; | ||
import seedu.pill.util.Order; | ||
import seedu.pill.util.TransactionManager; | ||
import seedu.pill.util.Item; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
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; | ||
|
||
/** | ||
* Unit tests for FulfillCommand | ||
*/ | ||
public class FulfillCommandTest { | ||
private ItemMap itemMap; | ||
private Storage storage; | ||
private TransactionManager transactionManager; | ||
private ByteArrayOutputStream outputStream; | ||
private PrintStream printStream; | ||
private final PrintStream standardOut = System.out; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
itemMap = new ItemMap(); | ||
storage = new Storage(); | ||
transactionManager = new TransactionManager(itemMap); | ||
outputStream = new ByteArrayOutputStream(); | ||
printStream = new PrintStream(outputStream); | ||
System.setOut(printStream); | ||
} | ||
|
||
@Test | ||
public void execute_insufficientStock_throwsException() { | ||
// Create dispense order without sufficient stock | ||
ItemMap orderItems = new ItemMap(); | ||
orderItems.addItemSilent(new Item("Paracetamol", 10)); | ||
Order order = transactionManager.createOrder(Order.OrderType.DISPENSE, orderItems, "Test failure"); | ||
|
||
FulfillCommand command = new FulfillCommand(order, transactionManager); | ||
|
||
assertThrows(PillException.class, () -> command.execute(itemMap, storage)); | ||
} | ||
|
||
@Test | ||
public void isExit_returnsAlwaysFalse() { | ||
ItemMap orderItems = new ItemMap(); | ||
Order order = transactionManager.createOrder(Order.OrderType.PURCHASE, orderItems, "Test"); | ||
FulfillCommand command = new FulfillCommand(order, transactionManager); | ||
assertFalse(command.isExit()); | ||
} | ||
|
||
@AfterEach | ||
public void restoreSystemOut() { | ||
System.setOut(standardOut); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package seedu.pill.command; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import seedu.pill.exceptions.PillException; | ||
import seedu.pill.util.ItemMap; | ||
import seedu.pill.util.Storage; | ||
import seedu.pill.util.TransactionManager; | ||
import seedu.pill.util.Order; | ||
import seedu.pill.util.Item; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
public class OrderCommandTest { | ||
private ItemMap itemMap; | ||
private Storage storage; | ||
private TransactionManager transactionManager; | ||
private ByteArrayOutputStream outputStream; | ||
private PrintStream printStream; | ||
private final PrintStream standardOut = System.out; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
itemMap = new ItemMap(); | ||
storage = new Storage(); | ||
transactionManager = new TransactionManager(itemMap); | ||
outputStream = new ByteArrayOutputStream(); | ||
printStream = new PrintStream(outputStream); | ||
System.setOut(printStream); | ||
} | ||
|
||
@Test | ||
public void execute_purchaseOrder_createsOrder() throws PillException { | ||
ItemMap itemsToOrder = new ItemMap(); | ||
itemsToOrder.addItemSilent(new Item("Paracetamol", 10)); | ||
|
||
OrderCommand command = new OrderCommand(itemsToOrder, transactionManager, | ||
Order.OrderType.PURCHASE); | ||
command.execute(itemMap, storage); | ||
|
||
assertEquals(1, transactionManager.getOrders().size()); | ||
Order createdOrder = transactionManager.getOrders().get(0); | ||
assertEquals(Order.OrderType.PURCHASE, createdOrder.getType()); | ||
} | ||
|
||
@Test | ||
public void execute_dispenseOrder_createsOrder() throws PillException { | ||
ItemMap itemsToOrder = new ItemMap(); | ||
itemsToOrder.addItemSilent(new Item("Paracetamol", 5)); | ||
|
||
OrderCommand command = new OrderCommand(itemsToOrder, transactionManager, | ||
Order.OrderType.DISPENSE); | ||
command.execute(itemMap, storage); | ||
|
||
assertEquals(1, transactionManager.getOrders().size()); | ||
Order createdOrder = transactionManager.getOrders().get(0); | ||
assertEquals(Order.OrderType.DISPENSE, createdOrder.getType()); | ||
} | ||
|
||
@Test | ||
public void isExit_returnsAlwaysFalse() { | ||
OrderCommand command = new OrderCommand(new ItemMap(), transactionManager, | ||
Order.OrderType.PURCHASE); | ||
assertFalse(command.isExit()); | ||
} | ||
|
||
@AfterEach | ||
public void restoreSystemOut() { | ||
System.setOut(standardOut); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/test/java/seedu/pill/command/RestockAllCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package seedu.pill.command; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import seedu.pill.exceptions.PillException; | ||
import seedu.pill.util.ItemMap; | ||
import seedu.pill.util.Storage; | ||
import seedu.pill.util.Item; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.time.LocalDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class RestockAllCommandTest { | ||
private ItemMap itemMap; | ||
private Storage storage; | ||
private ByteArrayOutputStream outputStream; | ||
private PrintStream printStream; | ||
private final PrintStream standardOut = System.out; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
itemMap = new ItemMap(); | ||
storage = new Storage(); | ||
outputStream = new ByteArrayOutputStream(); | ||
printStream = new PrintStream(outputStream); | ||
System.setOut(printStream); | ||
} | ||
|
||
@Test | ||
public void execute_noItemsBelowThreshold_printsNoChanges() throws PillException { | ||
itemMap.addItemSilent(new Item("Paracetamol", 20, LocalDate.now(), 5.0, 7.0)); | ||
itemMap.addItemSilent(new Item("Aspirin", 15, LocalDate.now(), 4.0, 6.0)); | ||
|
||
RestockAllCommand command = new RestockAllCommand(10); | ||
command.execute(itemMap, storage); | ||
|
||
String output = outputStream.toString().trim(); | ||
assertTrue(output.contains("Total Restock Cost for all items below threshold 10: $0.00")); | ||
} | ||
|
||
@Test | ||
public void execute_calculatesCorrectCosts() throws PillException { | ||
itemMap.addItemSilent(new Item("Paracetamol", 5, LocalDate.now(), 5.0, 7.0)); | ||
// Need to restock 5 units at $5.0 each = $25.0 | ||
|
||
RestockAllCommand command = new RestockAllCommand(10); | ||
command.execute(itemMap, storage); | ||
|
||
String output = outputStream.toString().trim(); | ||
assertTrue(output.contains("Restock Cost: $25.00")); | ||
assertTrue(output.contains("Total Restock Cost for all items below threshold 10: $25.00")); | ||
} | ||
|
||
@Test | ||
public void isExit_returnsAlwaysFalse() { | ||
RestockAllCommand command = new RestockAllCommand(10); | ||
assertFalse(command.isExit()); | ||
} | ||
|
||
@AfterEach | ||
public void restoreSystemOut() { | ||
System.setOut(standardOut); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/seedu/pill/command/RestockItemCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package seedu.pill.command; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import seedu.pill.exceptions.ExceptionMessages; | ||
import seedu.pill.exceptions.PillException; | ||
import seedu.pill.util.ItemMap; | ||
import seedu.pill.util.Storage; | ||
import seedu.pill.util.Item; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
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; | ||
|
||
public class RestockItemCommandTest { | ||
private ItemMap itemMap; | ||
private Storage storage; | ||
private ByteArrayOutputStream outputStream; | ||
private PrintStream printStream; | ||
private final PrintStream standardOut = System.out; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
itemMap = new ItemMap(); | ||
storage = new Storage(); | ||
outputStream = new ByteArrayOutputStream(); | ||
printStream = new PrintStream(outputStream); | ||
System.setOut(printStream); | ||
} | ||
|
||
@Test | ||
public void execute_itemDoesNotExist_throwsException() { | ||
RestockItemCommand command = new RestockItemCommand( | ||
"NonexistentItem", Optional.empty(), 10); | ||
|
||
assertThrows(PillException.class, () -> command.execute(itemMap, storage) | ||
); | ||
} | ||
|
||
@Test | ||
public void isExit_returnsAlwaysFalse() { | ||
RestockItemCommand command = new RestockItemCommand( | ||
"test", Optional.empty(), 10); | ||
assertFalse(command.isExit()); | ||
} | ||
|
||
@AfterEach | ||
public void restoreSystemOut() { | ||
System.setOut(standardOut); | ||
} | ||
} |
Oops, something went wrong.