Skip to content

Commit

Permalink
Fix all testing compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
gosongying committed Apr 4, 2024
1 parent 165ad15 commit 77af47b
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 385 deletions.
14 changes: 1 addition & 13 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public static class EditPersonDescriptor {
private Email email;
private Address address;
private Set<Tag> tags;
private Type type;
private BookingList bookingList;
private HousekeepingDetails details;
private Area area;
Expand All @@ -122,7 +121,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setType(toCopy.type);
setBookingList(toCopy.bookingList);
setDetails(toCopy.details);
setArea(toCopy.area);
Expand All @@ -132,7 +130,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags, type, area, bookingList);
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags, area, bookingList);
}

public void setName(Name name) {
Expand Down Expand Up @@ -184,14 +182,6 @@ public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

public void setType(Type type) {
this.type = type;
}

public Optional<Type> getType() {
return Optional.ofNullable(type);
}

public void setBookingList(BookingList bookingList) {
this.bookingList = bookingList;
}
Expand Down Expand Up @@ -234,7 +224,6 @@ public boolean equals(Object other) {
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(area, otherEditPersonDescriptor.area)
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(type, otherEditPersonDescriptor.type)
&& Objects.equals(bookingList, otherEditPersonDescriptor.bookingList);
}

Expand All @@ -246,7 +235,6 @@ public String toString() {
.add("email", email)
.add("address", address)
.add("tags", tags)
.add("type", type)
.add("area", area)
.add("booking list", bookingList)
.toString();
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,6 @@ public void setHousekeeper(Housekeeper target, Housekeeper editedHousekeeper) {
housekeepers.setPerson(target, editedHousekeeper);
}

/**
* Removes {@code key} from this {@code AddressBook}.
* {@code key} must exist in the address book.
*/
public void removePerson(Person key) {
if (key.isClient()) {
clients.remove((Client) key);
} else {
housekeepers.remove((Housekeeper) key);
}
}

/**
* Removes {@code client} from this {@code AddressBook}.
* {@code client} must exist in the address book.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.function.Predicate;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -237,7 +238,8 @@ public void updateFilteredHousekeeperList(Predicate<? extends Person> predicate)
}

@Override
public void updateAndSortFilteredClientList(Predicate<Client> predicate) {
public void updateAndSortFilteredClientList(Predicate<Client> predicate, Comparator<Client> comparator) {
throw new AssertionError("This method should not be called.");
}

@Override
Expand Down
126 changes: 82 additions & 44 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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.showHousekeeperAtIndex;
import static seedu.address.logic.commands.CommandTestUtil.showClientAtIndex;
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 All @@ -23,8 +25,12 @@
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Client;
import seedu.address.model.person.Housekeeper;
import seedu.address.model.person.Person;
import seedu.address.testutil.ClientBuilder;
import seedu.address.testutil.EditPersonDescriptorBuilder;
import seedu.address.testutil.HousekeeperBuilder;

/**
* Contains integration tests (interaction with the Model) and unit tests for EditCommand.
Expand All @@ -35,45 +41,76 @@ public class EditCommandTest {

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Person editedPerson = new PersonBuilder().build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor);
Client editedClient = new ClientBuilder().build();
Housekeeper editedHousekeeper = new HousekeeperBuilder().build();
EditPersonDescriptor descriptorClient = new EditPersonDescriptorBuilder(editedClient).build();
EditPersonDescriptor descriptorHousekeeper = new EditPersonDescriptorBuilder(editedHousekeeper).build();
EditCommand editClientCommand = new EditClientCommand(INDEX_FIRST_PERSON, descriptorClient);
EditCommand editHousekeeperCommand = new EditHousekeeperCommand(INDEX_FIRST_PERSON, descriptorHousekeeper);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));
String expectedMessageClient =
String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, Messages.formatClient(editedClient));
String expectedMessageHousekeeper =
String.format(EditHousekeeperCommand.MESSAGE_EDIT_HOUSEKEEPER_SUCCESS,
Messages.formatHousekeeper(editedHousekeeper));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson);
Model expectedModelClient = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModelClient.setClient(model.getFilteredClientList().get(0), editedClient);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
Model expectedModelHousekeeper = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModelHousekeeper.setHousekeeper(model.getFilteredHousekeeperList().get(0), editedHousekeeper);


assertCommandSuccess(editClientCommand, model, expectedMessageClient, expectedModelClient);

assertCommandSuccess(editClientCommand, model, expectedMessageHousekeeper, expectedModelHousekeeper);
}

@Test
public void execute_someFieldsSpecifiedUnfilteredList_success() {
Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size());
Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased());
Index indexLastClient = Index.fromOneBased(model.getFilteredClientList().size());
Client lastClient = model.getFilteredClientList().get(indexLastClient.getZeroBased());

Index indexLastHousekeeper = Index.fromOneBased(model.getFilteredHousekeeperList().size());
Housekeeper lastHousekeeper = model.getFilteredHousekeeperList().get(indexLastHousekeeper.getZeroBased());

PersonBuilder personInList = new PersonBuilder(lastPerson);
Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
ClientBuilder clientInList = new ClientBuilder(lastClient);
Client editedClient = clientInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withTags(VALID_TAG_HUSBAND).build();

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
HousekeeperBuilder housekeeperInList = new HousekeeperBuilder(lastHousekeeper);
Housekeeper editedHousekeeper = housekeeperInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withTags(VALID_TAG_HUSBAND).build();

EditPersonDescriptor descriptorC = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build();
EditCommand editCommand = new EditCommand(indexLastPerson, descriptor);
EditCommand editCommandClient = new EditClientCommand(indexLastClient, descriptorC);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));
EditPersonDescriptor descriptorH = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build();
EditCommand editCommandHousekeeper = new EditHousekeeperCommand(indexLastHousekeeper, descriptorH);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(lastPerson, editedPerson);
String expectedMessageH =
String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, Messages.formatClient(editedClient));
String expectedMessageC =
String.format(EditHousekeeperCommand.MESSAGE_EDIT_HOUSEKEEPER_SUCCESS, Messages.formatHousekeeper(editedHousekeeper));

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
Model expectedModelClient = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModelClient.setClient(lastClient, editedClient);
Model expectedModelHousekeeper = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModelHousekeeper.setHousekeeper(lastHousekeeper, editedHousekeeper);

assertCommandSuccess(editCommandClient, model, expectedMessageC, expectedModelClient);
assertCommandSuccess(editCommandHousekeeper, model, expectedMessageH, expectedModelHousekeeper);
}

@Test
public void execute_noFieldSpecifiedUnfilteredList_success() {
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, new EditPersonDescriptor());
Person editedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
EditCommand editCommand = new EditClientCommand(INDEX_FIRST_PERSON, new EditPersonDescriptor());
Client editedPerson = model.getFilteredClientList().get(INDEX_FIRST_PERSON.getZeroBased());

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));
String expectedMessage =
String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, Messages.formatClient(editedPerson));

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

Expand All @@ -82,47 +119,48 @@ public void execute_noFieldSpecifiedUnfilteredList_success() {

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

Person personInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person editedPerson = new PersonBuilder(personInFilteredList).withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON,
Client personInFilteredList = model.getFilteredClientList().get(INDEX_FIRST_PERSON.getZeroBased());
Client editedPerson = new ClientBuilder(personInFilteredList).withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditClientCommand(INDEX_FIRST_PERSON,
new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build());

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));
String expectedMessage =
String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, Messages.formatClient(editedPerson));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson);
expectedModel.setClient(model.getFilteredClientList().get(0), editedPerson);

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

@Test
public void execute_duplicatePersonUnfilteredList_failure() {
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Client firstPerson = model.getFilteredClientList().get(INDEX_FIRST_PERSON.getZeroBased());
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).build();
EditCommand editCommand = new EditCommand(INDEX_SECOND_PERSON, descriptor);
EditCommand editCommand = new EditClientCommand(INDEX_SECOND_PERSON, descriptor);

assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON);
assertCommandFailure(editCommand, model, EditClientCommand.MESSAGE_DUPLICATE_CLIENT);
}

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

// edit person in filtered list into a duplicate in address book
Person personInList = model.getAddressBook().getPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON,
Person personInList = model.getAddressBook().getClientList().get(INDEX_SECOND_PERSON.getZeroBased());
EditCommand editCommand = new EditClientCommand(INDEX_FIRST_PERSON,
new EditPersonDescriptorBuilder(personInList).build());

assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON);
assertCommandFailure(editCommand, model, EditClientCommand.MESSAGE_DUPLICATE_CLIENT);
}

@Test
public void execute_invalidPersonIndexUnfilteredList_failure() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredClientList().size() + 1);
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor);
EditCommand editCommand = new EditClientCommand(outOfBoundIndex, descriptor);

assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
Expand All @@ -133,24 +171,24 @@ public void execute_invalidPersonIndexUnfilteredList_failure() {
*/
@Test
public void execute_invalidPersonIndexFilteredList_failure() {
showPersonAtIndex(model, INDEX_FIRST_PERSON);
showClientAtIndex(model, INDEX_FIRST_PERSON);
Index outOfBoundIndex = INDEX_SECOND_PERSON;
// ensures that outOfBoundIndex is still in bounds of address book list
assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size());
assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getClientList().size());

EditCommand editCommand = new EditCommand(outOfBoundIndex,
EditCommand editCommand = new EditClientCommand(outOfBoundIndex,
new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build());

assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX);
}

@Test
public void equals() {
final EditCommand standardCommand = new EditCommand(INDEX_FIRST_PERSON, DESC_AMY);
final EditCommand standardCommand = new EditClientCommand(INDEX_FIRST_PERSON, DESC_AMY);

// same values -> returns true
EditPersonDescriptor copyDescriptor = new EditPersonDescriptor(DESC_AMY);
EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_PERSON, copyDescriptor);
EditCommand commandWithSameValues = new EditClientCommand(INDEX_FIRST_PERSON, copyDescriptor);
assertTrue(standardCommand.equals(commandWithSameValues));

// same object -> returns true
Expand All @@ -163,17 +201,17 @@ public void equals() {
assertFalse(standardCommand.equals(new ClearCommand()));

// different index -> returns false
assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_PERSON, DESC_AMY)));
assertFalse(standardCommand.equals(new EditClientCommand(INDEX_SECOND_PERSON, DESC_AMY)));

// different descriptor -> returns false
assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_PERSON, DESC_BOB)));
assertFalse(standardCommand.equals(new EditClientCommand(INDEX_FIRST_PERSON, DESC_BOB)));
}

@Test
public void toStringMethod() {
Index index = Index.fromOneBased(1);
EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();
EditCommand editCommand = new EditCommand(index, editPersonDescriptor);
EditCommand editCommand = new EditClientCommand(index, editPersonDescriptor);
String expected = EditCommand.class.getCanonicalName() + "{index=" + index + ", editPersonDescriptor="
+ editPersonDescriptor + "}";
assertEquals(expected, editCommand.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public void toStringMethod() {
+ editPersonDescriptor.getPhone().orElse(null) + ", email="
+ editPersonDescriptor.getEmail().orElse(null) + ", address="
+ editPersonDescriptor.getAddress().orElse(null) + ", tags="
+ editPersonDescriptor.getTags().orElse(null) + ", type="
+ editPersonDescriptor.getType().orElse(null) + "}";
+ "}";
assertEquals(expected, editPersonDescriptor.toString());
}
}
Loading

0 comments on commit 77af47b

Please sign in to comment.