Skip to content

Commit

Permalink
edited FindCommandTest cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbaracwx committed Oct 19, 2023
1 parent 7d3d198 commit 44e4e27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/main/java/seedu/stocker/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public Optional<List<Drug>> getRelevantDrugs() {
return Optional.ofNullable(relevantDrugs);
}


public String getFeedbackToUserFindTest() {
if (relevantDrugs != null) {
StringBuilder feedback = new StringBuilder();
for (int i = 0; i < relevantDrugs.size(); i++) {
feedback.append(i+1).append(". ").append(relevantDrugs.get(i));
feedback.append(System.lineSeparator());
}
feedback.append(System.lineSeparator());
feedback.append(feedbackToUser);
return feedback.toString();
} else {
return feedbackToUser;
}
}

}
12 changes: 10 additions & 2 deletions src/test/java/seedu/stocker/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ public void executeTest() {
Inventory inventory = new Inventory();
Drug drug1 = new Drug("Paracetamol", "12/05/2024", 12L);
inventory.addDrug(drug1);
Drug drug2 = new Drug("Panadol", "01/03/2027", 20L);
inventory.addDrug(drug2);


// Set the modified inventory for the command
command.setData(inventory);


// Define expected output
String expectedOutput = "Listed all drugs with the keyword in the inventory.";
String expectedOutput = "1. Name: Paracetamol, Expiry Date: 12/05/2024, Quantity: 12" +
System.lineSeparator() +
"2. Name: Panadol, Expiry Date: 01/03/2027, Quantity: 20" + System.lineSeparator() +
System.lineSeparator() +
"Listed all drugs with the keyword in the inventory.";



CommandResult actualResult = command.execute();

// Test the command's execute method with the modified inventory
assertEquals(expectedOutput, actualResult.feedbackToUser);
assertEquals(expectedOutput, actualResult.getFeedbackToUserFindTest());
}
}

0 comments on commit 44e4e27

Please sign in to comment.