forked from nus-cs2113-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from LouisLouis19/branch-JUnitTest
JUnit Test for View Link Command
- Loading branch information
Showing
2 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/terminus/command/link/ViewLinkCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package terminus.command.link; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import terminus.command.Command; | ||
import terminus.command.CommandResult; | ||
import terminus.content.Link; | ||
import terminus.exception.InvalidArgumentException; | ||
import terminus.exception.InvalidCommandException; | ||
import terminus.module.NusModule; | ||
import terminus.parser.LinkCommandParser; | ||
import terminus.ui.Ui; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class ViewLinkCommandTest { | ||
|
||
private LinkCommandParser linkCommandParser; | ||
private NusModule nusModule; | ||
private Ui ui; | ||
|
||
Class<Link> type = Link.class; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
this.linkCommandParser = LinkCommandParser.getInstance(); | ||
this.nusModule = new NusModule(); | ||
this.ui = new Ui(); | ||
} | ||
|
||
@Test | ||
void execute_viewAll_success() throws InvalidCommandException, InvalidArgumentException { | ||
for (int i = 0; i < 5; i++) { | ||
Command addLinkCommand = linkCommandParser.parseCommand( | ||
"add \"test\" \"Saturday\" \"00:00\" \"https://zoom.us/test\""); | ||
CommandResult addLinkResult = addLinkCommand.execute(ui, nusModule); | ||
assertTrue(addLinkResult.isOk()); | ||
} | ||
assertEquals(5, nusModule.getContentManager(type).getTotalContents()); | ||
|
||
Command viewLinkCommand = linkCommandParser.parseCommand("view"); | ||
CommandResult viewLinkResult = viewLinkCommand.execute(ui, nusModule); | ||
assertTrue(viewLinkResult.isOk()); | ||
} | ||
|
||
@Test | ||
void execute_viewLink_success() throws InvalidCommandException, InvalidArgumentException { | ||
for (int i = 0; i < 5; i++) { | ||
Command addLinkCommand = linkCommandParser.parseCommand( | ||
"add \"test\" \"Saturday\" \"00:00\" \"https://zoom.us/test\""); | ||
CommandResult addLinkResult = addLinkCommand.execute(ui, nusModule); | ||
assertTrue(addLinkResult.isOk()); | ||
} | ||
assertEquals(5, nusModule.getContentManager(type).getTotalContents()); | ||
|
||
Command viewLinkCommand = linkCommandParser.parseCommand("view 1"); | ||
CommandResult viewLinkResult = viewLinkCommand.execute(ui, nusModule); | ||
assertTrue(viewLinkResult.isOk()); | ||
|
||
viewLinkCommand = linkCommandParser.parseCommand("view 5"); | ||
viewLinkResult = viewLinkCommand.execute(ui, nusModule); | ||
assertTrue(viewLinkResult.isOk()); | ||
} | ||
|
||
@Test | ||
void execute_viewLink_exceptionThrown() throws InvalidCommandException, InvalidArgumentException { | ||
for (int i = 0; i < 5; i++) { | ||
Command addLinkCommand = linkCommandParser.parseCommand( | ||
"add \"test\" \"Saturday\" \"00:00\" \"https://zoom.us/test\""); | ||
CommandResult addLinkResult = addLinkCommand.execute(ui, nusModule); | ||
assertTrue(addLinkResult.isOk()); | ||
} | ||
assertEquals(5, nusModule.getContentManager(type).getTotalContents()); | ||
|
||
assertThrows(InvalidArgumentException.class, () -> linkCommandParser.parseCommand("view -1")); | ||
assertThrows(InvalidArgumentException.class, () -> linkCommandParser.parseCommand("view X")); | ||
assertThrows(InvalidCommandException.class, () -> linkCommandParser.parseCommand("viewwwww")); | ||
} | ||
} |