From d570dd361298bedc7d5b20eb4773a70befcb2f97 Mon Sep 17 00:00:00 2001 From: jasonqiu212 Date: Fri, 21 Oct 2022 02:41:53 +0800 Subject: [PATCH 1/6] Refactor: rename DeleteCommand to DeleteContactCommand --- ...Command.java => DeleteContactCommand.java} | 10 +++---- .../swift/logic/parser/AddressBookParser.java | 8 +++--- ...r.java => DeleteContactCommandParser.java} | 10 +++---- .../java/swift/logic/LogicManagerTest.java | 2 +- ...est.java => DeleteContactCommandTest.java} | 28 +++++++++---------- .../logic/parser/AddressBookParserTest.java | 8 +++--- ...va => DeleteContactCommandParserTest.java} | 10 +++---- 7 files changed, 38 insertions(+), 38 deletions(-) rename src/main/java/swift/logic/commands/{DeleteCommand.java => DeleteContactCommand.java} (81%) rename src/main/java/swift/logic/parser/{DeleteCommandParser.java => DeleteContactCommandParser.java} (71%) rename src/test/java/swift/logic/commands/{DeleteCommandTest.java => DeleteContactCommandTest.java} (69%) rename src/test/java/swift/logic/parser/{DeleteCommandParserTest.java => DeleteContactCommandParserTest.java} (74%) diff --git a/src/main/java/swift/logic/commands/DeleteCommand.java b/src/main/java/swift/logic/commands/DeleteContactCommand.java similarity index 81% rename from src/main/java/swift/logic/commands/DeleteCommand.java rename to src/main/java/swift/logic/commands/DeleteContactCommand.java index cf2ed3c6428..ee5be62eedf 100644 --- a/src/main/java/swift/logic/commands/DeleteCommand.java +++ b/src/main/java/swift/logic/commands/DeleteContactCommand.java @@ -13,9 +13,9 @@ /** * Deletes a person identified using it's displayed index from the address book. */ -public class DeleteCommand extends Command { +public class DeleteContactCommand extends Command { - public static final String COMMAND_WORD = "delete"; + public static final String COMMAND_WORD = "delete_contact"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the person identified by the index number used in the displayed person list.\n" @@ -26,7 +26,7 @@ public class DeleteCommand extends Command { private final Index targetIndex; - public DeleteCommand(Index targetIndex) { + public DeleteContactCommand(Index targetIndex) { this.targetIndex = targetIndex; } @@ -47,7 +47,7 @@ public CommandResult execute(Model model) throws CommandException { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof DeleteCommand // instanceof handles nulls - && targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check + || (other instanceof DeleteContactCommand // instanceof handles nulls + && targetIndex.equals(((DeleteContactCommand) other).targetIndex)); // state check } } diff --git a/src/main/java/swift/logic/parser/AddressBookParser.java b/src/main/java/swift/logic/parser/AddressBookParser.java index 044378f42a0..0e985df5b10 100644 --- a/src/main/java/swift/logic/parser/AddressBookParser.java +++ b/src/main/java/swift/logic/parser/AddressBookParser.java @@ -10,7 +10,7 @@ import swift.logic.commands.AddTaskCommand; import swift.logic.commands.ClearCommand; import swift.logic.commands.Command; -import swift.logic.commands.DeleteCommand; +import swift.logic.commands.DeleteContactCommand; import swift.logic.commands.DeleteTaskCommand; import swift.logic.commands.EditContactCommand; import swift.logic.commands.EditTaskCommand; @@ -50,11 +50,11 @@ public Command parseCommand(String userInput) throws ParseException { final String arguments = matcher.group("arguments"); switch (commandWord) { case AddContactCommand.COMMAND_WORD: - return new AddCommandParser().parse(arguments); + return new AddContactCommandParser().parse(arguments); case EditContactCommand.COMMAND_WORD: return new EditContactCommandParser().parse(arguments); - case DeleteCommand.COMMAND_WORD: - return new DeleteCommandParser().parse(arguments); + case DeleteContactCommand.COMMAND_WORD: + return new DeleteContactCommandParser().parse(arguments); case ClearCommand.COMMAND_WORD: return new ClearCommand(); case FindContactCommand.COMMAND_WORD: diff --git a/src/main/java/swift/logic/parser/DeleteCommandParser.java b/src/main/java/swift/logic/parser/DeleteContactCommandParser.java similarity index 71% rename from src/main/java/swift/logic/parser/DeleteCommandParser.java rename to src/main/java/swift/logic/parser/DeleteContactCommandParser.java index 38f745b4107..1dc0c3fbbe0 100644 --- a/src/main/java/swift/logic/parser/DeleteCommandParser.java +++ b/src/main/java/swift/logic/parser/DeleteContactCommandParser.java @@ -3,26 +3,26 @@ import static swift.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import swift.commons.core.index.Index; -import swift.logic.commands.DeleteCommand; +import swift.logic.commands.DeleteContactCommand; import swift.logic.parser.exceptions.ParseException; /** * Parses input arguments and creates a new DeleteCommand object */ -public class DeleteCommandParser implements Parser { +public class DeleteContactCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the DeleteCommand * and returns a DeleteCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ - public DeleteCommand parse(String args) throws ParseException { + public DeleteContactCommand parse(String args) throws ParseException { try { Index index = ParserUtil.parseIndex(args); - return new DeleteCommand(index); + return new DeleteContactCommand(index); } catch (ParseException pe) { throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe); + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteContactCommand.MESSAGE_USAGE), pe); } } diff --git a/src/test/java/swift/logic/LogicManagerTest.java b/src/test/java/swift/logic/LogicManagerTest.java index bd1cf67d109..8ee7808f414 100644 --- a/src/test/java/swift/logic/LogicManagerTest.java +++ b/src/test/java/swift/logic/LogicManagerTest.java @@ -58,7 +58,7 @@ public void execute_invalidCommandFormat_throwsParseException() { @Test public void execute_commandExecutionError_throwsCommandException() { - String deleteCommand = "delete 9"; + String deleteCommand = "delete_contact 9"; assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } diff --git a/src/test/java/swift/logic/commands/DeleteCommandTest.java b/src/test/java/swift/logic/commands/DeleteContactCommandTest.java similarity index 69% rename from src/test/java/swift/logic/commands/DeleteCommandTest.java rename to src/test/java/swift/logic/commands/DeleteContactCommandTest.java index 890452a1c10..fe9a28a5116 100644 --- a/src/test/java/swift/logic/commands/DeleteCommandTest.java +++ b/src/test/java/swift/logic/commands/DeleteContactCommandTest.java @@ -22,29 +22,29 @@ * Contains integration tests (interaction with the Model) and unit tests for * {@code DeleteCommand}. */ -public class DeleteCommandTest { +public class DeleteContactCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); @Test public void execute_validIndexUnfilteredList_success() { Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON); + DeleteContactCommand deleteContactCommand = new DeleteContactCommand(INDEX_FIRST_PERSON); - String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete); + String expectedMessage = String.format(DeleteContactCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); expectedModel.deletePerson(personToDelete); - assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); + assertCommandSuccess(deleteContactCommand, model, expectedMessage, expectedModel); } @Test public void execute_invalidIndexUnfilteredList_throwsCommandException() { Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); - DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex); + DeleteContactCommand deleteContactCommand = new DeleteContactCommand(outOfBoundIndex); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteContactCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @Test @@ -52,15 +52,15 @@ public void execute_validIndexFilteredList_success() { showPersonAtIndex(model, INDEX_FIRST_PERSON); Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON); + DeleteContactCommand deleteContactCommand = new DeleteContactCommand(INDEX_FIRST_PERSON); - String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete); + String expectedMessage = String.format(DeleteContactCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); expectedModel.deletePerson(personToDelete); showNoPerson(expectedModel); - assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); + assertCommandSuccess(deleteContactCommand, model, expectedMessage, expectedModel); } @Test @@ -71,21 +71,21 @@ public void execute_invalidIndexFilteredList_throwsCommandException() { // ensures that outOfBoundIndex is still in bounds of address book list assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); - DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex); + DeleteContactCommand deleteContactCommand = new DeleteContactCommand(outOfBoundIndex); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteContactCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @Test public void equals() { - DeleteCommand deleteFirstCommand = new DeleteCommand(INDEX_FIRST_PERSON); - DeleteCommand deleteSecondCommand = new DeleteCommand(INDEX_SECOND_PERSON); + DeleteContactCommand deleteFirstCommand = new DeleteContactCommand(INDEX_FIRST_PERSON); + DeleteContactCommand deleteSecondCommand = new DeleteContactCommand(INDEX_SECOND_PERSON); // same object -> returns true assertTrue(deleteFirstCommand.equals(deleteFirstCommand)); // same values -> returns true - DeleteCommand deleteFirstCommandCopy = new DeleteCommand(INDEX_FIRST_PERSON); + DeleteContactCommand deleteFirstCommandCopy = new DeleteContactCommand(INDEX_FIRST_PERSON); assertTrue(deleteFirstCommand.equals(deleteFirstCommandCopy)); // different types -> returns false diff --git a/src/test/java/swift/logic/parser/AddressBookParserTest.java b/src/test/java/swift/logic/parser/AddressBookParserTest.java index 2446f753408..45ac8349cdc 100644 --- a/src/test/java/swift/logic/parser/AddressBookParserTest.java +++ b/src/test/java/swift/logic/parser/AddressBookParserTest.java @@ -17,7 +17,7 @@ import swift.logic.commands.AddContactCommand; import swift.logic.commands.AddTaskCommand; import swift.logic.commands.ClearCommand; -import swift.logic.commands.DeleteCommand; +import swift.logic.commands.DeleteContactCommand; import swift.logic.commands.EditContactCommand; import swift.logic.commands.EditContactCommand.EditPersonDescriptor; import swift.logic.commands.ExitCommand; @@ -54,9 +54,9 @@ public void parseCommand_clear() throws Exception { @Test public void parseCommand_delete() throws Exception { - DeleteCommand command = (DeleteCommand) parser.parseCommand( - DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); - assertEquals(new DeleteCommand(INDEX_FIRST_PERSON), command); + DeleteContactCommand command = (DeleteContactCommand) parser.parseCommand( + DeleteContactCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); + assertEquals(new DeleteContactCommand(INDEX_FIRST_PERSON), command); } @Test diff --git a/src/test/java/swift/logic/parser/DeleteCommandParserTest.java b/src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java similarity index 74% rename from src/test/java/swift/logic/parser/DeleteCommandParserTest.java rename to src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java index fd94348bac9..66d000cc209 100644 --- a/src/test/java/swift/logic/parser/DeleteCommandParserTest.java +++ b/src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; -import swift.logic.commands.DeleteCommand; +import swift.logic.commands.DeleteContactCommand; /** * As we are only doing white-box testing, our test cases do not cover path variations @@ -16,17 +16,17 @@ * The path variation for those two cases occur inside the ParserUtil, and * therefore should be covered by the ParserUtilTest. */ -public class DeleteCommandParserTest { +public class DeleteContactCommandParserTest { - private DeleteCommandParser parser = new DeleteCommandParser(); + private DeleteContactCommandParser parser = new DeleteContactCommandParser(); @Test public void parse_validArgs_returnsDeleteCommand() { - assertParseSuccess(parser, "1", new DeleteCommand(INDEX_FIRST_PERSON)); + assertParseSuccess(parser, "1", new DeleteContactCommand(INDEX_FIRST_PERSON)); } @Test public void parse_invalidArgs_throwsParseException() { - assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteContactCommand.MESSAGE_USAGE)); } } From 7e4dcfd98b5c2eeeab39c41df0f8275f793ecf2a Mon Sep 17 00:00:00 2001 From: jasonqiu212 Date: Fri, 21 Oct 2022 02:42:07 +0800 Subject: [PATCH 2/6] Refactor: rename AddCommandParser to AddContactCommandParser --- .../{AddCommandParser.java => AddContactCommandParser.java} | 2 +- ...ommandParserTest.java => AddContactCommandParserTest.java} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/swift/logic/parser/{AddCommandParser.java => AddContactCommandParser.java} (97%) rename src/test/java/swift/logic/parser/{AddCommandParserTest.java => AddContactCommandParserTest.java} (98%) diff --git a/src/main/java/swift/logic/parser/AddCommandParser.java b/src/main/java/swift/logic/parser/AddContactCommandParser.java similarity index 97% rename from src/main/java/swift/logic/parser/AddCommandParser.java rename to src/main/java/swift/logic/parser/AddContactCommandParser.java index a15550dd4ba..9c05ff9e005 100644 --- a/src/main/java/swift/logic/parser/AddCommandParser.java +++ b/src/main/java/swift/logic/parser/AddContactCommandParser.java @@ -23,7 +23,7 @@ /** * Parses input arguments and creates a new AddCommand object */ -public class AddCommandParser implements Parser { +public class AddContactCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the AddCommand diff --git a/src/test/java/swift/logic/parser/AddCommandParserTest.java b/src/test/java/swift/logic/parser/AddContactCommandParserTest.java similarity index 98% rename from src/test/java/swift/logic/parser/AddCommandParserTest.java rename to src/test/java/swift/logic/parser/AddContactCommandParserTest.java index afe618557f9..ec4105e7ff5 100644 --- a/src/test/java/swift/logic/parser/AddCommandParserTest.java +++ b/src/test/java/swift/logic/parser/AddContactCommandParserTest.java @@ -40,8 +40,8 @@ import swift.model.tag.Tag; import swift.testutil.PersonBuilder; -public class AddCommandParserTest { - private AddCommandParser parser = new AddCommandParser(); +public class AddContactCommandParserTest { + private AddContactCommandParser parser = new AddContactCommandParser(); @Test public void parse_allFieldsPresent_success() { From a2cff3921a06bb41dd598d0259d7ffb549cd8989 Mon Sep 17 00:00:00 2001 From: jasonqiu212 Date: Fri, 21 Oct 2022 02:42:12 +0800 Subject: [PATCH 3/6] Build: enable assertions in gradle --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index 2c5ef023df1..8f97e675939 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,10 @@ test { finalizedBy jacocoTestReport } +run { + enableAssertions = true +} + task coverage(type: JacocoReport) { sourceDirectories.from files(sourceSets.main.allSource.srcDirs) classDirectories.from files(sourceSets.main.output) From 6fce345a24e38f06dca5f0522106460133eeea62 Mon Sep 17 00:00:00 2001 From: jasonqiu212 Date: Fri, 21 Oct 2022 02:47:17 +0800 Subject: [PATCH 4/6] Build: change jar file name in gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8f97e675939..93513babb8a 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ dependencies { } shadowJar { - archiveFileName = 'addressbook.jar' + archiveFileName = 'swift+.jar' } defaultTasks 'clean', 'test' From b1ec0276fa5b098c866354093df6edf7290a6835 Mon Sep 17 00:00:00 2001 From: jasonqiu212 Date: Fri, 21 Oct 2022 02:47:28 +0800 Subject: [PATCH 5/6] Chore: update version number --- src/main/java/swift/MainApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/swift/MainApp.java b/src/main/java/swift/MainApp.java index 31507a03f31..e8bc5511c99 100644 --- a/src/main/java/swift/MainApp.java +++ b/src/main/java/swift/MainApp.java @@ -36,7 +36,7 @@ */ public class MainApp extends Application { - public static final Version VERSION = new Version(0, 2, 0, true); + public static final Version VERSION = new Version(1, 3, 0, true); private static final Logger logger = LogsCenter.getLogger(MainApp.class); From a85604bcc12109542c40ae4d8ea4844d6710ec3c Mon Sep 17 00:00:00 2001 From: jasonqiu212 Date: Fri, 21 Oct 2022 02:52:20 +0800 Subject: [PATCH 6/6] Style: fix checkstyle --- .../swift/logic/parser/DeleteContactCommandParserTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java b/src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java index 66d000cc209..21ad749ced7 100644 --- a/src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java +++ b/src/test/java/swift/logic/parser/DeleteContactCommandParserTest.java @@ -11,7 +11,7 @@ /** * As we are only doing white-box testing, our test cases do not cover path variations - * outside of the DeleteCommand code. For example, inputs "1" and "1 abc" take the + * outside the DeleteCommand code. For example, inputs "1" and "1 abc" take the * same path through the DeleteCommand, and therefore we test only one of them. * The path variation for those two cases occur inside the ParserUtil, and * therefore should be covered by the ParserUtilTest. @@ -27,6 +27,7 @@ public void parse_validArgs_returnsDeleteCommand() { @Test public void parse_invalidArgs_throwsParseException() { - assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteContactCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + DeleteContactCommand.MESSAGE_USAGE)); } }