diff --git a/src/main/java/seedu/address/model/medicine/Quantity.java b/src/main/java/seedu/address/model/medicine/Quantity.java index 8c089b07c824..961a89d9bc55 100644 --- a/src/main/java/seedu/address/model/medicine/Quantity.java +++ b/src/main/java/seedu/address/model/medicine/Quantity.java @@ -7,7 +7,7 @@ * Represents the quantity of a Medicine in the inventory. * Guarantees: immutable; is valid as declared in {@link #isValidQuantity(String)} */ -public class Quantity { +public class Quantity implements Comparable { public static final int MAX_QUANTITY = 1000000000; public static final int MIN_QUANTITY = 0; @@ -60,6 +60,11 @@ public boolean equals(Object other) { && value == ((Quantity) other).value); // state check } + @Override + public int compareTo(Quantity other) { + return Integer.compare(getNumericValue(), other.getNumericValue()); + } + @Override public int hashCode() { return this.toString().hashCode(); diff --git a/src/test/data/JsonSerializableInventoryTest/typicalMedicinesInventory.json b/src/test/data/JsonSerializableInventoryTest/typicalMedicinesInventory.json index a71f4b00d8f9..e26c694adc26 100644 --- a/src/test/data/JsonSerializableInventoryTest/typicalMedicinesInventory.json +++ b/src/test/data/JsonSerializableInventoryTest/typicalMedicinesInventory.json @@ -33,6 +33,11 @@ "batchNumber" : "GKP1685", "expiry" : "15/08/2019", "quantity" : "300" + }, + { + "batchNumber" : "GKP1682", + "expiry" : "31/07/2019", + "quantity" : "5" } ] }, { "name" : "Lipitor", diff --git a/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java b/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java index 5c17a0f07999..6fac03b8856f 100644 --- a/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/UpdateCommandTest.java @@ -30,6 +30,7 @@ import seedu.address.model.UserPrefs; import seedu.address.model.medicine.Batch; import seedu.address.model.medicine.BatchNumber; +import seedu.address.model.medicine.Expiry; import seedu.address.model.medicine.Medicine; import seedu.address.model.medicine.Quantity; import seedu.address.testutil.BatchBuilder; @@ -201,16 +202,17 @@ public void execute_removeBatchUnfilteredListOneOtherBatch_success() { Batch batchToRemove = iter.next(); assertTrue(iter.hasNext()); // There is one more batch after removing - Batch batchRemaining = iter.next(); batches.remove(batchToRemove.getBatchNumber()); int newQuantity = medicineToUpdate.getTotalQuantity().getNumericValue() - batchToRemove.getQuantity().getNumericValue(); + Expiry newExpiry = batches.values().stream().min(Comparator.comparing(Batch::getExpiry)).get().getExpiry(); + Medicine updatedMedicine = new MedicineBuilder(medicineToUpdate) .withQuantity(Integer.toString(newQuantity)) - .withExpiry(batchRemaining.getExpiry().toString()) + .withExpiry(newExpiry.toString()) .withBatches(batches).build(); Batch inputBatch = new BatchBuilder(batchToRemove).withQuantity("0").build(); diff --git a/src/test/java/seedu/address/testutil/TypicalMedicines.java b/src/test/java/seedu/address/testutil/TypicalMedicines.java index 941b1f7c4d08..2f5bcade196a 100644 --- a/src/test/java/seedu/address/testutil/TypicalMedicines.java +++ b/src/test/java/seedu/address/testutil/TypicalMedicines.java @@ -34,7 +34,8 @@ public class TypicalMedicines { .withQuantity("0").withExpiry("-").build(); public static final Medicine LEVOTHYROXINE = new MedicineBuilder().withName("Levothyroxine Sodium") .withCompany("3M Pharmaceuticals").withQuantity("533").withExpiry("13/08/2019").withTags("thyroid") - .withBatches("GKP1684", "233", "13/08/2019", "GKP1685", "300", "15/08/2019").build(); + .withBatches("GKP1684", "233", "13/08/2019", "GKP1685", "300", "15/08/2019", "GKP1682", "5", "31/07/2019") + .build(); public static final Medicine LISINOPRIL = new MedicineBuilder().withName("Lisinopril") .withCompany("Takeda Pharmaceutical Co.").withQuantity("94").withExpiry("06/07/2019") .withBatches("307002", "94", "06/07/2019").build(); diff --git a/src/test/java/seedu/address/ui/InformationPanelTest.java b/src/test/java/seedu/address/ui/InformationPanelTest.java index e561c28ae46b..72483c48ec3a 100644 --- a/src/test/java/seedu/address/ui/InformationPanelTest.java +++ b/src/test/java/seedu/address/ui/InformationPanelTest.java @@ -99,10 +99,10 @@ private void assertSorted(List data, SortProperty sortProperty, SortDirec sortedData.sort(Comparator.comparing(b -> b.getBatchNumber().toString())); break; case EXPIRY: - sortedData.sort(Comparator.comparing(b -> b.getExpiry())); + sortedData.sort(Comparator.comparing(Batch::getExpiry)); break; case QUANTITY: - sortedData.sort(Comparator.comparing(b -> b.getQuantity().getNumericValue())); + sortedData.sort(Comparator.comparing(Batch::getQuantity)); break; default: throw new IllegalArgumentException("Unknown Sort Property");