Skip to content

Commit

Permalink
Merge pull request #156 from Xilef121/branch-editcommand-testing
Browse files Browse the repository at this point in the history
Add more rigorous testing to EditCommand functionalities
  • Loading branch information
cocoanautz authored Apr 15, 2024
2 parents 2909e96 + 146c5fe commit 37ecb10
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import static seedu.address.logic.commands.CommandTestUtil.DESC_ADIDAS;
import static seedu.address.logic.commands.CommandTestUtil.DESC_BMW;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BMW;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BMW;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_ANALYST;
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.TypicalCompanies.getTypicalInternBook;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_COMPANY;
Expand All @@ -26,6 +29,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.EditCommand.EditCompanyDescriptor;
import seedu.address.model.InternBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyInternBook;
Expand Down Expand Up @@ -286,4 +290,93 @@ public boolean hasCompany(Company company) {
return this.companies.get(0).isSameCompany(company);
}
}

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Company editedCompany = new CompanyBuilder().build();
EditCommand.EditCompanyDescriptor descriptor = new EditCompanyDescriptorBuilder(editedCompany).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_COMPANY, descriptor);

String expectedMessage = String.format(
EditCommand.MESSAGE_EDIT_COMPANY_SUCCESS, Messages.format(editedCompany));

Model expectedModel = new ModelManager(new InternBook(model.getAddressBook()), new UserPrefs());
expectedModel.setCompany(model.getFilteredCompanyList().get(0), editedCompany);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_someFieldsSpecifiedUnfilteredList_success() {
Index indexLastPerson = Index.fromOneBased(model.getFilteredCompanyList().size());
Company lastCompany = model.getFilteredCompanyList().get(indexLastPerson.getZeroBased());

CompanyBuilder personInList = new CompanyBuilder(lastCompany);
Company editedCompany = personInList.withName(VALID_NAME_BMW).withPhone(VALID_PHONE_BMW)
.withTags(VALID_TAG_ANALYST).build();

EditCompanyDescriptor descriptor = new EditCompanyDescriptorBuilder().withName(VALID_NAME_BMW)
.withPhone(VALID_PHONE_BMW).withTags(VALID_TAG_ANALYST).build();
EditCommand editCommand = new EditCommand(indexLastPerson, descriptor);

String expectedMessage = String.format(
EditCommand.MESSAGE_EDIT_COMPANY_SUCCESS, Messages.format(editedCompany));

Model expectedModel = new ModelManager(new InternBook(model.getAddressBook()), new UserPrefs());
expectedModel.setCompany(lastCompany, editedCompany);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_noFieldSpecifiedUnfilteredList_success() {
EditCommand editCommand = new EditCommand(INDEX_FIRST_COMPANY, new EditCompanyDescriptor());
Company editedCompany = model.getFilteredCompanyList().get(INDEX_FIRST_COMPANY.getZeroBased());

String expectedMessage = String.format(
EditCommand.MESSAGE_EDIT_COMPANY_SUCCESS, Messages.format(editedCompany));

Model expectedModel = new ModelManager(new InternBook(model.getAddressBook()), new UserPrefs());

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_filteredList_success() {
showPersonAtIndex(model, INDEX_FIRST_COMPANY);

Company companyInFilteredList = model.getFilteredCompanyList().get(INDEX_FIRST_COMPANY.getZeroBased());
Company editedCompany = new CompanyBuilder(companyInFilteredList).withName(VALID_NAME_BMW).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_COMPANY,
new EditCompanyDescriptorBuilder().withName(VALID_NAME_BMW).build());

String expectedMessage = String.format(
EditCommand.MESSAGE_EDIT_COMPANY_SUCCESS, Messages.format(editedCompany));

Model expectedModel = new ModelManager(new InternBook(model.getAddressBook()), new UserPrefs());
expectedModel.setCompany(model.getFilteredCompanyList().get(0), editedCompany);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_duplicatePersonUnfilteredList_failure() {
Company firstCompany = model.getFilteredCompanyList().get(INDEX_FIRST_COMPANY.getZeroBased());
EditCompanyDescriptor descriptor = new EditCompanyDescriptorBuilder(firstCompany).build();
EditCommand editCommand = new EditCommand(INDEX_SECOND_COMPANY, descriptor);

assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_COMPANY);
}

@Test
public void execute_duplicatePersonFilteredList_failure() {
showPersonAtIndex(model, INDEX_FIRST_COMPANY);

// edit company in filtered list into a duplicate in address book
Company companyInList = model.getAddressBook().getCompanyList().get(INDEX_SECOND_COMPANY.getZeroBased());
EditCommand editCommand = new EditCommand(INDEX_FIRST_COMPANY,
new EditCompanyDescriptorBuilder(companyInList).build());

assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_COMPANY);
}
}

0 comments on commit 37ecb10

Please sign in to comment.