Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more rigorous testing to EditCommand functionalities #156

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading