Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yashma-sonara committed Mar 15, 2024
1 parent 98f2a19 commit d1cef6c
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 226 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;

import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -23,13 +23,13 @@ public class AddCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
//+ PREFIX_PHONE + "PHONE "

+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
//+ PREFIX_PHONE + "98765432 "

+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;

import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

Expand Down Expand Up @@ -40,12 +40,12 @@ public class EditCommand extends Command {
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
//+ "[" + PREFIX_PHONE + "PHONE] "

+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
//+ PREFIX_PHONE + "91234567 "

+ PREFIX_EMAIL + "[email protected]";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
Expand Down Expand Up @@ -96,7 +96,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
assert personToEdit != null;

Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
//Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());

Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Expand Down Expand Up @@ -134,7 +134,7 @@ public String toString() {
*/
public static class EditPersonDescriptor {
private Name name;
private Phone phone;

private Email email;
private Address address;
private Set<Tag> tags;
Expand All @@ -147,7 +147,7 @@ public EditPersonDescriptor() {}
*/
public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setPhone(toCopy.phone);

setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
Expand All @@ -157,7 +157,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);
return CollectionUtil.isAnyNonNull(name, email, address, tags);
}

public void setName(Name name) {
Expand All @@ -168,13 +168,9 @@ public Optional<Name> getName() {
return Optional.ofNullable(name);
}

public void setPhone(Phone phone) {
this.phone = phone;
}

public Optional<Phone> getPhone() {
return Optional.ofNullable(phone);
}



public void setEmail(Email email) {
this.email = email;
Expand Down Expand Up @@ -222,7 +218,7 @@ public boolean equals(Object other) {

EditPersonDescriptor otherEditPersonDescriptor = (EditPersonDescriptor) other;
return Objects.equals(name, otherEditPersonDescriptor.name)
&& Objects.equals(phone, otherEditPersonDescriptor.phone)

&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
Expand All @@ -232,7 +228,7 @@ public boolean equals(Object other) {
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
.add("phone", phone)

.add("email", email)
.add("address", address)
.add("tags", tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;

import seedu.address.model.tag.Tag;

/**
Expand All @@ -40,7 +40,7 @@ public AddCommand parse(String args) throws ParseException {

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_EMAIL, PREFIX_ADDRESS);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
//Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());

Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class CliSyntax {

/* Prefix definitions */
public static final Prefix PREFIX_NAME = new Prefix("n/");
//public static final Prefix PREFIX_PHONE = new Prefix("p/");

public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;

import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
Expand Down Expand Up @@ -49,9 +49,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
}
//if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
// editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()));
//}



if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ public static Name parseName(String name) throws ParseException {
return new Name(trimmedName);
}

/**
* Parses a {@code String phone} into a {@code Phone}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code phone} is invalid.
*/
/*public static Phone parsePhone(String phone) throws ParseException {
requireNonNull(phone);
String trimmedPhone = phone.trim();
if (!Phone.isValidPhone(trimmedPhone)) {
throw new ParseException(Phone.MESSAGE_CONSTRAINTS);
}
return new Phone(trimmedPhone);
}*/















/**
* Parses a {@code String address} into an {@code Address}.
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Person {

// Identity fields
private final Name name;
//private final Phone phone;

private final Email email;

// Data fields
Expand All @@ -31,7 +31,7 @@ public class Person {
public Person(Name name, Email email, Address address, Set<Tag> tags) {
requireAllNonNull(name, email, address, tags);
this.name = name;
//this.phone = phone;

this.email = email;
this.address = address;
this.tags.addAll(tags);
Expand All @@ -41,9 +41,9 @@ public Name getName() {
return name;
}

//public Phone getPhone() {
// return phone;
//}




public Email getEmail() {
return email;
Expand Down Expand Up @@ -91,7 +91,7 @@ public boolean equals(Object other) {

Person otherPerson = (Person) other;
return name.equals(otherPerson.name)
//&& phone.equals(otherPerson.phone)

&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& tags.equals(otherPerson.tags);
Expand All @@ -107,7 +107,7 @@ public int hashCode() {
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
//.add("phone", phone)

.add("email", email)
.add("address", address)
.add("tags", tags)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;

import seedu.address.model.tag.Tag;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class PersonCard extends UiPart<Region> {
private Label name;
@FXML
private Label id;
//@FXML
//private Label phone;


@FXML
private Label address;
@FXML
Expand All @@ -49,7 +49,7 @@ public PersonCard(Person person, int displayedIndex) {
this.person = person;
id.setText(displayedIndex + ". ");
name.setText(person.getName().fullName);
//phone.setText(person.getPhone().value);

address.setText(person.getAddress().value);
email.setText(person.getEmail().value);
person.getTags().stream()
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
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.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.AMY;

Expand Down Expand Up @@ -165,8 +165,7 @@ 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 + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY;
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY;
Person expectedPerson = new PersonBuilder(AMY).withTags().build();
ModelManager expectedModel = new ModelManager();
expectedModel.addPerson(expectedPerson);
Expand Down
13 changes: 5 additions & 8 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;

import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.testutil.Assert.assertThrows;

Expand All @@ -28,8 +28,7 @@ public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo";
public static final String VALID_PHONE_AMY = "11111111";
public static final String VALID_PHONE_BOB = "22222222";

public static final String VALID_EMAIL_AMY = "[email protected]";
public static final String VALID_EMAIL_BOB = "[email protected]";
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1";
Expand All @@ -39,8 +38,6 @@ public class CommandTestUtil {

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;
public static final String PHONE_DESC_BOB = " " + PREFIX_PHONE + VALID_PHONE_BOB;
public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY;
public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB;
public static final String ADDRESS_DESC_AMY = " " + PREFIX_ADDRESS + VALID_ADDRESS_AMY;
Expand All @@ -49,7 +46,7 @@ public class CommandTestUtil {
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;

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_PHONE_DESC = " " + "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
Expand All @@ -62,10 +59,10 @@ public class CommandTestUtil {

static {
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withTags(VALID_TAG_FRIEND).build();
DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB)
.withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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_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;
Expand Down Expand Up @@ -55,11 +55,10 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased());

PersonBuilder personInList = new PersonBuilder(lastPerson);
Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withTags(VALID_TAG_HUSBAND).build();
Person editedPerson = personInList.withName(VALID_NAME_BOB).withTags(VALID_TAG_HUSBAND).build();

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

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));
Expand Down
Loading

0 comments on commit d1cef6c

Please sign in to comment.