Skip to content

Commit

Permalink
Merge pull request #86 from LouisLouis19/branch-JUnitTest
Browse files Browse the repository at this point in the history
JUnit Test for View Link Command
  • Loading branch information
3m0W33D authored Oct 12, 2021
2 parents fe2c46d + 81235a6 commit 6cce5a4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void setUp() {
}

@Test
void execute_success() throws InvalidCommandException, InvalidArgumentException {
void execute_deleteLink_success() throws InvalidCommandException, InvalidArgumentException {
for (int i = 0; i < 3; i++) {
Command addLinkCommand = linkCommandParser.parseCommand("add \"test_desc\" \"Monday\" \"12:00\" \"https://zoom.us/test\"");
CommandResult addResult = addLinkCommand.execute(ui, nusModule);
Expand All @@ -54,7 +54,7 @@ void execute_success() throws InvalidCommandException, InvalidArgumentException
}

@Test
void execute_throwsException() throws InvalidCommandException, InvalidArgumentException {
void execute_deleteLink_throwsException() throws InvalidCommandException, InvalidArgumentException {
Command deleteLinkCommand = linkCommandParser.parseCommand("delete 20");
assertThrows(InvalidArgumentException.class, () -> deleteLinkCommand.execute(ui, nusModule));
}
Expand Down
81 changes: 81 additions & 0 deletions src/test/java/terminus/command/link/ViewLinkCommandTest.java
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"));
}
}

0 comments on commit 6cce5a4

Please sign in to comment.