Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
-Fix broken command
-Add new test cases
  • Loading branch information
hm-yang1 committed Sep 20, 2024
1 parent 05cc493 commit 01c1746
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 74 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static String format(Person person) {
.append(person.getEmail())
.append("; Address: ")
.append(person.getAddress())
.append("; Remark: ")
.append(person.getRemark())
.append("; Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -100,10 +99,16 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Remark updatedRemark = editPersonDescriptor.getRemark();
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRemark, updatedTags);
return new Person(
updatedName,
updatedPhone,
updatedEmail,
updatedAddress,
personToEdit.getRemark(),
updatedTags
);
}

@Override
Expand Down Expand Up @@ -140,8 +145,6 @@ public static class EditPersonDescriptor {
private Email email;
private Address address;
private Set<Tag> tags;
private Remark remark;

public EditPersonDescriptor() {}

/**
Expand All @@ -154,7 +157,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setRemark(toCopy.remark);
}

/**
Expand Down Expand Up @@ -196,14 +198,6 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setRemark(Remark remark) {
this.remark = remark;
}

public Remark getRemark() {
return remark;
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand Down Expand Up @@ -237,8 +231,7 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(remark, otherEditPersonDescriptor.remark);
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
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.logic.parser.CliSyntax.*;

import java.util.Collection;
import java.util.Collections;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
/**
* Parses a {@code String tag} into a Remark
*/
public static Remark parseRemark(String s) {
requireNonNull(s);
String trimmedRemark = s.trim();
return new Remark(trimmedRemark);
public static Remark parseRemark(String remarkString) {
requireNonNull(remarkString);
return new Remark(remarkString);
}
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public Person(Name name,
Address address,
Remark remark,
Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
requireAllNonNull(name, phone, email, address, remark, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.tags.addAll(tags);
this.remark = remark;
this.tags.addAll(tags);
}

public Name getName() {
Expand Down
73 changes: 54 additions & 19 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.*;
import seedu.address.model.person.Address;
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.person.Remark;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -16,24 +21,54 @@ public class SampleDataUtil {
public static final Remark EMPTY_REMARK = new Remark("");
public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK,
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_REMARK,
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), EMPTY_REMARK,
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), EMPTY_REMARK,
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK,
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK,
getTagSet("colleagues"))
new Person(
new Name("Alex Yeoh"),
new Phone("87438807"),
new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"),
EMPTY_REMARK,
getTagSet("friends")
),
new Person(
new Name("Bernice Yu"),
new Phone("99272758"),
new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
EMPTY_REMARK,
getTagSet("colleagues", "friends")
),
new Person(
new Name("Charlotte Oliveiro"),
new Phone("93210283"),
new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
EMPTY_REMARK,
getTagSet("neighbours")
),
new Person(
new Name("David Li"),
new Phone("91031282"),
new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
EMPTY_REMARK,
getTagSet("family")
),
new Person(
new Name("Irfan Ibrahim"),
new Phone("92492021"),
new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"),
EMPTY_REMARK,
getTagSet("classmates")
),
new Person(
new Name("Roy Balakrishnan"),
new Phone("92624417"),
new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
EMPTY_REMARK,
getTagSet("colleagues")
)
};
}

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 @@ -107,7 +107,7 @@ public Person toModelType() throws IllegalValueException {
final Remark modelRemark = new Remark(remark);

final Set<Tag> modelTags = new HashSet<>(personTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, new Remark(""), modelTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelTags);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"phone": "94351253",
"email": "[email protected]",
"address": "123, Jurong West Ave 6, #08-111",
"remark": "",
"tags": [ "friends" ]
}, {
"name": "Alice Pauline",
"phone": "94351253",
"email": "[email protected]",
"address": "4th street"
"address": "4th street",
"remark": ""
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,49 @@
"phone" : "94351253",
"email" : "[email protected]",
"address" : "123, Jurong West Ave 6, #08-111",
"remark" : "Nice",
"tags" : [ "friends" ]
}, {
"name" : "Benson Meier",
"phone" : "98765432",
"email" : "[email protected]",
"address" : "311, Clementi Ave 2, #02-25",
"remark" : "athletic",
"tags" : [ "owesMoney", "friends" ]
}, {
"name" : "Carl Kurz",
"phone" : "95352563",
"email" : "[email protected]",
"address" : "wall street",
"remark" : "just carl",
"tags" : [ ]
}, {
"name" : "Daniel Meier",
"phone" : "87652533",
"email" : "[email protected]",
"address" : "10th street",
"remark" : "more",
"tags" : [ "friends" ]
}, {
"name" : "Elle Meyer",
"phone" : "9482224",
"email" : "[email protected]",
"address" : "michegan ave",
"remark" : "",
"tags" : [ ]
}, {
"name" : "Fiona Kunz",
"phone" : "9482427",
"email" : "[email protected]",
"address" : "little tokyo",
"remark" : "",
"tags" : [ ]
}, {
"name" : "George Best",
"phone" : "9482442",
"email" : "[email protected]",
"address" : "4th street",
"remark" : "",
"tags" : [ ]
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class EditCommandTest {

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Person editedPerson = new PersonBuilder().build();
Person editedPerson = new PersonBuilder().withRemark("Nice").build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public class RemarkCommandTest {
private static final String REMARK_STUB = "Some remark";
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

@Test
public void execute_addRemarkUnfilteredList_success() {
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person editedPerson = new PersonBuilder(firstPerson).withRemark(REMARK_STUB).build();
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark(editedPerson.getRemark().value));
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, editedPerson);
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, Messages.format(editedPerson));
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(firstPerson, editedPerson);
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel);
Expand All @@ -37,7 +38,7 @@ public void execute_deleteRemarkUnfilteredList_success() {
Person editedPerson = new PersonBuilder(firstPerson).withRemark("").build();
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_PERSON,
new Remark(editedPerson.getRemark().toString()));
String expectedMessage = String.format(RemarkCommand.MESSAGE_DELETE_REMARK_SUCCESS, editedPerson);
String expectedMessage = String.format(RemarkCommand.MESSAGE_DELETE_REMARK_SUCCESS, Messages.format(editedPerson));
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(firstPerson, editedPerson);
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel);
Expand All @@ -50,7 +51,7 @@ public void execute_filteredList_success() {
Person editedPerson = new PersonBuilder(model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()))
.withRemark(REMARK_STUB).build();
RemarkCommand remarkCommand = new RemarkCommand(INDEX_FIRST_PERSON, new Remark(editedPerson.getRemark().value));
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, editedPerson);
String expectedMessage = String.format(RemarkCommand.MESSAGE_ADD_REMARK_SUCCESS, Messages.format(editedPerson));
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(firstPerson, editedPerson);
assertCommandSuccess(remarkCommand, model, expectedMessage, expectedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void parseCommand_help() throws Exception {

@Test
public void parseCommand_remark() throws Exception {
assertTrue(parser.parseCommand(RemarkCommand.COMMAND_WORD) instanceof RemarkCommand);
assertTrue(parser.parseCommand(RemarkCommand.COMMAND_WORD + " 3 r/") instanceof RemarkCommand);
}


Expand Down
10 changes: 8 additions & 2 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ public void equals() {

@Test
public void toStringMethod() {
String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress() + ", tags=" + ALICE.getTags() + "}";
String expected = Person.class.getCanonicalName()
+ "{name=" + ALICE.getName()
+ ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail()
+ ", address=" + ALICE.getAddress()
+ ", remark=" + ALICE.getRemark()
+ ", tags=" + ALICE.getTags()
+ "}";
assertEquals(expected, ALICE.toString());
}
}
Loading

0 comments on commit 01c1746

Please sign in to comment.