Skip to content

Commit

Permalink
Merge pull request #70 from cnivedit/bugfix/findcommandoutput
Browse files Browse the repository at this point in the history
Fix findItem printing intermediate outputs closes #69
  • Loading branch information
cnivedit authored Oct 14, 2024
2 parents 91e350f + e08ea45 commit 624e838
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/main/java/seedu/pill/util/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ public void listItems() {
* @param itemName The name of the item.
*/
public ItemList findItem(String itemName) {
ItemList foundItems = new ItemList();
ArrayList<Item> foundItems = new ArrayList<Item>();
if (itemName == null || itemName.trim().isEmpty()) {
return foundItems;
return new ItemList(foundItems);
}
for (Item item : items) {
if (item.getName().contains(itemName)) {
foundItems.addItem(item.getName(), item.getQuantity());
foundItems.add(item);
}
}
return foundItems;
return new ItemList(foundItems);
}
}
12 changes: 1 addition & 11 deletions src/test/java/seedu/pill/command/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public void listFindEmptyNotFoundPasses() throws PillException {

//Compare output
String output = outputStream.toString();
output = output.replace("\r\n", "\n");
expectedOutput = expectedOutput.replace("\r\n", "\n");
assertEquals(output, expectedOutput);
}
@Test
Expand All @@ -49,11 +47,7 @@ public void listFindSimplePasses() throws PillException {
FindCommand findCommand = new FindCommand("Band");

// Declare expected output
String outputFromAddFoundTasks = "Added the following item to the inventory: " + System.lineSeparator() +
"Bandage: 20 in stock" + System.lineSeparator() +
"Added the following item to the inventory: " + System.lineSeparator() +
"Band-aid: 5 in stock" + System.lineSeparator();
String expectedOutput = outputFromAddFoundTasks + "Listing all items:" + System.lineSeparator() +
String expectedOutput = "Listing all items:" + System.lineSeparator() +
"1. Bandage: 20 in stock" + System.lineSeparator() +
"2. Band-aid: 5 in stock" + System.lineSeparator();

Expand All @@ -67,8 +61,6 @@ public void listFindSimplePasses() throws PillException {

//Compare output
String output = outputStream.toString();
output = output.replace("\r\n", "\n");
expectedOutput = expectedOutput.replace("\r\n", "\n");
assertEquals(output, expectedOutput);
}
@Test
Expand Down Expand Up @@ -96,8 +88,6 @@ public void listFindNotFoundPasses() throws PillException {

//Compare output
String output = outputStream.toString();
output = output.replace("\r\n", "\n");
expectedOutput = expectedOutput.replace("\r\n", "\n");
assertEquals(output, expectedOutput);
}
}

0 comments on commit 624e838

Please sign in to comment.