Skip to content

Commit

Permalink
Merge pull request #73 from HengShuHong/master
Browse files Browse the repository at this point in the history
Add JUnit Test for ExitCommand and HelpCommand
  • Loading branch information
HengShuHong committed Mar 29, 2024
2 parents 71940b8 + ee6e94b commit 39d9ede
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/main/java/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public static boolean getIsExit() {

@Override
public void execute() {

}
}
21 changes: 21 additions & 0 deletions src/test/java/command/ExitCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package command;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ExitCommandTest {
@Test
public void testGetIsExit() {
ExitCommand exitCommand = new ExitCommand(true);
assertTrue(ExitCommand.getIsExit());
}

@Test
public void testExecute() {
ExitCommand exitCommand = new ExitCommand(false);
exitCommand.execute();
assertFalse(ExitCommand.getIsExit());
}
}
21 changes: 21 additions & 0 deletions src/test/java/command/HelpCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package command;

import common.Messages;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

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

public class HelpCommandTest {
@Test
public void testExecute() {
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStreamCaptor));
HelpCommand helpCommand = new HelpCommand();
helpCommand.execute();
String expectedOutput = Messages.HELP + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}
}
1 change: 0 additions & 1 deletion src/test/java/ui/TextUiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void testValidInput() {
@Test
public <T> void testShowInventoryList() {
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
PrintStream originalOut = System.out;
System.setOut(new PrintStream(outputStreamCaptor));
ArrayList<String> itemList = new ArrayList<>();
itemList.add("test 1");
Expand Down

0 comments on commit 39d9ede

Please sign in to comment.