Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JUnit test for print list methods #43

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/test/java/seedu/binbash/ItemListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,18 @@ void addItem_itemNameAndDescription_correctItemNameAndDescription() {
assertEquals(item.getItemDescription(), "A test item");
}

@Test
void printList_twoItemsInItemList_correctPrintFormatForBothItems() {
ItemList itemList = new ItemList();

itemList.addItem("testItem", "1");
itemList.addItem("testItem", "2");

String actualOutput = itemList.printList();

String expectedOutput = "testItem: 1" + System.lineSeparator() +
"testItem: 2" + System.lineSeparator();

assertEquals(expectedOutput, actualOutput);
}
}
26 changes: 26 additions & 0 deletions src/test/java/seedu/binbash/command/ListCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.binbash.command;

import org.junit.jupiter.api.Test;
import seedu.binbash.ItemList;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ListCommandTest {

@Test
void execute_listCommandWithTwoItemsInItemList_correctPrintFormatForBothItems() {
ItemList itemList = new ItemList();

itemList.addItem("testItem", "1");
itemList.addItem("testItem", "2");

ListCommand listCommand = new ListCommand(itemList);

String actualOutput = listCommand.execute();

String expectedOutput = "testItem: 1" + System.lineSeparator() +
"testItem: 2" + System.lineSeparator();

assertEquals(expectedOutput, actualOutput);
}
}
6 changes: 3 additions & 3 deletions src/test/java/seedu/binbash/ui/UiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public void restoreStreams() {

@Test
public void testTalk() {
String test_line = "this is a test line of text.";
ui.talk(test_line);
assertEquals(LINE_DIVIDER + System.lineSeparator() + test_line + System.lineSeparator() + LINE_DIVIDER
String testLine = "this is a test line of text.";
ui.talk(testLine);
assertEquals(LINE_DIVIDER + System.lineSeparator() + testLine + System.lineSeparator() + LINE_DIVIDER
+ System.lineSeparator(), outContent.toString());
}
}
Loading