forked from nus-cs2103-AY2425S1/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 #122 from avrilmohh/remark-command-tests
Add test cases for remark implementation
- Loading branch information
Showing
4 changed files
with
233 additions
and
5 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
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
120 changes: 120 additions & 0 deletions
120
src/test/java/seedu/address/logic/commands/RemarkCommandTest.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,120 @@ | ||
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.VALID_REMARK_MATH; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.logic.commands.CommandTestUtil.showStudentAtIndex; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_STUDENT; | ||
import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.student.Student; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for | ||
* {@code RemarkCommand}. | ||
*/ | ||
public class RemarkCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_validIndexUnfilteredList_success() { | ||
Student studentToAddRemark = model.getFilteredStudentList().get(INDEX_FIRST_STUDENT.getZeroBased()); | ||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_STUDENT, VALID_REMARK_MATH); | ||
|
||
Student updatedStudent = new Student(studentToAddRemark, VALID_REMARK_MATH); | ||
|
||
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, | ||
Messages.format(updatedStudent)); | ||
|
||
ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
expectedModel.setStudent(studentToAddRemark, updatedStudent); | ||
|
||
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidIndexUnfilteredList_throwsCommandException() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredStudentList().size() + 1); | ||
RemarkCommand remarkCommand = new RemarkCommand(outOfBoundIndex, VALID_REMARK_MATH); | ||
|
||
assertCommandFailure(remarkCommand, model, Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX); | ||
} | ||
|
||
@Test | ||
public void execute_validIndexFilteredList_success() { | ||
showStudentAtIndex(model, INDEX_FIRST_STUDENT); | ||
|
||
Student studentToAddRemark = model.getFilteredStudentList().get(INDEX_FIRST_STUDENT.getZeroBased()); | ||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_STUDENT, VALID_REMARK_MATH); | ||
|
||
Student updatedStudent = new Student(studentToAddRemark, VALID_REMARK_MATH); | ||
|
||
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, | ||
Messages.format(updatedStudent)); | ||
|
||
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
expectedModel.setStudent(studentToAddRemark, updatedStudent); | ||
|
||
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_emptyRemark_throwsCommandException() { | ||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_STUDENT, ""); | ||
|
||
assertCommandFailure(remarkCommand, model, RemarkCommand.MESSAGE_NO_REMARK); | ||
} | ||
|
||
@Test | ||
public void constructor_nullRemark_throwsNullPointerException() { | ||
// null remark should throw a NullPointerException | ||
assertThrows(NullPointerException.class, () -> new RemarkCommand(INDEX_FIRST_STUDENT, null)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
String firstRemark = "Weak in Math"; | ||
String secondRemark = "Strong in Science"; | ||
|
||
RemarkCommand remarkFirstCommand = new RemarkCommand(INDEX_FIRST_STUDENT, firstRemark); | ||
RemarkCommand remarkSecondCommand = new RemarkCommand(INDEX_SECOND_STUDENT, secondRemark); | ||
|
||
// same object -> returns true | ||
assertTrue(remarkFirstCommand.equals(remarkFirstCommand)); | ||
|
||
// same values -> returns true | ||
RemarkCommand remarkFirstCommandCopy = new RemarkCommand(INDEX_FIRST_STUDENT, firstRemark); | ||
assertTrue(remarkFirstCommand.equals(remarkFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(remarkFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(remarkFirstCommand.equals(null)); | ||
|
||
// different student -> returns false | ||
assertFalse(remarkFirstCommand.equals(remarkSecondCommand)); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
String remark = "Weak at English"; | ||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_STUDENT, remark); | ||
String expected = RemarkCommand.class.getCanonicalName() + "{studentIndex=" + INDEX_FIRST_STUDENT | ||
+ ", remark=" + remark + "}"; | ||
assertEquals(expected, remarkCommand.toString()); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.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,100 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.INVALID_INDEX; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARK_MATH; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT_INDEX; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.RemarkCommand; | ||
|
||
public class RemarkCommandParserTest { | ||
|
||
private final RemarkCommandParser parser = new RemarkCommandParser(); | ||
|
||
@Test | ||
public void parse_validArgs_returnsRemarkCommand() { | ||
String userInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " " | ||
+ PREFIX_REMARK + VALID_REMARK_MATH; | ||
assertParseSuccess(parser, userInput, new RemarkCommand(INDEX_FIRST_STUDENT, VALID_REMARK_MATH)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidArgs_throwsParseException() { | ||
assertParseFailure(parser, INVALID_INDEX, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_missingStudentIndex_throwsParseException() { | ||
String userInput = " " + PREFIX_STUDENT_INDEX + PREFIX_REMARK + VALID_REMARK_MATH; | ||
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_missingRemark_throwsParseException() { | ||
String userInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " " + PREFIX_REMARK; | ||
assertParseFailure(parser, userInput, RemarkCommand.MESSAGE_NO_REMARK); | ||
} | ||
|
||
@Test | ||
public void parse_missingPrefixes_throwsParseException() { | ||
// Missing both prefixes | ||
String userInput = "1 " + VALID_REMARK_MATH; | ||
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
|
||
// Missing student prefix | ||
userInput = "1 " + PREFIX_REMARK + VALID_REMARK_MATH; | ||
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
|
||
// Missing remark prefix | ||
userInput = PREFIX_STUDENT_INDEX + "1"; | ||
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_duplicatePrefixes_throwsParseException() { | ||
// Duplicate student prefix | ||
String duplicateStudentInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " " | ||
+ PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " " + PREFIX_REMARK + VALID_REMARK_MATH; | ||
assertParseFailure(parser, duplicateStudentInput, | ||
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_STUDENT_INDEX)); | ||
|
||
// Duplicate remark prefix | ||
String duplicateRemarkInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " " | ||
+ PREFIX_REMARK + VALID_REMARK_MATH + " " + PREFIX_REMARK + VALID_REMARK_MATH; | ||
assertParseFailure(parser, duplicateRemarkInput, | ||
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_REMARK)); | ||
} | ||
|
||
@Test | ||
public void parse_emptyRemark_throwsParseException() { | ||
String userInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " " | ||
+ PREFIX_REMARK + " "; // Empty remark | ||
assertParseFailure(parser, userInput, RemarkCommand.MESSAGE_NO_REMARK); | ||
} | ||
|
||
@Test | ||
public void parse_nonNumericStudentIndex_throwsParseException() { | ||
String userInput = PREFIX_STUDENT_INDEX + INVALID_INDEX + " " + PREFIX_REMARK + VALID_REMARK_MATH; | ||
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_emptyInput_throwsParseException() { | ||
// Empty input | ||
assertParseFailure(parser, "", String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE)); | ||
} | ||
} |