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.
Update and create test files for Note function
Update and create test files for Note function for testing purposes. Remarks: Refer to issue #48 for more info
- Loading branch information
1 parent
0d3132f
commit 188a6e7
Showing
12 changed files
with
274 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ | |
"phone": "94351253", | ||
"email": "[email protected]", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"note": "", | ||
"tags": [ "friends" ] | ||
}, { | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
"address": "4th street", | ||
"note": "" | ||
} ] | ||
} |
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 |
---|---|---|
|
@@ -5,42 +5,49 @@ | |
"phone" : "94351253", | ||
"email" : "[email protected]", | ||
"address" : "123, Jurong West Ave 6, #08-111", | ||
"note": "", | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Benson Meier", | ||
"phone" : "98765432", | ||
"email" : "[email protected]", | ||
"address" : "311, Clementi Ave 2, #02-25", | ||
"note": "", | ||
"tags" : [ "owesMoney", "friends" ] | ||
}, { | ||
"name" : "Carl Kurz", | ||
"phone" : "95352563", | ||
"email" : "[email protected]", | ||
"address" : "wall street", | ||
"note": "", | ||
"tags" : [ ] | ||
}, { | ||
"name" : "Daniel Meier", | ||
"phone" : "87652533", | ||
"email" : "[email protected]", | ||
"address" : "10th street", | ||
"note": "", | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Elle Meyer", | ||
"phone" : "9482224", | ||
"email" : "[email protected]", | ||
"address" : "michegan ave", | ||
"note": "", | ||
"tags" : [ ] | ||
}, { | ||
"name" : "Fiona Kunz", | ||
"phone" : "9482427", | ||
"email" : "[email protected]", | ||
"address" : "little tokyo", | ||
"note": "", | ||
"tags" : [ ] | ||
}, { | ||
"name" : "George Best", | ||
"phone" : "9482442", | ||
"email" : "[email protected]", | ||
"address" : "4th street", | ||
"note": "", | ||
"tags" : [ ] | ||
} ] | ||
} |
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 |
---|---|---|
|
@@ -34,6 +34,8 @@ public class CommandTestUtil { | |
public static final String VALID_EMAIL_BOB = "[email protected]"; | ||
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1"; | ||
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3"; | ||
public static final String VALID_NOTE_AMY = "Super confident"; | ||
public static final String VALID_NOTE_BOB = "Amazing energy and charisma"; | ||
public static final String VALID_TAG_HUSBAND = "husband"; | ||
public static final String VALID_TAG_FRIEND = "friend"; | ||
|
||
|
134 changes: 134 additions & 0 deletions
134
src/test/java/seedu/address/logic/commands/NoteCommandTest.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,134 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_NOTE_AMY; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_NOTE_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.Note; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for NoteCommand. | ||
*/ | ||
public class NoteCommandTest { | ||
private static final String NOTE_STUB = "Some note"; | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_addNoteUnfilteredList_success() { | ||
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
Person editedPerson = new PersonBuilder(firstPerson).withNote(NOTE_STUB).build(); | ||
|
||
NoteCommand noteCommand = new NoteCommand(INDEX_FIRST_PERSON, new Note(editedPerson.getNote().value)); | ||
|
||
String expectedMessage = String.format(NoteCommand.MESSAGE_ADD_NOTE_SUCCESS, editedPerson); | ||
|
||
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); | ||
expectedModel.setPerson(firstPerson, editedPerson); | ||
|
||
assertCommandSuccess(noteCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_deleteNoteUnfilteredList_success() { | ||
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
Person editedPerson = new PersonBuilder(firstPerson).withNote("").build(); | ||
|
||
NoteCommand noteCommand = new NoteCommand(INDEX_FIRST_PERSON, | ||
new Note(editedPerson.getNote().toString())); | ||
|
||
String expectedMessage = String.format(NoteCommand.MESSAGE_DELETE_NOTE_SUCCESS, editedPerson); | ||
|
||
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); | ||
expectedModel.setPerson(firstPerson, editedPerson); | ||
|
||
assertCommandSuccess(noteCommand, 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())) | ||
.withNote(NOTE_STUB).build(); | ||
|
||
NoteCommand noteCommand = new NoteCommand(INDEX_FIRST_PERSON, new Note(editedPerson.getNote().value)); | ||
|
||
String expectedMessage = String.format(NoteCommand.MESSAGE_ADD_NOTE_SUCCESS, editedPerson); | ||
|
||
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); | ||
expectedModel.setPerson(firstPerson, editedPerson); | ||
|
||
assertCommandSuccess(noteCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidPersonIndexUnfilteredList_failure() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); | ||
NoteCommand noteCommand = new NoteCommand(outOfBoundIndex, new Note(VALID_NOTE_BOB)); | ||
|
||
assertCommandFailure(noteCommand, 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()); | ||
|
||
NoteCommand noteCommand = new NoteCommand(outOfBoundIndex, new Note(VALID_NOTE_BOB)); | ||
|
||
assertCommandFailure(noteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
final NoteCommand standardCommand = new NoteCommand(INDEX_FIRST_PERSON, | ||
new Note(VALID_NOTE_AMY)); | ||
|
||
// same values -> returns true | ||
NoteCommand commandWithSameValues = new NoteCommand(INDEX_FIRST_PERSON, | ||
new Note(VALID_NOTE_AMY)); | ||
assertTrue(standardCommand.equals(commandWithSameValues)); | ||
|
||
// same object -> returns true | ||
assertTrue(standardCommand.equals(standardCommand)); | ||
|
||
// null -> returns false | ||
assertFalse(standardCommand.equals(null)); | ||
|
||
// different types -> returns false | ||
assertFalse(standardCommand.equals(new ClearCommand())); | ||
|
||
// different index -> returns false | ||
assertFalse(standardCommand.equals(new NoteCommand(INDEX_SECOND_PERSON, | ||
new Note(VALID_NOTE_AMY)))); | ||
|
||
// different note -> returns false | ||
assertFalse(standardCommand.equals(new NoteCommand(INDEX_FIRST_PERSON, | ||
new Note(VALID_NOTE_BOB)))); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/test/java/seedu/address/logic/parser/NoteCommandParserTest.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,43 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.NoteCommand; | ||
import seedu.address.model.person.Note; | ||
|
||
public class RemarkCommandParserTest { | ||
private NoteCommandParser parser = new NoteCommandParser(); | ||
private final String nonEmptyRemark = "Some remark."; | ||
|
||
@Test | ||
public void parse_indexSpecified_success() { | ||
// have note | ||
Index targetIndex = INDEX_FIRST_PERSON; | ||
String userInput = targetIndex.getOneBased() + " " + PREFIX_NOTE + nonEmptyRemark; | ||
NoteCommand expectedCommand = new NoteCommand(INDEX_FIRST_PERSON, new Note(nonEmptyRemark)); | ||
assertParseSuccess(parser, userInput, expectedCommand); | ||
|
||
// no note | ||
userInput = targetIndex.getOneBased() + " " + PREFIX_NOTE; | ||
expectedCommand = new NoteCommand(INDEX_FIRST_PERSON, new Note("")); | ||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_missingCompulsoryField_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, NoteCommand.MESSAGE_USAGE); | ||
|
||
// no parameters | ||
assertParseFailure(parser, NoteCommand.COMMAND_WORD, expectedMessage); | ||
|
||
// no index | ||
assertParseFailure(parser, NoteCommand.COMMAND_WORD + " " + nonEmptyRemark, expectedMessage); | ||
} | ||
} |
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,31 @@ | ||
package seedu.address.model.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class NoteTest { | ||
|
||
@Test | ||
public void equals() { | ||
Note note = new Note("Hello"); | ||
|
||
// same object -> returns true | ||
assertTrue(note.equals(note)); | ||
|
||
// same values -> returns true | ||
Note noteCopy = new Note(note.value); | ||
assertTrue(note.equals(noteCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(note.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(note.equals(null)); | ||
|
||
// different note -> returns false | ||
Note differentNote = new Note("Bye"); | ||
assertFalse(note.equals(differentNote)); | ||
} | ||
} |
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
Oops, something went wrong.