forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #112 from marquestye/info-command
Add tests for InfoCommand and InfoCommandParser
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/test/java/seedu/address/logic/commands/InfoCommandTest.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,64 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.module.ModuleCode; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for | ||
* {@code InfoCommand}. | ||
*/ | ||
public class InfoCommandTest { | ||
|
||
private Model model = new ModelManager(); | ||
private Model expectedModel = new ModelManager(); | ||
|
||
@Test | ||
public void execute_sampleMessage_success() { | ||
ModuleCode moduleCode = new ModuleCode("CS1101S"); | ||
String expectedMessage = InfoCommand.MESSAGE_INFO_MODULE_SUCCESS_SAMPLE; | ||
|
||
assertCommandSuccess(new InfoCommand(moduleCode), model, expectedMessage, expectedModel); | ||
} | ||
|
||
|
||
@Test | ||
public void equals() { | ||
ModuleCode firstCode = new ModuleCode("CS2030S"); | ||
ModuleCode secondCode = new ModuleCode("CS2040S"); | ||
InfoCommand infoFirstCommand = new InfoCommand(firstCode); | ||
InfoCommand infoSecondCommand = new InfoCommand(secondCode); | ||
|
||
// same object -> returns true | ||
assertTrue(infoFirstCommand.equals(infoFirstCommand)); | ||
|
||
// same values -> returns true | ||
InfoCommand infoFirstCommandCopy = new InfoCommand(firstCode); | ||
assertTrue(infoFirstCommand.equals(infoFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(infoFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(infoFirstCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(infoFirstCommand.equals(infoSecondCommand)); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
ModuleCode moduleCode = new ModuleCode("CS1101S"); | ||
InfoCommand infoCommand = new InfoCommand(moduleCode); | ||
String expected = InfoCommand.class.getCanonicalName() + "{moduleCode=" + moduleCode + "}"; | ||
assertEquals(expected, infoCommand.toString()); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/seedu/address/logic/parser/InfoCommandParserTest.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,37 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.model.module.ModuleCode.MESSAGE_CONSTRAINTS; | ||
import static seedu.address.logic.commands.InfoCommand.MESSAGE_USAGE; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class InfoCommandParserTest { | ||
|
||
private InfoCommandParser parser = new InfoCommandParser(); | ||
|
||
@Test | ||
public void parse_invalidSingleArg_throwsParseException() { | ||
// Module code constraint exception should be thrown when the given argument | ||
// contains only one word | ||
|
||
// Single alphanumeric word (no spaces) | ||
assertParseFailure(parser, "a1b2c3", MESSAGE_CONSTRAINTS); | ||
|
||
// Single word with non-alphanumeric characters | ||
assertParseFailure(parser, "a_b\\c:e", MESSAGE_CONSTRAINTS); | ||
} | ||
|
||
@Test | ||
public void parse_invalidMultipleArgs_throwsParseException() { | ||
// Command format exception should be thrown instead of module code constraint | ||
// exception when the given argument contains more than one word | ||
|
||
String message = String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE); | ||
|
||
// Multiple words with spaces | ||
assertParseFailure(parser, "abc de", message); | ||
assertParseFailure(parser, "a b c d e", message); | ||
} | ||
} |