Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S1#81 from jasonqiu212/70-rename-…
Browse files Browse the repository at this point in the history
…delete-command

Rename `delete` command to `delete_contact`
  • Loading branch information
peppapighs authored Oct 21, 2022
2 parents 6ebfb4d + a85604b commit 1bcefc2
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 44 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -66,7 +70,7 @@ dependencies {
}

shadowJar {
archiveFileName = 'addressbook.jar'
archiveFileName = 'swift+.jar'
}

defaultTasks 'clean', 'test'
2 changes: 1 addition & 1 deletion src/main/java/swift/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,7 +26,7 @@ public class DeleteCommand extends Command {

private final Index targetIndex;

public DeleteCommand(Index targetIndex) {
public DeleteContactCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Parses input arguments and creates a new AddCommand object
*/
public class AddCommandParser implements Parser<AddContactCommand> {
public class AddContactCommandParser implements Parser<AddContactCommand> {

/**
* Parses the given {@code String} of arguments in the context of the AddCommand
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/swift/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeleteCommand> {
public class DeleteContactCommandParser implements Parser<DeleteContactCommand> {

/**
* 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/swift/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,45 @@
* 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
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/swift/logic/parser/AddressBookParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@

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
* 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.
*/
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));
}
}

0 comments on commit 1bcefc2

Please sign in to comment.