Skip to content

Commit

Permalink
Increase code coverage and fix checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garylow2001 committed Nov 1, 2023
1 parent 5b4032b commit da97802
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -79,32 +84,57 @@ 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);
} catch (Exception e) {
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);
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit da97802

Please sign in to comment.