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

Testing #122

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
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
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
13 changes: 6 additions & 7 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.TYPE_DESC_AMY;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.AMY;

Expand All @@ -28,11 +27,11 @@
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Person;
import seedu.address.model.person.Client;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.StorageManager;
import seedu.address.testutil.PersonBuilder;
import seedu.address.testutil.ClientBuilder;

public class LogicManagerTest {
private static final IOException DUMMY_IO_EXCEPTION = new IOException("dummy IO exception");
Expand Down Expand Up @@ -85,7 +84,7 @@ public void execute_storageThrowsAdException_throwsCommandException() {

@Test
public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException() {
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredPersonList().remove(0));
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredClientList().remove(0));
}

/**
Expand Down Expand Up @@ -166,11 +165,11 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath)
logic = new LogicManager(model, storage);

// Triggers the saveAddressBook method by executing an add command
String addCommand = AddCommand.COMMAND_WORD + TYPE_DESC_AMY + NAME_DESC_AMY + PHONE_DESC_AMY
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY;
Person expectedPerson = new PersonBuilder(AMY).withTags().build();
Client expectedClient = new ClientBuilder(AMY).withTags().build();
ModelManager expectedModel = new ModelManager();
expectedModel.addPerson(expectedPerson);
expectedModel.addClient(expectedClient);
assertCommandFailure(addCommand, CommandException.class, expectedMessage, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Person;
import seedu.address.testutil.PersonBuilder;
import seedu.address.model.person.Client;
import seedu.address.model.person.Housekeeper;
import seedu.address.testutil.ClientBuilder;
import seedu.address.testutil.HousekeeperBuilder;

/**
* Contains integration tests (interaction with the Model) for {@code AddCommand}.
Expand All @@ -27,22 +29,41 @@ public void setUp() {
}

@Test
public void execute_newPerson_success() {
Person validPerson = new PersonBuilder().build();
public void execute_newClient_success() {
Client validClient = new ClientBuilder().build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addPerson(validPerson);
expectedModel.addClient(validClient);

assertCommandSuccess(new AddCommand(validPerson), model,
String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
assertCommandSuccess(new AddClientCommand(validClient), model,
String.format(AddClientCommand.MESSAGE_SUCCESS, Messages.formatClient(validClient)),
expectedModel);
}

@Test
public void execute_duplicatePerson_throwsCommandException() {
Person personInList = model.getAddressBook().getPersonList().get(0);
assertCommandFailure(new AddCommand(personInList), model,
AddCommand.MESSAGE_DUPLICATE_PERSON);
public void execute_newHousekeeper_success() {
Housekeeper validHousekeeper = new HousekeeperBuilder().build();

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

assertCommandSuccess(new AddHousekeeperCommand(validHousekeeper), model,
String.format(AddHousekeeperCommand.MESSAGE_SUCCESS, validHousekeeper),
expectedModel);
}

@Test
public void execute_duplicateClient_throwsCommandException() {
Client clientInList = model.getAddressBook().getClientList().get(0);
assertCommandFailure(new AddClientCommand(clientInList), model,
AddClientCommand.MESSAGE_DUPLICATE_CLIENT);
}

@Test
public void execute_duplicateHousekeeper_throwsCommandException() {
Housekeeper housekeeperInList = model.getAddressBook().getHousekeeperList().get(0);
assertCommandFailure(new AddHousekeeperCommand(housekeeperInList), model,
AddHousekeeperCommand.MESSAGE_DUPLICATE_HOUSEKEEPER);
}

}
24 changes: 19 additions & 5 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BOB;

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 All @@ -27,7 +29,6 @@
import seedu.address.model.person.Person;
import seedu.address.testutil.ClientBuilder;
import seedu.address.testutil.HousekeeperBuilder;
import seedu.address.testutil.PersonBuilder;

public class AddCommandTest {

Expand Down Expand Up @@ -124,8 +125,12 @@ public void equals() {
@Test
public void toStringMethod() {
AddClientCommand addClientCommand = new AddClientCommand(ALICE);
String expected = AddClientCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}";
assertEquals(expected, addClientCommand.toString());
String expectedOne = AddClientCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}";
assertEquals(expectedOne, addClientCommand.toString());

AddHousekeeperCommand addHousekeeperCommand = new AddHousekeeperCommand(BOB);
String expectedTwo = AddHousekeeperCommand.class.getCanonicalName() + "{toAdd=" + BOB + "}";
assertEquals(expectedTwo, addHousekeeperCommand.toString());
}

/**
Expand Down Expand Up @@ -223,14 +228,23 @@ public ObservableList<Housekeeper> getFilteredHousekeeperList() {
}

@Override
public void updateFilteredClientList(Predicate<Client> predicate) {
public void updateFilteredClientList(Predicate<? extends Person> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredHousekeeperList(Predicate<? extends Person> predicate) {
throw new AssertionError("This method should not be called.");
}

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

@Override
public void updateFilteredHousekeeperListWithHousekeeperPredicate(Predicate<Housekeeper> predicate) {
}
}

/**
Expand Down
48 changes: 35 additions & 13 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AREA;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -17,6 +18,9 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.person.BookingList;
import seedu.address.model.person.Client;
import seedu.address.model.person.Housekeeper;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
import seedu.address.testutil.EditPersonDescriptorBuilder;
Expand All @@ -36,12 +40,11 @@ public class CommandTestUtil {
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final String VALID_TYPE_AMY = "client";
public static final String VALID_TYPE_BOB = "housekeeper";
public static final String VALID_AREA_AMY = "north";
public static final String VALID_AREA_BOB = "south";
public static final BookingList VALID_BOOKING_LIST_BOB = new BookingList();

public static final String TYPE_DESC_AMY = " " + VALID_TYPE_AMY;

public static final String TYPE_DESC_BOB = " " + VALID_TYPE_BOB;
public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
public static final String PHONE_DESC_AMY = " " + PREFIX_PHONE + VALID_PHONE_AMY;
Expand All @@ -52,12 +55,15 @@ public class CommandTestUtil {
public static final String ADDRESS_DESC_BOB = " " + PREFIX_ADDRESS + VALID_ADDRESS_BOB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
public static final String AREA_DESC_AMY = " " + PREFIX_AREA + VALID_AREA_AMY;
public static final String AREA_DESC_BOB = " " + PREFIX_AREA + VALID_AREA_BOB;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String INVALID_AREA_DESC = " " + PREFIX_AREA + "central"; // 'northwest' not allowed in area

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";
Expand Down Expand Up @@ -110,24 +116,40 @@ public static void assertCommandFailure(Command command, Model actualModel, Stri
// we are unable to defensively copy the model for comparison later, so we can
// only do so by copying its components.
AddressBook expectedAddressBook = new AddressBook(actualModel.getAddressBook());
List<Person> expectedFilteredList = new ArrayList<>(actualModel.getFilteredPersonList());
List<Client> expectedFilteredClientList = new ArrayList<>(actualModel.getFilteredClientList());
List<Housekeeper> expectedFilteredHousekeeperList = new ArrayList<>(actualModel.getFilteredHousekeeperList());

assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel));
assertEquals(expectedAddressBook, actualModel.getAddressBook());
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
assertEquals(expectedFilteredClientList, actualModel.getFilteredClientList());
assertEquals(expectedFilteredHousekeeperList, actualModel.getFilteredHousekeeperList());
}

/**
* Updates {@code model}'s filtered list to show only the person at the given {@code targetIndex} in the
* Updates {@code model}'s filtered client list to show only the client at the given {@code targetIndex} in the
* {@code model}'s address book.
*/
public static void showPersonAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredPersonList().size());
public static void showClientAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredClientList().size());

Person person = model.getFilteredPersonList().get(targetIndex.getZeroBased());
final String[] splitName = person.getName().fullName.split("\\s+");
model.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));
Client client = model.getFilteredClientList().get(targetIndex.getZeroBased());
final String[] splitName = client.getName().fullName.split("\\s+");
model.updateFilteredClientList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));

assertEquals(1, model.getFilteredPersonList().size());
assertEquals(1, model.getFilteredClientList().size());
}

/**
* Updates {@code model}'s filtered housekeeper list to show only the housekeeper at the given {@code targetIndex}
* in the {@code model}'s address book.
*/
public static void showHousekeeperAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredHousekeeperList().size());

Housekeeper housekeeper = model.getFilteredHousekeeperList().get(targetIndex.getZeroBased());
final String[] splitName = housekeeper.getName().fullName.split("\\s+");
model.updateFilteredHousekeeperList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));

assertEquals(1, model.getFilteredHousekeeperList().size());
}
}
Loading
Loading