forked from nus-cs2103-AY2324S2/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.
- Loading branch information
Pluiexo
authored and
Pluiexo
committed
Feb 29, 2024
1 parent
bfce179
commit 026dad9
Showing
2 changed files
with
102 additions
and
0 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
100 changes: 100 additions & 0 deletions
100
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,100 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARK_BOB; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.AddressBook; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Remark; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
class RemarkCommandTest { | ||
private static final String REMARK_STUB = "Some remark"; | ||
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_addRemarkUnfilteredList_success() { | ||
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
Person editedPerson = new PersonBuilder(firstPerson).withRemark(REMARK_STUB).build(); | ||
|
||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark(editedPerson.getRemark().value)); | ||
|
||
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, editedPerson); | ||
|
||
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); | ||
expectedModel.setPerson(firstPerson, editedPerson); | ||
|
||
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_deleteRemarkUnfilteredList_success() { | ||
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
Person editedPerson = new PersonBuilder(firstPerson).withRemark("").build(); | ||
|
||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark(editedPerson.getRemark() | ||
.toString())); | ||
|
||
String expectedMessage = String.format(RemarkCommand.MESSAGE_DELETE_REMARK_SUCCESS, editedPerson); | ||
|
||
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); | ||
expectedModel.setPerson(firstPerson, editedPerson); | ||
|
||
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_filteredList_success() { | ||
showPersonAtIndex(model, INDEX_FIRST_PERSON); | ||
|
||
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
Person editedPerson = new PersonBuilder(model.getFilteredPersonList() | ||
.get(INDEX_FIRST_PERSON.getZeroBased())).withRemark(REMARK_STUB) | ||
.build(); | ||
|
||
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark(editedPerson.getRemark().value)); | ||
|
||
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, editedPerson); | ||
|
||
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); | ||
expectedModel.setPerson(firstPerson, editedPerson); | ||
|
||
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidPersonIndexUnfilteredList_failure() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); | ||
RemarkCommand remarkCommand = new RemarkCommand(outOfBoundIndex, new Remark(VALID_REMARK_BOB)); | ||
|
||
assertCommandFailure(remarkCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
/** | ||
* Edit filtered list where index is larger than size of filtered list, | ||
* but smaller than size of address book | ||
*/ | ||
@Test | ||
public void execute_invalidPersonIndexFilteredList_failure() { | ||
showPersonAtIndex(model, INDEX_FIRST_PERSON); | ||
Index outOfBoundIndex = INDEX_SECOND_PERSON; | ||
// ensures that outOfBoundIndex is still in bounds of address book list | ||
assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); | ||
|
||
RemarkCommand remarkCommand = new RemarkCommand(outOfBoundIndex, new Remark(VALID_REMARK_BOB)); | ||
assertCommandFailure(remarkCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
} |