Skip to content

Commit

Permalink
Merge pull request #112 from marquestye/info-command
Browse files Browse the repository at this point in the history
Add tests for InfoCommand and InfoCommandParser
  • Loading branch information
rocketninja7 authored Oct 19, 2023
2 parents a0a28ff + b438489 commit 88d7e3c
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/test/java/seedu/address/logic/commands/InfoCommandTest.java
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());
}

}
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);
}
}

0 comments on commit 88d7e3c

Please sign in to comment.