diff --git a/src/main/java/seedu/address/logic/commands/DeleteMeetingCommand.java b/src/main/java/seedu/address/logic/commands/DeleteMeetingCommand.java index 4d12acb2ad6..cfea0d704a9 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteMeetingCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteMeetingCommand.java @@ -1,5 +1,11 @@ package seedu.address.logic.commands; +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import java.util.List; +import java.util.Optional; + import seedu.address.commons.core.index.Index; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; @@ -9,12 +15,6 @@ import seedu.address.model.person.Lead; import seedu.address.model.person.Person; -import java.util.List; -import java.util.Optional; - -import static java.util.Objects.requireNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; - /** * Deletes a meeting identified using it's displayed index from the address book. */ @@ -60,13 +60,16 @@ private static Person deleteMeeting(Person personToDeleteMeeting) { personToDeleteMeeting.getTags()); } else { // If person is not Client, person is a Lead + assert personToDeleteMeeting.isLead(); + Lead leadWithMeetingDeleted = (Lead) personToDeleteMeeting; personWithMeetingDeleted = new Lead( - personToDeleteMeeting.getName(), - personToDeleteMeeting.getPhone(), - personToDeleteMeeting.getEmail(), - personToDeleteMeeting.getAddress(), + leadWithMeetingDeleted.getName(), + leadWithMeetingDeleted.getPhone(), + leadWithMeetingDeleted.getEmail(), + leadWithMeetingDeleted.getAddress(), + leadWithMeetingDeleted.getKeyMilestone(), Optional.empty(), - personToDeleteMeeting.getTags()); + leadWithMeetingDeleted.getTags()); } return personWithMeetingDeleted; @@ -85,7 +88,8 @@ public CommandResult execute(Model model) throws CommandException { Person personWithMeetingDeleted = deleteMeeting(personToDeleteMeeting); model.setPerson(personToDeleteMeeting, personWithMeetingDeleted); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format(MESSAGE_DELETE_MEETING_SUCCESS, personToDeleteMeeting.getMeetingTimeString(), + return new CommandResult(String.format(MESSAGE_DELETE_MEETING_SUCCESS, + personToDeleteMeeting.getMeetingTimeString(), targetIndex.getOneBased())); } diff --git a/src/main/java/seedu/address/logic/parser/DeleteMeetingCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteMeetingCommandParser.java index 43b2a16f735..def3dedc869 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteMeetingCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteMeetingCommandParser.java @@ -1,12 +1,11 @@ package seedu.address.logic.parser; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.DeleteCommand; import seedu.address.logic.commands.DeleteMeetingCommand; import seedu.address.logic.parser.exceptions.ParseException; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; - /** * Parses input arguments and creates a new DeleteMeetingCommand object */ diff --git a/src/test/java/seedu/address/logic/commands/DeleteMeetingCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteMeetingCommandTest.java index ecd21ee3759..913c5131a28 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteMeetingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteMeetingCommandTest.java @@ -1,6 +1,17 @@ package seedu.address.logic.commands; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +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.Model; @@ -9,14 +20,6 @@ import seedu.address.model.person.Person; import seedu.address.testutil.PersonBuilder; -import static org.junit.jupiter.api.Assertions.*; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; -import static seedu.address.testutil.TypicalClients.ALICE; -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; - /** * Contains integration tests (interaction with the Model) and unit tests for * {@code DeleteMeetingCommand}. @@ -44,10 +47,12 @@ public void execute_validIndexUnfilteredList_success() { @Test public void execute_invalidIndexUnfilteredList_throwsCommandException() { - Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); // Last person in typical address book + Index outOfBoundIndex = Index.fromOneBased( + model.getFilteredPersonList().size() + 1); // Last person in typical address book DeleteMeetingCommand deleteMeetingCommand = new DeleteMeetingCommand(outOfBoundIndex); - CommandTestUtil.assertCommandFailure(deleteMeetingCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + CommandTestUtil.assertCommandFailure(deleteMeetingCommand, model, + Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @Test @@ -79,19 +84,20 @@ public void execute_invalidIndexFilteredList_throwsCommandException() { DeleteMeetingCommand deleteMeetingCommand = new DeleteMeetingCommand(outOfBoundIndex); - CommandTestUtil.assertCommandFailure(deleteMeetingCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + CommandTestUtil.assertCommandFailure(deleteMeetingCommand, model, + Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @Test public void deleteMeeting_personIsLead() { - Index INDEX_FIRST_LEAD = Index.fromOneBased(5); - Person leadToDeleteMeeting = model.getFilteredPersonList().get(INDEX_FIRST_LEAD.getZeroBased()); + Index indexFirstLead = Index.fromOneBased(5); + Person leadToDeleteMeeting = model.getFilteredPersonList().get(indexFirstLead.getZeroBased()); assertTrue(leadToDeleteMeeting.isLead()); Person leadWithMeetingDeleted = new PersonBuilder(leadToDeleteMeeting) - .withMeetingTime(null).buildLead(); // First person in typical address book without meeting time + .withMeetingTime(null).buildLead(); // First lead in typical address book without meeting time - DeleteMeetingCommand deleteMeetingCommand = new DeleteMeetingCommand(INDEX_FIRST_LEAD); + DeleteMeetingCommand deleteMeetingCommand = new DeleteMeetingCommand(indexFirstLead); try { deleteMeetingCommand.execute(model); @@ -99,12 +105,36 @@ public void deleteMeeting_personIsLead() { fail(); } - Person expectedLead = model.getFilteredPersonList().get(INDEX_FIRST_LEAD.getZeroBased()); + Person expectedLead = model.getFilteredPersonList().get(indexFirstLead.getZeroBased()); assertTrue(expectedLead.isLead()); assertEquals(expectedLead, leadWithMeetingDeleted); } + @Test + public void deleteMeeting_personNoMeetingTime_returnsPerson() { + Index indexPersonWithNoMeeting = Index.fromOneBased(3); // Third person in typical address book + Person personToDeleteMeeting = model.getFilteredPersonList() + .get(indexPersonWithNoMeeting.getZeroBased()); + + assertTrue(personToDeleteMeeting.getMeetingTime().isEmpty()); + + Person personWithMeetingDeleted = new PersonBuilder(personToDeleteMeeting) + .withMeetingTime(null).buildClient(); + assertEquals(personToDeleteMeeting, personWithMeetingDeleted); + + DeleteMeetingCommand deleteMeetingCommand = new DeleteMeetingCommand(indexPersonWithNoMeeting); + + try { + deleteMeetingCommand.execute(model); + } catch (Exception e) { + fail(); + } + + Person expectedPerson = model.getFilteredPersonList().get(indexPersonWithNoMeeting.getZeroBased()); + assertEquals(expectedPerson, personWithMeetingDeleted); + } + @Test public void equals() { DeleteMeetingCommand deleteMeetingFirstCommand = new DeleteMeetingCommand(INDEX_FIRST_PERSON); diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 95c734e74e0..299fc7a8d89 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -3,7 +3,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.*; +import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MEETING_TIME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +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; diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index ca36dc729dd..59771816997 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -20,6 +20,7 @@ import seedu.address.logic.commands.AddLeadCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteMeetingCommand; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditLeadDescriptor; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; @@ -74,6 +75,14 @@ public void parseCommand_delete() throws Exception { assertEquals(new DeleteCommand(INDEX_FIRST_PERSON), command); } //todo: test failed maybe because meeting time is null, should be fixed after merging master + + @Test + public void parseCommand_deleteMeeting() throws Exception { + DeleteMeetingCommand command = (DeleteMeetingCommand) parser.parseCommand( + DeleteMeetingCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); + assertEquals(new DeleteMeetingCommand(INDEX_FIRST_PERSON), command); + } + @Test public void parseCommand_edit_withClient() throws Exception { Client client = new PersonBuilder().buildClient(); diff --git a/src/test/java/seedu/address/logic/parser/DeleteMeetingCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteMeetingCommandParserTest.java index c664534f90d..59895eddb8b 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteMeetingCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteMeetingCommandParserTest.java @@ -1,13 +1,14 @@ package seedu.address.logic.parser; -import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.DeleteMeetingCommand; - import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; 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.logic.commands.DeleteMeetingCommand; + public class DeleteMeetingCommandParserTest { private DeleteMeetingCommandParser parser = new DeleteMeetingCommandParser();