From faa22c38945d1ee722d81aec17b8aa170867a273 Mon Sep 17 00:00:00 2001 From: Jeffry Lum <22460123+j-lum@users.noreply.github.com> Date: Fri, 19 Jul 2019 15:27:21 +0800 Subject: [PATCH 01/12] Logic: Implement minimal `remark` command Add a minimum viable implementation of the `remark` command. This implementation meant to be a bridging step between seeing a positive result and doing things the right way. Tests are not implemented because students are not expected to know how to write them yet. --- .../address/logic/commands/RemarkCommand.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/RemarkCommand.java diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java new file mode 100644 index 00000000000..64ac7c50973 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -0,0 +1,16 @@ +package seedu.address.logic.commands; + +import seedu.address.model.Model; + +/** + * Changes the remark of an existing person in the address book. + */ +public class RemarkCommand extends Command { + + public static final String COMMAND_WORD = "remark"; + + @Override + public CommandResult execute(Model model) { + return new CommandResult("Hello from remark"); + } +} From 35eb7286f18a029d39cb7a29df8f172a001e4fd8 Mon Sep 17 00:00:00 2001 From: Jeffry Lum <22460123+j-lum@users.noreply.github.com> Date: Thu, 6 Jun 2019 14:01:33 +0800 Subject: [PATCH 02/12] Logic: Teach the app to accept 'remark' but do nothing Add a RemarkCommand that just throws an Exception. Add RemarkCommandTest that will test that executeUndoableCommand() throws an Exception. Modify AddressBookParser to accept a RemarkCommand. Add new test to AddressBookParserTest, which will test that typing "remark" returns an instance of RemarkCommand. --- .../address/logic/commands/RemarkCommand.java | 17 +++++++++++-- .../logic/parser/AddressBookParser.java | 4 ++++ .../seedu/address/logic/parser/CliSyntax.java | 1 + .../logic/commands/RemarkCommandTest.java | 24 +++++++++++++++++++ .../logic/parser/AddressBookParserTest.java | 6 +++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/test/java/seedu/address/logic/commands/RemarkCommandTest.java diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index 64ac7c50973..e4e13204ced 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -1,5 +1,8 @@ package seedu.address.logic.commands; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; + +import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; /** @@ -9,8 +12,18 @@ public class RemarkCommand extends Command { public static final String COMMAND_WORD = "remark"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the remark of the person identified " + + "by the index number used in the last person listing. " + + "Existing remark will be overwritten by the input.\n" + + "Parameters: INDEX (must be a positive integer) " + + PREFIX_REMARK + "[REMARK]\n" + + "Example: " + COMMAND_WORD + " 1 " + + PREFIX_REMARK + "Likes to swim."; + + public static final String MESSAGE_NOT_IMPLEMENTED_YET = "Remark command not implemented yet"; + @Override - public CommandResult execute(Model model) { - return new CommandResult("Hello from remark"); + public CommandResult execute(Model model) throws CommandException { + throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET); } } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 1e466792b46..5509310e105 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -15,6 +15,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -59,6 +60,9 @@ public Command parseCommand(String userInput) throws ParseException { case FindCommand.COMMAND_WORD: return new FindCommandParser().parse(arguments); + case RemarkCommand.COMMAND_WORD: + return new RemarkCommand(); + case ListCommand.COMMAND_WORD: return new ListCommand(); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf119..d1631e40cd6 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -10,6 +10,7 @@ public class CliSyntax { public static final Prefix PREFIX_PHONE = new Prefix("p/"); public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); + public static final Prefix PREFIX_REMARK = new Prefix("r/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); } diff --git a/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java new file mode 100644 index 00000000000..ae28ca754e0 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java @@ -0,0 +1,24 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.RemarkCommand.MESSAGE_NOT_IMPLEMENTED_YET; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; + +/** + * Contains integration tests (interaction with the Model) and unit tests for RemarkCommand. + */ +public class RemarkCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute() { + assertCommandFailure(new RemarkCommand(), model, MESSAGE_NOT_IMPLEMENTED_YET); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index d9659205b57..aab9384fd5e 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -22,6 +22,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; @@ -88,6 +89,11 @@ public void parseCommand_list() throws Exception { assertTrue(parser.parseCommand(ListCommand.COMMAND_WORD + " 3") instanceof ListCommand); } + @Test + public void parseCommand_remark() throws Exception { + assertTrue(parser.parseCommand(RemarkCommand.COMMAND_WORD) instanceof RemarkCommand); + } + @Test public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), () From dc6d5139d08f6403da0ec624ea32bd79a2ae0cbf Mon Sep 17 00:00:00 2001 From: Jeffry Lum <22460123+j-lum@users.noreply.github.com> Date: Thu, 6 Jun 2019 14:16:58 +0800 Subject: [PATCH 03/12] Logic: Teach the app to accept 'remark' arguments but still do nothing Modify RemarkCommand to take in an Index and String for remark, and print those two parameters as the error message Modify RemarkCommandTest to test the equals method Add RemarkCommandParser that will know how to parse two arguments, one index and one with prefix 'r/' Add RemarkCommandParserTest that will test different boundary values for RemarkCommandParser. Modify AddressBookParser to use the newly implemented RemarkCommandParser Modify AddressBookParserTest to ensure that what the user input generated the correct command. --- .../address/logic/commands/RemarkCommand.java | 37 +++++++++++++++- .../logic/parser/AddressBookParser.java | 2 +- .../logic/parser/RemarkCommandParser.java | 36 ++++++++++++++++ .../logic/commands/CommandTestUtil.java | 2 + .../logic/commands/RemarkCommandTest.java | 38 ++++++++++++++++- .../logic/parser/AddressBookParserTest.java | 6 ++- .../logic/parser/RemarkCommandParserTest.java | 42 +++++++++++++++++++ 7 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 src/main/java/seedu/address/logic/parser/RemarkCommandParser.java create mode 100644 src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index e4e13204ced..940c0ef35e3 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -1,7 +1,9 @@ package seedu.address.logic.commands; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; +import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -20,10 +22,41 @@ public class RemarkCommand extends Command { + "Example: " + COMMAND_WORD + " 1 " + PREFIX_REMARK + "Likes to swim."; - public static final String MESSAGE_NOT_IMPLEMENTED_YET = "Remark command not implemented yet"; + public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; + private final Index index; + private final String remark; + + /** + * @param index of the person in the filtered person list to edit the remark + * @param remark of the person to be updated to + */ + public RemarkCommand(Index index, String remark) { + requireAllNonNull(index, remark); + + this.index = index; + this.remark = remark; + } @Override public CommandResult execute(Model model) throws CommandException { - throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET); + throw new CommandException(String.format(MESSAGE_ARGUMENTS, index.getOneBased(), remark)); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof RemarkCommand)) { + return false; + } + + // state check + RemarkCommand e = (RemarkCommand) other; + return index.equals(e.index) + && remark.equals(e.remark); } } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 5509310e105..eff2d21e832 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -61,7 +61,7 @@ public Command parseCommand(String userInput) throws ParseException { return new FindCommandParser().parse(arguments); case RemarkCommand.COMMAND_WORD: - return new RemarkCommand(); + return new RemarkCommandParser().parse(arguments); case ListCommand.COMMAND_WORD: return new ListCommand(); diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java new file mode 100644 index 00000000000..0be4d52205e --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -0,0 +1,36 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; + +import seedu.address.commons.core.index.Index; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.commands.RemarkCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new {@code RemarkCommand} object + */ +public class RemarkCommandParser implements Parser { + /** + * Parses the given {@code String} of arguments in the context of the {@code RemarkCommand} + * and returns a {@code RemarkCommand} object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public RemarkCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_REMARK); + + Index index; + try { + index = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (IllegalValueException ive) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemarkCommand.MESSAGE_USAGE), ive); + } + + String remark = argMultimap.getValue(PREFIX_REMARK).orElse(""); + + return new RemarkCommand(index, remark); + } +} diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 643a1d08069..313b370a7a8 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -34,6 +34,8 @@ public class CommandTestUtil { public static final String VALID_EMAIL_BOB = "bob@example.com"; 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_REMARK_AMY = "Like skiing."; + public static final String VALID_REMARK_BOB = "Favourite pastime: Eating"; public static final String VALID_TAG_HUSBAND = "husband"; public static final String VALID_TAG_FRIEND = "friend"; diff --git a/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java index ae28ca754e0..da09c651b91 100644 --- a/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java @@ -1,7 +1,14 @@ 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_REMARK_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARK_BOB; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; -import static seedu.address.logic.commands.RemarkCommand.MESSAGE_NOT_IMPLEMENTED_YET; +import static seedu.address.logic.commands.RemarkCommand.MESSAGE_ARGUMENTS; +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; @@ -19,6 +26,33 @@ public class RemarkCommandTest { @Test public void execute() { - assertCommandFailure(new RemarkCommand(), model, MESSAGE_NOT_IMPLEMENTED_YET); + final String remark = "Some remark"; + + assertCommandFailure(new RemarkCommand(INDEX_FIRST_PERSON, remark), model, + String.format(MESSAGE_ARGUMENTS, INDEX_FIRST_PERSON.getOneBased(), remark)); + } + + @Test + public void equals() { + final RemarkCommand standardCommand = new RemarkCommand(INDEX_FIRST_PERSON, VALID_REMARK_AMY); + + // same values -> returns true + RemarkCommand commandWithSameValues = new RemarkCommand(INDEX_FIRST_PERSON, VALID_REMARK_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 RemarkCommand(INDEX_SECOND_PERSON, VALID_REMARK_AMY))); + + // different remark -> returns false + assertFalse(standardCommand.equals(new RemarkCommand(INDEX_FIRST_PERSON, VALID_REMARK_BOB))); } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index aab9384fd5e..fb413f512e9 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; @@ -91,7 +92,10 @@ public void parseCommand_list() throws Exception { @Test public void parseCommand_remark() throws Exception { - assertTrue(parser.parseCommand(RemarkCommand.COMMAND_WORD) instanceof RemarkCommand); + final String remark = "Some remark."; + RemarkCommand command = (RemarkCommand) parser.parseCommand(RemarkCommand.COMMAND_WORD + " " + + INDEX_FIRST_PERSON.getOneBased() + " " + PREFIX_REMARK + remark); + assertEquals(new RemarkCommand(INDEX_FIRST_PERSON, remark), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java b/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java new file mode 100644 index 00000000000..9118a73f03e --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java @@ -0,0 +1,42 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; +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.RemarkCommand; + +public class RemarkCommandParserTest { + private RemarkCommandParser parser = new RemarkCommandParser(); + private final String nonEmptyRemark = "Some remark."; + + @Test + public void parse_indexSpecified_success() { + // have remark + Index targetIndex = INDEX_FIRST_PERSON; + String userInput = targetIndex.getOneBased() + " " + PREFIX_REMARK + nonEmptyRemark; + RemarkCommand expectedCommand = new RemarkCommand(INDEX_FIRST_PERSON, nonEmptyRemark); + assertParseSuccess(parser, userInput, expectedCommand); + + // no remark + userInput = targetIndex.getOneBased() + " " + PREFIX_REMARK; + expectedCommand = new RemarkCommand(INDEX_FIRST_PERSON, ""); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_missingCompulsoryField_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemarkCommand.MESSAGE_USAGE); + + // no parameters + assertParseFailure(parser, RemarkCommand.COMMAND_WORD, expectedMessage); + + // no index + assertParseFailure(parser, RemarkCommand.COMMAND_WORD + " " + nonEmptyRemark, expectedMessage); + } +} From 4516e099699baa9e2d51801bd26f016d812dedcc Mon Sep 17 00:00:00 2001 From: Jeffry Lum <22460123+j-lum@users.noreply.github.com> Date: Thu, 6 Jun 2019 14:26:52 +0800 Subject: [PATCH 04/12] Model: Add Remark class Add Remark to model component (copy from Address, remove the regex and rename accordingly). Add test for Remark (to test the equals method). Modify RemarkCommand to now take in a Remark instead of a String. --- .../address/logic/commands/RemarkCommand.java | 5 +-- .../logic/parser/RemarkCommandParser.java | 3 +- .../seedu/address/model/person/Remark.java | 33 +++++++++++++++++++ .../logic/commands/RemarkCommandTest.java | 15 ++++++--- .../logic/parser/AddressBookParserTest.java | 5 +-- .../logic/parser/RemarkCommandParserTest.java | 5 +-- .../address/model/person/RemarkTest.java | 31 +++++++++++++++++ 7 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/main/java/seedu/address/model/person/Remark.java create mode 100644 src/test/java/seedu/address/model/person/RemarkTest.java diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index 940c0ef35e3..3190aaded32 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -6,6 +6,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.person.Remark; /** * Changes the remark of an existing person in the address book. @@ -25,13 +26,13 @@ public class RemarkCommand extends Command { public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; private final Index index; - private final String remark; + private final Remark remark; /** * @param index of the person in the filtered person list to edit the remark * @param remark of the person to be updated to */ - public RemarkCommand(Index index, String remark) { + public RemarkCommand(Index index, Remark remark) { requireAllNonNull(index, remark); this.index = index; diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java index 0be4d52205e..d4a8c8f0233 100644 --- a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -8,6 +8,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Remark; /** * Parses input arguments and creates a new {@code RemarkCommand} object @@ -31,6 +32,6 @@ public RemarkCommand parse(String args) throws ParseException { String remark = argMultimap.getValue(PREFIX_REMARK).orElse(""); - return new RemarkCommand(index, remark); + return new RemarkCommand(index, new Remark(remark)); } } diff --git a/src/main/java/seedu/address/model/person/Remark.java b/src/main/java/seedu/address/model/person/Remark.java new file mode 100644 index 00000000000..2e5c65280b9 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Remark.java @@ -0,0 +1,33 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; + +/** + * Represents a Person's remark in the address book. + * Guarantees: immutable; is always valid + */ +public class Remark { + public final String value; + + public Remark(String remark) { + requireNonNull(remark); + value = remark; + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Remark // instanceof handles nulls + && value.equals(((Remark) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java index da09c651b91..d92598a0440 100644 --- a/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/RemarkCommandTest.java @@ -16,6 +16,7 @@ import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.person.Remark; /** * Contains integration tests (interaction with the Model) and unit tests for RemarkCommand. @@ -26,7 +27,7 @@ public class RemarkCommandTest { @Test public void execute() { - final String remark = "Some remark"; + final Remark remark = new Remark("Some remark"); assertCommandFailure(new RemarkCommand(INDEX_FIRST_PERSON, remark), model, String.format(MESSAGE_ARGUMENTS, INDEX_FIRST_PERSON.getOneBased(), remark)); @@ -34,10 +35,12 @@ public void execute() { @Test public void equals() { - final RemarkCommand standardCommand = new RemarkCommand(INDEX_FIRST_PERSON, VALID_REMARK_AMY); + final RemarkCommand standardCommand = new RemarkCommand(INDEX_FIRST_PERSON, + new Remark(VALID_REMARK_AMY)); // same values -> returns true - RemarkCommand commandWithSameValues = new RemarkCommand(INDEX_FIRST_PERSON, VALID_REMARK_AMY); + RemarkCommand commandWithSameValues = new RemarkCommand(INDEX_FIRST_PERSON, + new Remark(VALID_REMARK_AMY)); assertTrue(standardCommand.equals(commandWithSameValues)); // same object -> returns true @@ -50,9 +53,11 @@ public void equals() { assertFalse(standardCommand.equals(new ClearCommand())); // different index -> returns false - assertFalse(standardCommand.equals(new RemarkCommand(INDEX_SECOND_PERSON, VALID_REMARK_AMY))); + assertFalse(standardCommand.equals(new RemarkCommand(INDEX_SECOND_PERSON, + new Remark(VALID_REMARK_AMY)))); // different remark -> returns false - assertFalse(standardCommand.equals(new RemarkCommand(INDEX_FIRST_PERSON, VALID_REMARK_BOB))); + assertFalse(standardCommand.equals(new RemarkCommand(INDEX_FIRST_PERSON, + new Remark(VALID_REMARK_BOB)))); } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index fb413f512e9..5c4733feade 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -27,6 +27,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; +import seedu.address.model.person.Remark; import seedu.address.testutil.EditPersonDescriptorBuilder; import seedu.address.testutil.PersonBuilder; import seedu.address.testutil.PersonUtil; @@ -92,9 +93,9 @@ public void parseCommand_list() throws Exception { @Test public void parseCommand_remark() throws Exception { - final String remark = "Some remark."; + final Remark remark = new Remark("Some remark."); RemarkCommand command = (RemarkCommand) parser.parseCommand(RemarkCommand.COMMAND_WORD + " " - + INDEX_FIRST_PERSON.getOneBased() + " " + PREFIX_REMARK + remark); + + INDEX_FIRST_PERSON.getOneBased() + " " + PREFIX_REMARK + remark.value); assertEquals(new RemarkCommand(INDEX_FIRST_PERSON, remark), command); } diff --git a/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java b/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java index 9118a73f03e..8a2bfd0414f 100644 --- a/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java @@ -10,6 +10,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.RemarkCommand; +import seedu.address.model.person.Remark; public class RemarkCommandParserTest { private RemarkCommandParser parser = new RemarkCommandParser(); @@ -20,12 +21,12 @@ public void parse_indexSpecified_success() { // have remark Index targetIndex = INDEX_FIRST_PERSON; String userInput = targetIndex.getOneBased() + " " + PREFIX_REMARK + nonEmptyRemark; - RemarkCommand expectedCommand = new RemarkCommand(INDEX_FIRST_PERSON, nonEmptyRemark); + RemarkCommand expectedCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark(nonEmptyRemark)); assertParseSuccess(parser, userInput, expectedCommand); // no remark userInput = targetIndex.getOneBased() + " " + PREFIX_REMARK; - expectedCommand = new RemarkCommand(INDEX_FIRST_PERSON, ""); + expectedCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark("")); assertParseSuccess(parser, userInput, expectedCommand); } diff --git a/src/test/java/seedu/address/model/person/RemarkTest.java b/src/test/java/seedu/address/model/person/RemarkTest.java new file mode 100644 index 00000000000..34117c68ddf --- /dev/null +++ b/src/test/java/seedu/address/model/person/RemarkTest.java @@ -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 RemarkTest { + + @Test + public void equals() { + Remark remark = new Remark("Hello"); + + // same object -> returns true + assertTrue(remark.equals(remark)); + + // same values -> returns true + Remark remarkCopy = new Remark(remark.value); + assertTrue(remark.equals(remarkCopy)); + + // different types -> returns false + assertFalse(remark.equals(1)); + + // null -> returns false + assertFalse(remark.equals(null)); + + // different remark -> returns false + Remark differentRemark = new Remark("Bye"); + assertFalse(remark.equals(differentRemark)); + } +} From 850b78879582f38accb05dd20c245963c65ea599 Mon Sep 17 00:00:00 2001 From: Jeffry Lum <22460123+j-lum@users.noreply.github.com> Date: Thu, 6 Jun 2019 14:30:09 +0800 Subject: [PATCH 05/12] Ui: Add a placeholder for remark in PersonCard GUI Add label with any random text inside PersonListCard.fxml Add FXML annotation in PersonCard to tie the variable to the actual label. --- src/main/java/seedu/address/ui/PersonCard.java | 2 ++ src/main/resources/view/PersonListCard.fxml | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 0684b088868..4ffd359dfd2 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -39,6 +39,8 @@ public class PersonCard extends UiPart { @FXML private Label email; @FXML + private Label remark; + @FXML private FlowPane tags; public PersonCard(Person person, int displayedIndex) { diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index f08ea32ad55..d1a7eb614f8 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -31,6 +31,7 @@