From 809a9ff8a4157be00df7d5bbd78490d41434ac1c Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Fri, 9 Dec 2016 23:45:15 +0800 Subject: [PATCH 01/23] Add testutil classes to facilitate testing --- .../addressbook/testutil/PersonBuilder.java | 40 ++++++++++++ .../addressbook/testutil/TestPerson.java | 62 +++++++++++++++++++ .../testutil/TypicalTestPersons.java | 55 ++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 test/java/seedu/addressbook/testutil/PersonBuilder.java create mode 100644 test/java/seedu/addressbook/testutil/TestPerson.java create mode 100644 test/java/seedu/addressbook/testutil/TypicalTestPersons.java diff --git a/test/java/seedu/addressbook/testutil/PersonBuilder.java b/test/java/seedu/addressbook/testutil/PersonBuilder.java new file mode 100644 index 000000000..14722ec80 --- /dev/null +++ b/test/java/seedu/addressbook/testutil/PersonBuilder.java @@ -0,0 +1,40 @@ +package seedu.addressbook.testutil; + +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.Address; +import seedu.addressbook.data.person.Email; +import seedu.addressbook.data.person.Name; +import seedu.addressbook.data.person.Phone; + +public class PersonBuilder { + + private TestPerson person; + + public PersonBuilder() { + this.person = new TestPerson(); + } + + public PersonBuilder withName(String name) throws IllegalValueException { + this.person.setName(new Name(name)); + return this; + } + + public PersonBuilder withPhone(String phone, boolean isPrivate) throws IllegalValueException { + this.person.setPhone(new Phone(phone, isPrivate)); + return this; + } + + public PersonBuilder withEmail(String email, boolean isPrivate) throws IllegalValueException { + this.person.setEmail(new Email(email, isPrivate)); + return this; + } + + public PersonBuilder withAddress(String address, boolean isPrivate) throws IllegalValueException { + this.person.setAddress(new Address(address, isPrivate)); + return this; + } + + public TestPerson build() { + return this.person; + } +} diff --git a/test/java/seedu/addressbook/testutil/TestPerson.java b/test/java/seedu/addressbook/testutil/TestPerson.java new file mode 100644 index 000000000..f0fca0e1d --- /dev/null +++ b/test/java/seedu/addressbook/testutil/TestPerson.java @@ -0,0 +1,62 @@ +package seedu.addressbook.testutil; + +import seedu.addressbook.data.person.Address; +import seedu.addressbook.data.person.Email; +import seedu.addressbook.data.person.Name; +import seedu.addressbook.data.person.Phone; +import seedu.addressbook.data.person.ReadOnlyPerson; +import seedu.addressbook.data.tag.UniqueTagList; + +public class TestPerson implements ReadOnlyPerson { + + private Name name; + private Phone phone; + private Email email; + private Address address; + + private final UniqueTagList tags; + + public TestPerson() { + tags = new UniqueTagList(); + } + + public Name getName() { + return name; + } + + public Phone getPhone() { + return phone; + } + + public Email getEmail() { + return email; + } + + public Address getAddress() { + return address; + } + + public void setName(Name name) { + this.name = name; + } + + public void setPhone(Phone phone) { + this.phone = phone; + } + + public void setEmail(Email email) { + this.email = email; + } + + public void setAddress(Address address) { + this.address = address; + } + + + public UniqueTagList getTags() { + return new UniqueTagList(tags); + } + + + +} diff --git a/test/java/seedu/addressbook/testutil/TypicalTestPersons.java b/test/java/seedu/addressbook/testutil/TypicalTestPersons.java new file mode 100644 index 000000000..b934dce45 --- /dev/null +++ b/test/java/seedu/addressbook/testutil/TypicalTestPersons.java @@ -0,0 +1,55 @@ +package seedu.addressbook.testutil; + +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.Person; +import seedu.addressbook.data.person.UniquePersonList; + +public class TypicalTestPersons { + + public static TestPerson claude, gates, jobs, donald, hopper; + + public TypicalTestPersons() { + try { + claude = new PersonBuilder().withName("Claude Shannon").withPhone("91234567", false) + .withEmail("cs@gmail.com", false).withAddress("1 Clementi Road", true).build(); + + gates = new PersonBuilder().withName("Bill Gates").withPhone("92434567", false) + .withEmail("bg@gmail.com", false).withAddress("2 Clementi Road", false).build(); + + jobs = new PersonBuilder().withName("Steve Jobs").withPhone("91934267", true) + .withEmail("sj@gmail.com", true).withAddress("3 Clementi Road", false).build(); + + donald = new PersonBuilder().withName("Donald Knuth").withPhone("91214567", true) + .withEmail("dk@gmail.com", false).withAddress("4 Clementi Road", true).build(); + + hopper = new PersonBuilder().withName("Grace Hopper").withPhone("83434567", true) + .withEmail("gh@gmail.com", true).withAddress("5 Clementi Road", true).build(); + + } catch (IllegalValueException e) { + e.printStackTrace(); + assert false : "not possible"; + } + } + + public void loadAddressBookWithSampleData(AddressBook ab) { + try { + for (TestPerson t : getTypicalPersons()) { + ab.addPerson(new Person(t)); + } + } catch (UniquePersonList.DuplicatePersonException e) { + assert false : "not possible"; + } + } + + public TestPerson[] getTypicalPersons() { + return new TestPerson[] { claude, gates, jobs, donald, hopper }; + } + + + public AddressBook getTypicalAddressBook() { + AddressBook ab = new AddressBook(); + loadAddressBookWithSampleData(ab); + return ab; + } +} From cb04f843bded3da749cb1e411828fb2ab0f800c5 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sat, 10 Dec 2016 01:02:20 +0800 Subject: [PATCH 02/23] Add TestMain class to facilitate testing of commands --- .../addressbook/testutil/PersonBuilder.java | 3 + .../addressbook/testutil/TestDataHelper.java | 17 +++++ .../seedu/addressbook/testutil/TestMain.java | 67 +++++++++++++++++++ .../testutil/TypicalTestPersons.java | 3 + 4 files changed, 90 insertions(+) create mode 100644 test/java/seedu/addressbook/testutil/TestDataHelper.java create mode 100644 test/java/seedu/addressbook/testutil/TestMain.java diff --git a/test/java/seedu/addressbook/testutil/PersonBuilder.java b/test/java/seedu/addressbook/testutil/PersonBuilder.java index 14722ec80..e4dd58f7d 100644 --- a/test/java/seedu/addressbook/testutil/PersonBuilder.java +++ b/test/java/seedu/addressbook/testutil/PersonBuilder.java @@ -6,6 +6,9 @@ import seedu.addressbook.data.person.Name; import seedu.addressbook.data.person.Phone; +/** + * Factory class for building TestPerson + */ public class PersonBuilder { private TestPerson person; diff --git a/test/java/seedu/addressbook/testutil/TestDataHelper.java b/test/java/seedu/addressbook/testutil/TestDataHelper.java new file mode 100644 index 000000000..8d15358e0 --- /dev/null +++ b/test/java/seedu/addressbook/testutil/TestDataHelper.java @@ -0,0 +1,17 @@ +package seedu.addressbook.testutil; + +import java.util.Arrays; +import java.util.List; + +import seedu.addressbook.data.person.Person; + +/** + * A utility class to generate test data. + */ +public class TestDataHelper { + + public List generatePersonList(Person... persons) { + return Arrays.asList(persons); + } + +} diff --git a/test/java/seedu/addressbook/testutil/TestMain.java b/test/java/seedu/addressbook/testutil/TestMain.java new file mode 100644 index 000000000..3ad18f096 --- /dev/null +++ b/test/java/seedu/addressbook/testutil/TestMain.java @@ -0,0 +1,67 @@ +package seedu.addressbook.testutil; +import seedu.addressbook.data.person.ReadOnlyPerson; + +import seedu.addressbook.commands.*; +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.parser.Parser; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Test class for Main + */ +public class TestMain { + + private AddressBook addressBook; + + /** The list of person shown to the user most recently. */ + private List lastShownList = Collections.emptyList(); + + public TestMain() { + this.addressBook = new TypicalTestPersons().getTypicalAddressBook(); + } + + public List getLastShownList() { + return this.lastShownList; + } + + public AddressBook getAddressBook() { + return this.addressBook; + } + + /** Reads the user command and executes it */ + public CommandResult runCommand(String inputCommand) { + Command command = new Parser().parseCommand(inputCommand); + CommandResult result = executeCommand(command); + recordResult(result); + return result; + } + + /** Updates the {@link #lastShownList} if the result contains a list of Persons. */ + private void recordResult(CommandResult result) { + final Optional> personList = result.getRelevantPersons(); + if (personList.isPresent()) { + lastShownList = personList.get(); + } + } + + /** + * Executes the command and returns the result. + * + * @param command user command + * @return result of the command + */ + private CommandResult executeCommand(Command command) { + try { + command.setData(addressBook, lastShownList); + CommandResult result = command.execute(); + return result; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + +} diff --git a/test/java/seedu/addressbook/testutil/TypicalTestPersons.java b/test/java/seedu/addressbook/testutil/TypicalTestPersons.java index b934dce45..286936d6d 100644 --- a/test/java/seedu/addressbook/testutil/TypicalTestPersons.java +++ b/test/java/seedu/addressbook/testutil/TypicalTestPersons.java @@ -5,6 +5,9 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.UniquePersonList; +/** + * Class to generate typical test persons + */ public class TypicalTestPersons { public static TestPerson claude, gates, jobs, donald, hopper; From 228696bdef3d4b232a7d6e71090cc4b5fc2fd59d Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sat, 10 Dec 2016 01:03:17 +0800 Subject: [PATCH 03/23] Add equals() methond in AddressBook, UniquePersonList and UniqueTagList --- src/seedu/addressbook/data/AddressBook.java | 8 ++++++++ src/seedu/addressbook/data/person/UniquePersonList.java | 8 ++++++++ src/seedu/addressbook/data/tag/UniqueTagList.java | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 32d03913d..e71e12ee5 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -143,4 +143,12 @@ public UniquePersonList getAllPersons() { public UniqueTagList getAllTags() { return new UniqueTagList(allTags); } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof AddressBook // instanceof handles nulls + && this.allPersons.equals(((AddressBook) other).allPersons) + && this.allTags.equals(((AddressBook) other).allTags)); + } } diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index bd85a891f..ddda8becf 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -124,6 +124,14 @@ public void clear() { public Iterator iterator() { return internalList.iterator(); } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof UniquePersonList // instanceof handles nulls + && this.internalList.equals( + ((UniquePersonList) other).internalList)); + } @Override public boolean equals(Object other) { diff --git a/src/seedu/addressbook/data/tag/UniqueTagList.java b/src/seedu/addressbook/data/tag/UniqueTagList.java index 4211752cd..f63d0b913 100644 --- a/src/seedu/addressbook/data/tag/UniqueTagList.java +++ b/src/seedu/addressbook/data/tag/UniqueTagList.java @@ -159,5 +159,13 @@ public void setTags(UniqueTagList replacement) { public Iterator iterator() { return internalList.iterator(); } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof UniqueTagList // instanceof handles nulls + && this.internalList.equals( + ((UniqueTagList) other).internalList)); + } } From d6649329c03f5ea7177d86a73d5517453f85db54 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sat, 10 Dec 2016 01:05:05 +0800 Subject: [PATCH 04/23] Add FindCommandTest and CommandTest --- src/seedu/addressbook/commands/Command.java | 2 +- .../addressbook/commands/CommandTest.java | 65 +++++++++++++++++++ .../addressbook/commands/FindCommandTest.java | 55 ++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 test/java/seedu/addressbook/commands/CommandTest.java create mode 100644 test/java/seedu/addressbook/commands/FindCommandTest.java diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index 2e4708de9..67b193409 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -32,7 +32,7 @@ protected Command() { * @param personsDisplayed used to generate summary * @return summary message for persons displayed */ - protected String getMessageForPersonListShownSummary(List personsDisplayed) { + public static String getMessageForPersonListShownSummary(List personsDisplayed) { return String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, personsDisplayed.size()); } diff --git a/test/java/seedu/addressbook/commands/CommandTest.java b/test/java/seedu/addressbook/commands/CommandTest.java new file mode 100644 index 000000000..032d86d16 --- /dev/null +++ b/test/java/seedu/addressbook/commands/CommandTest.java @@ -0,0 +1,65 @@ +package seedu.addressbook.commands; + +import java.util.Collections; +import java.util.List; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertEquals; + +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.ReadOnlyPerson; +import seedu.addressbook.testutil.TestDataHelper; +import seedu.addressbook.testutil.TestMain; + +/** + * Parent class for all commands test + */ +public class CommandTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + protected TestMain testMain; + protected TestDataHelper helper; + + @Before + public void setUp() { + this.testMain = new TestMain(); + this.helper = new TestDataHelper(); + } + + /** + * Executes the command and confirms that the result message is correct. + * Both the 'address book' and the 'last shown list' are expected to be empty. + * @see #assertCommandBehavior(String, String, AddressBook, List) + */ + protected void assertCommandBehavior(String inputCommand, String expectedMessage) throws IllegalValueException { + assertCommandBehavior(inputCommand, expectedMessage, new AddressBook(), Collections.emptyList()); + } + + /** + * Executes the command and confirms that the result message is correct and + * also confirms that the following three parts of the LogicManager object's state are as expected:
+ * - the internal do do bird data are same as those in the {@code expectedAddressBook}
+ * - the backing list shown by UI matches the {@code shownList}
+ * - {@code expectedAddressBook} was saved to the storage file.
+ */ + protected void assertCommandBehavior(String inputCommand, String expectedMessage, + AddressBook expectedAddressBook, + List expectedShownList) throws IllegalValueException { + //Execute the command + CommandResult result = testMain.runCommand(inputCommand); + assertEquals(expectedMessage, result.feedbackToUser); + for (int i = 0; i < expectedShownList.size(); i++) { + assertEquals(expectedShownList.get(i), testMain.getLastShownList().get(i)); + } + + //Confirm the state of data (saved and in-memory) is as expected + assertEquals(expectedAddressBook, testMain.getAddressBook()); + + } +} diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java new file mode 100644 index 000000000..bf77685df --- /dev/null +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -0,0 +1,55 @@ +package seedu.addressbook.commands; + +import java.util.Collections; +import java.util.List; + +import org.junit.Test; + +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.Person; +import seedu.addressbook.testutil.TypicalTestPersons; + +/** + * Test class for the Find Command + */ +public class FindCommandTest extends CommandTest { + + @Test + public void execute_find_isCaseSensitive() throws IllegalValueException { + List expectedOne = helper.generatePersonList(new Person(TypicalTestPersons.claude)); + List expectedZero = Collections.emptyList(); + + assertCommandBehavior("find Claude", + Command.getMessageForPersonListShownSummary(expectedOne), + testMain.getAddressBook(), + expectedOne); + + + assertCommandBehavior("find cLaude", + Command.getMessageForPersonListShownSummary(expectedZero), + testMain.getAddressBook(), + expectedZero); + } + + @Test + public void execute_find_onlyMatchesFullWordsInNames() throws IllegalValueException { + List expectedList = Collections.emptyList(); + + assertCommandBehavior("find Laude", + Command.getMessageForPersonListShownSummary(expectedList), + testMain.getAddressBook(), + expectedList); + } + + @Test + public void execute_find_multipleMatches() throws IllegalValueException { + List expectedList = helper.generatePersonList(new Person(TypicalTestPersons.claude), + new Person(TypicalTestPersons.hopper)); + + assertCommandBehavior("find Claude Hopper", + Command.getMessageForPersonListShownSummary(expectedList), + testMain.getAddressBook(), + expectedList); + } + +} From d40448bb3f655fa53f2907c5b2eeee2972ebaa80 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sat, 10 Dec 2016 01:17:25 +0800 Subject: [PATCH 05/23] Fix code style --- .../addressbook/commands/CommandTest.java | 39 +++++++------ .../addressbook/commands/FindCommandTest.java | 41 +++++-------- .../addressbook/testutil/PersonBuilder.java | 58 +++++++++---------- .../addressbook/testutil/TestPerson.java | 19 +++--- .../testutil/TypicalTestPersons.java | 1 - 5 files changed, 74 insertions(+), 84 deletions(-) diff --git a/test/java/seedu/addressbook/commands/CommandTest.java b/test/java/seedu/addressbook/commands/CommandTest.java index 032d86d16..ae7b45a7e 100644 --- a/test/java/seedu/addressbook/commands/CommandTest.java +++ b/test/java/seedu/addressbook/commands/CommandTest.java @@ -1,40 +1,42 @@ package seedu.addressbook.commands; -import java.util.Collections; -import java.util.List; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Rule; import org.junit.rules.ExpectedException; -import static org.junit.Assert.assertEquals; - import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.testutil.TestDataHelper; import seedu.addressbook.testutil.TestMain; +import java.util.Collections; +import java.util.List; + /** * Parent class for all commands test */ public class CommandTest { - + @Rule public ExpectedException thrown = ExpectedException.none(); - + protected TestMain testMain; protected TestDataHelper helper; - + @Before public void setUp() { this.testMain = new TestMain(); this.helper = new TestDataHelper(); } - + /** * Executes the command and confirms that the result message is correct. - * Both the 'address book' and the 'last shown list' are expected to be empty. + * Both the 'address book' and the 'last shown list' are expected to be + * empty. + * * @see #assertCommandBehavior(String, String, AddressBook, List) */ protected void assertCommandBehavior(String inputCommand, String expectedMessage) throws IllegalValueException { @@ -43,22 +45,23 @@ protected void assertCommandBehavior(String inputCommand, String expectedMessage /** * Executes the command and confirms that the result message is correct and - * also confirms that the following three parts of the LogicManager object's state are as expected:
- * - the internal do do bird data are same as those in the {@code expectedAddressBook}
- * - the backing list shown by UI matches the {@code shownList}
- * - {@code expectedAddressBook} was saved to the storage file.
+ * also confirms that the following three parts of the LogicManager object's + * state are as expected:
+ * - the internal do do bird data are same as those in the + * {@code expectedAddressBook}
+ * - the backing list shown by UI matches the {@code shownList}
+ * - {@code expectedAddressBook} was saved to the storage file.
*/ - protected void assertCommandBehavior(String inputCommand, String expectedMessage, - AddressBook expectedAddressBook, - List expectedShownList) throws IllegalValueException { - //Execute the command + protected void assertCommandBehavior(String inputCommand, String expectedMessage, AddressBook expectedAddressBook, + List expectedShownList) throws IllegalValueException { + // Execute the command CommandResult result = testMain.runCommand(inputCommand); assertEquals(expectedMessage, result.feedbackToUser); for (int i = 0; i < expectedShownList.size(); i++) { assertEquals(expectedShownList.get(i), testMain.getLastShownList().get(i)); } - //Confirm the state of data (saved and in-memory) is as expected + // Confirm the state of data (saved and in-memory) is as expected assertEquals(expectedAddressBook, testMain.getAddressBook()); } diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index bf77685df..893f57fb2 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -18,38 +18,29 @@ public class FindCommandTest extends CommandTest { public void execute_find_isCaseSensitive() throws IllegalValueException { List expectedOne = helper.generatePersonList(new Person(TypicalTestPersons.claude)); List expectedZero = Collections.emptyList(); - - assertCommandBehavior("find Claude", - Command.getMessageForPersonListShownSummary(expectedOne), - testMain.getAddressBook(), - expectedOne); - - - assertCommandBehavior("find cLaude", - Command.getMessageForPersonListShownSummary(expectedZero), - testMain.getAddressBook(), - expectedZero); + + assertCommandBehavior("find Claude", Command.getMessageForPersonListShownSummary(expectedOne), + testMain.getAddressBook(), expectedOne); + + assertCommandBehavior("find cLaude", Command.getMessageForPersonListShownSummary(expectedZero), + testMain.getAddressBook(), expectedZero); } - + @Test public void execute_find_onlyMatchesFullWordsInNames() throws IllegalValueException { List expectedList = Collections.emptyList(); - - assertCommandBehavior("find Laude", - Command.getMessageForPersonListShownSummary(expectedList), - testMain.getAddressBook(), - expectedList); + + assertCommandBehavior("find Laude", Command.getMessageForPersonListShownSummary(expectedList), + testMain.getAddressBook(), expectedList); } - + @Test public void execute_find_multipleMatches() throws IllegalValueException { - List expectedList = helper.generatePersonList(new Person(TypicalTestPersons.claude), + List expectedList = helper.generatePersonList(new Person(TypicalTestPersons.claude), new Person(TypicalTestPersons.hopper)); - - assertCommandBehavior("find Claude Hopper", - Command.getMessageForPersonListShownSummary(expectedList), - testMain.getAddressBook(), - expectedList); + + assertCommandBehavior("find Claude Hopper", Command.getMessageForPersonListShownSummary(expectedList), + testMain.getAddressBook(), expectedList); } - + } diff --git a/test/java/seedu/addressbook/testutil/PersonBuilder.java b/test/java/seedu/addressbook/testutil/PersonBuilder.java index e4dd58f7d..db77aadf6 100644 --- a/test/java/seedu/addressbook/testutil/PersonBuilder.java +++ b/test/java/seedu/addressbook/testutil/PersonBuilder.java @@ -11,33 +11,33 @@ */ public class PersonBuilder { - private TestPerson person; - - public PersonBuilder() { - this.person = new TestPerson(); - } - - public PersonBuilder withName(String name) throws IllegalValueException { - this.person.setName(new Name(name)); - return this; - } - - public PersonBuilder withPhone(String phone, boolean isPrivate) throws IllegalValueException { - this.person.setPhone(new Phone(phone, isPrivate)); - return this; - } - - public PersonBuilder withEmail(String email, boolean isPrivate) throws IllegalValueException { - this.person.setEmail(new Email(email, isPrivate)); - return this; - } - - public PersonBuilder withAddress(String address, boolean isPrivate) throws IllegalValueException { - this.person.setAddress(new Address(address, isPrivate)); - return this; - } - - public TestPerson build() { - return this.person; - } + private TestPerson person; + + public PersonBuilder() { + this.person = new TestPerson(); + } + + public PersonBuilder withName(String name) throws IllegalValueException { + this.person.setName(new Name(name)); + return this; + } + + public PersonBuilder withPhone(String phone, boolean isPrivate) throws IllegalValueException { + this.person.setPhone(new Phone(phone, isPrivate)); + return this; + } + + public PersonBuilder withEmail(String email, boolean isPrivate) throws IllegalValueException { + this.person.setEmail(new Email(email, isPrivate)); + return this; + } + + public PersonBuilder withAddress(String address, boolean isPrivate) throws IllegalValueException { + this.person.setAddress(new Address(address, isPrivate)); + return this; + } + + public TestPerson build() { + return this.person; + } } diff --git a/test/java/seedu/addressbook/testutil/TestPerson.java b/test/java/seedu/addressbook/testutil/TestPerson.java index f0fca0e1d..0678ae6b1 100644 --- a/test/java/seedu/addressbook/testutil/TestPerson.java +++ b/test/java/seedu/addressbook/testutil/TestPerson.java @@ -8,18 +8,18 @@ import seedu.addressbook.data.tag.UniqueTagList; public class TestPerson implements ReadOnlyPerson { - - private Name name; + + private Name name; private Phone phone; private Email email; private Address address; - + private final UniqueTagList tags; - + public TestPerson() { - tags = new UniqueTagList(); + tags = new UniqueTagList(); } - + public Name getName() { return name; } @@ -35,7 +35,7 @@ public Email getEmail() { public Address getAddress() { return address; } - + public void setName(Name name) { this.name = name; } @@ -51,12 +51,9 @@ public void setEmail(Email email) { public void setAddress(Address address) { this.address = address; } - public UniqueTagList getTags() { return new UniqueTagList(tags); } - - - + } diff --git a/test/java/seedu/addressbook/testutil/TypicalTestPersons.java b/test/java/seedu/addressbook/testutil/TypicalTestPersons.java index 286936d6d..6be133ee5 100644 --- a/test/java/seedu/addressbook/testutil/TypicalTestPersons.java +++ b/test/java/seedu/addressbook/testutil/TypicalTestPersons.java @@ -49,7 +49,6 @@ public TestPerson[] getTypicalPersons() { return new TestPerson[] { claude, gates, jobs, donald, hopper }; } - public AddressBook getTypicalAddressBook() { AddressBook ab = new AddressBook(); loadAddressBookWithSampleData(ab); From 16800118b15cd8f0678487d01f029552d5dcc32e Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sat, 10 Dec 2016 22:44:01 +0800 Subject: [PATCH 06/23] Add indentation for equals() method --- src/seedu/addressbook/data/AddressBook.java | 4 +- .../data/person/UniquePersonList.java | 3 +- .../addressbook/data/tag/UniqueTagList.java | 3 +- .../addressbook/commands/CommandTest.java | 68 ------------------- .../addressbook/testutil/TestDataHelper.java | 17 ----- .../seedu/addressbook/testutil/TestMain.java | 67 ------------------ .../{testutil => util}/PersonBuilder.java | 0 .../{testutil => util}/TestPerson.java | 0 .../TypicalTestPersons.java | 0 9 files changed, 4 insertions(+), 158 deletions(-) delete mode 100644 test/java/seedu/addressbook/commands/CommandTest.java delete mode 100644 test/java/seedu/addressbook/testutil/TestDataHelper.java delete mode 100644 test/java/seedu/addressbook/testutil/TestMain.java rename test/java/seedu/addressbook/{testutil => util}/PersonBuilder.java (100%) rename test/java/seedu/addressbook/{testutil => util}/TestPerson.java (100%) rename test/java/seedu/addressbook/{testutil => util}/TypicalTestPersons.java (100%) diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index e71e12ee5..e3e4356d4 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -148,7 +148,7 @@ public UniqueTagList getAllTags() { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof AddressBook // instanceof handles nulls - && this.allPersons.equals(((AddressBook) other).allPersons) - && this.allTags.equals(((AddressBook) other).allTags)); + && this.allPersons.equals(((AddressBook) other).allPersons) + && this.allTags.equals(((AddressBook) other).allTags)); } } diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index ddda8becf..54cbb1978 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -129,8 +129,7 @@ public Iterator iterator() { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof UniquePersonList // instanceof handles nulls - && this.internalList.equals( - ((UniquePersonList) other).internalList)); + && this.internalList.equals(((UniquePersonList) other).internalList)); } @Override diff --git a/src/seedu/addressbook/data/tag/UniqueTagList.java b/src/seedu/addressbook/data/tag/UniqueTagList.java index f63d0b913..7e2509f51 100644 --- a/src/seedu/addressbook/data/tag/UniqueTagList.java +++ b/src/seedu/addressbook/data/tag/UniqueTagList.java @@ -164,8 +164,7 @@ public Iterator iterator() { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof UniqueTagList // instanceof handles nulls - && this.internalList.equals( - ((UniqueTagList) other).internalList)); + && this.internalList.equals(((UniqueTagList) other).internalList)); } } diff --git a/test/java/seedu/addressbook/commands/CommandTest.java b/test/java/seedu/addressbook/commands/CommandTest.java deleted file mode 100644 index ae7b45a7e..000000000 --- a/test/java/seedu/addressbook/commands/CommandTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package seedu.addressbook.commands; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.ExpectedException; - -import seedu.addressbook.data.AddressBook; -import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.person.ReadOnlyPerson; -import seedu.addressbook.testutil.TestDataHelper; -import seedu.addressbook.testutil.TestMain; - -import java.util.Collections; -import java.util.List; - -/** - * Parent class for all commands test - */ -public class CommandTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - protected TestMain testMain; - protected TestDataHelper helper; - - @Before - public void setUp() { - this.testMain = new TestMain(); - this.helper = new TestDataHelper(); - } - - /** - * Executes the command and confirms that the result message is correct. - * Both the 'address book' and the 'last shown list' are expected to be - * empty. - * - * @see #assertCommandBehavior(String, String, AddressBook, List) - */ - protected void assertCommandBehavior(String inputCommand, String expectedMessage) throws IllegalValueException { - assertCommandBehavior(inputCommand, expectedMessage, new AddressBook(), Collections.emptyList()); - } - - /** - * Executes the command and confirms that the result message is correct and - * also confirms that the following three parts of the LogicManager object's - * state are as expected:
- * - the internal do do bird data are same as those in the - * {@code expectedAddressBook}
- * - the backing list shown by UI matches the {@code shownList}
- * - {@code expectedAddressBook} was saved to the storage file.
- */ - protected void assertCommandBehavior(String inputCommand, String expectedMessage, AddressBook expectedAddressBook, - List expectedShownList) throws IllegalValueException { - // Execute the command - CommandResult result = testMain.runCommand(inputCommand); - assertEquals(expectedMessage, result.feedbackToUser); - for (int i = 0; i < expectedShownList.size(); i++) { - assertEquals(expectedShownList.get(i), testMain.getLastShownList().get(i)); - } - - // Confirm the state of data (saved and in-memory) is as expected - assertEquals(expectedAddressBook, testMain.getAddressBook()); - - } -} diff --git a/test/java/seedu/addressbook/testutil/TestDataHelper.java b/test/java/seedu/addressbook/testutil/TestDataHelper.java deleted file mode 100644 index 8d15358e0..000000000 --- a/test/java/seedu/addressbook/testutil/TestDataHelper.java +++ /dev/null @@ -1,17 +0,0 @@ -package seedu.addressbook.testutil; - -import java.util.Arrays; -import java.util.List; - -import seedu.addressbook.data.person.Person; - -/** - * A utility class to generate test data. - */ -public class TestDataHelper { - - public List generatePersonList(Person... persons) { - return Arrays.asList(persons); - } - -} diff --git a/test/java/seedu/addressbook/testutil/TestMain.java b/test/java/seedu/addressbook/testutil/TestMain.java deleted file mode 100644 index 3ad18f096..000000000 --- a/test/java/seedu/addressbook/testutil/TestMain.java +++ /dev/null @@ -1,67 +0,0 @@ -package seedu.addressbook.testutil; -import seedu.addressbook.data.person.ReadOnlyPerson; - -import seedu.addressbook.commands.*; -import seedu.addressbook.data.AddressBook; -import seedu.addressbook.parser.Parser; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -/** - * Test class for Main - */ -public class TestMain { - - private AddressBook addressBook; - - /** The list of person shown to the user most recently. */ - private List lastShownList = Collections.emptyList(); - - public TestMain() { - this.addressBook = new TypicalTestPersons().getTypicalAddressBook(); - } - - public List getLastShownList() { - return this.lastShownList; - } - - public AddressBook getAddressBook() { - return this.addressBook; - } - - /** Reads the user command and executes it */ - public CommandResult runCommand(String inputCommand) { - Command command = new Parser().parseCommand(inputCommand); - CommandResult result = executeCommand(command); - recordResult(result); - return result; - } - - /** Updates the {@link #lastShownList} if the result contains a list of Persons. */ - private void recordResult(CommandResult result) { - final Optional> personList = result.getRelevantPersons(); - if (personList.isPresent()) { - lastShownList = personList.get(); - } - } - - /** - * Executes the command and returns the result. - * - * @param command user command - * @return result of the command - */ - private CommandResult executeCommand(Command command) { - try { - command.setData(addressBook, lastShownList); - CommandResult result = command.execute(); - return result; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - -} diff --git a/test/java/seedu/addressbook/testutil/PersonBuilder.java b/test/java/seedu/addressbook/util/PersonBuilder.java similarity index 100% rename from test/java/seedu/addressbook/testutil/PersonBuilder.java rename to test/java/seedu/addressbook/util/PersonBuilder.java diff --git a/test/java/seedu/addressbook/testutil/TestPerson.java b/test/java/seedu/addressbook/util/TestPerson.java similarity index 100% rename from test/java/seedu/addressbook/testutil/TestPerson.java rename to test/java/seedu/addressbook/util/TestPerson.java diff --git a/test/java/seedu/addressbook/testutil/TypicalTestPersons.java b/test/java/seedu/addressbook/util/TypicalTestPersons.java similarity index 100% rename from test/java/seedu/addressbook/testutil/TypicalTestPersons.java rename to test/java/seedu/addressbook/util/TypicalTestPersons.java From ba2d41df977ffe8530cd77f52689db23a7391651 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sat, 10 Dec 2016 22:45:51 +0800 Subject: [PATCH 07/23] Reimplement FindCommandTest without use of TestMain --- .../addressbook/commands/FindCommandTest.java | 95 +++++++++++++++---- .../seedu/addressbook/util/PersonBuilder.java | 29 ++++-- .../seedu/addressbook/util/TestPerson.java | 2 +- .../addressbook/util/TypicalTestPersons.java | 26 ++--- 4 files changed, 114 insertions(+), 38 deletions(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 893f57fb2..6a5e12cf0 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -1,46 +1,107 @@ package seedu.addressbook.commands; +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.Person; -import seedu.addressbook.testutil.TypicalTestPersons; +import seedu.addressbook.data.person.ReadOnlyPerson; +import seedu.addressbook.util.TestUtil; +import seedu.addressbook.util.TypicalTestPersons; /** * Test class for the Find Command */ -public class FindCommandTest extends CommandTest { +public class FindCommandTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private AddressBook addressBook; + private AddressBook unmutatedAddressBook; + + @Before public void setUp() { + this.addressBook = new TypicalTestPersons().getTypicalAddressBook(); + this.unmutatedAddressBook = new TypicalTestPersons().getTypicalAddressBook(); + } @Test - public void execute_find_isCaseSensitive() throws IllegalValueException { - List expectedOne = helper.generatePersonList(new Person(TypicalTestPersons.claude)); - List expectedZero = Collections.emptyList(); + public void execute_find_matchesOnlyIfCaseSensitive() throws IllegalValueException { + List expectedOne = TestUtil.createList(new Person(TypicalTestPersons.amy)); + List expectedZero = Collections.emptyList(); + + String[] caseSensitiveKeywords = {"Amy"}; + String[] caseInsensitiveKeywords = {"aMy"}; + + FindCommand command = createFindCommand(caseSensitiveKeywords); + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedOne), + unmutatedAddressBook, addressBook); + + command = createFindCommand(caseInsensitiveKeywords); + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedZero), + unmutatedAddressBook, addressBook); - assertCommandBehavior("find Claude", Command.getMessageForPersonListShownSummary(expectedOne), - testMain.getAddressBook(), expectedOne); - assertCommandBehavior("find cLaude", Command.getMessageForPersonListShownSummary(expectedZero), - testMain.getAddressBook(), expectedZero); } @Test - public void execute_find_onlyMatchesFullWordsInNames() throws IllegalValueException { - List expectedList = Collections.emptyList(); + public void execute_find_matchesOnlyFullWordsInNames() throws IllegalValueException { + List expectedZero = Collections.emptyList(); + + String[] keywords = {"my"}; + + FindCommand command = createFindCommand(keywords); + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedZero), + unmutatedAddressBook, addressBook); - assertCommandBehavior("find Laude", Command.getMessageForPersonListShownSummary(expectedList), - testMain.getAddressBook(), expectedList); } @Test public void execute_find_multipleMatches() throws IllegalValueException { - List expectedList = helper.generatePersonList(new Person(TypicalTestPersons.claude), - new Person(TypicalTestPersons.hopper)); + List expectedTwo = TestUtil.createList(new Person(TypicalTestPersons.amy), + new Person(TypicalTestPersons.bill)); + + String[] keywords = {"Amy", "Bill"}; + + FindCommand command = createFindCommand(keywords); + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedTwo), + unmutatedAddressBook, addressBook); - assertCommandBehavior("find Claude Hopper", Command.getMessageForPersonListShownSummary(expectedList), - testMain.getAddressBook(), expectedList); } + /** + * Executes the find command, and checks that the execution was what we had expected. + */ + private void assertCommandBehavior(Command command, String expectedMessage, + AddressBook expectedAddressBook, AddressBook actualAddressBook) { + + CommandResult result = command.execute(); + + assertEquals(expectedMessage, result.feedbackToUser); + assertEquals(expectedAddressBook, actualAddressBook); + } + + + /** + * Creates a new find command. + * + * @param keywords to search for in the names' of persons + */ + private FindCommand createFindCommand(String[] keywords) { + final Set keywordSet = new HashSet<>(Arrays.asList(keywords)); + FindCommand command = new FindCommand(keywordSet); + command.setData(addressBook, Collections.emptyList()); + return command; + } } diff --git a/test/java/seedu/addressbook/util/PersonBuilder.java b/test/java/seedu/addressbook/util/PersonBuilder.java index db77aadf6..c56050e97 100644 --- a/test/java/seedu/addressbook/util/PersonBuilder.java +++ b/test/java/seedu/addressbook/util/PersonBuilder.java @@ -1,4 +1,4 @@ -package seedu.addressbook.testutil; +package seedu.addressbook.util; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.Address; @@ -21,19 +21,34 @@ public PersonBuilder withName(String name) throws IllegalValueException { this.person.setName(new Name(name)); return this; } + + public PersonBuilder withPrivatePhone(String phone) throws IllegalValueException { + this.person.setPhone(new Phone(phone, true)); + return this; + } + + public PersonBuilder withPublicPhone(String phone) throws IllegalValueException { + this.person.setPhone(new Phone(phone, false)); + return this; + } - public PersonBuilder withPhone(String phone, boolean isPrivate) throws IllegalValueException { - this.person.setPhone(new Phone(phone, isPrivate)); + public PersonBuilder withPrivateEmail(String email) throws IllegalValueException { + this.person.setEmail(new Email(email, true)); return this; } - public PersonBuilder withEmail(String email, boolean isPrivate) throws IllegalValueException { - this.person.setEmail(new Email(email, isPrivate)); + public PersonBuilder withPublicEmail(String email) throws IllegalValueException { + this.person.setEmail(new Email(email, false)); + return this; + } + + public PersonBuilder withPrivateAddress(String address) throws IllegalValueException { + this.person.setAddress(new Address(address, true)); return this; } - public PersonBuilder withAddress(String address, boolean isPrivate) throws IllegalValueException { - this.person.setAddress(new Address(address, isPrivate)); + public PersonBuilder withPublicAddress(String address) throws IllegalValueException { + this.person.setAddress(new Address(address, false)); return this; } diff --git a/test/java/seedu/addressbook/util/TestPerson.java b/test/java/seedu/addressbook/util/TestPerson.java index 0678ae6b1..c4df564b0 100644 --- a/test/java/seedu/addressbook/util/TestPerson.java +++ b/test/java/seedu/addressbook/util/TestPerson.java @@ -1,4 +1,4 @@ -package seedu.addressbook.testutil; +package seedu.addressbook.util; import seedu.addressbook.data.person.Address; import seedu.addressbook.data.person.Email; diff --git a/test/java/seedu/addressbook/util/TypicalTestPersons.java b/test/java/seedu/addressbook/util/TypicalTestPersons.java index 6be133ee5..ce76150a9 100644 --- a/test/java/seedu/addressbook/util/TypicalTestPersons.java +++ b/test/java/seedu/addressbook/util/TypicalTestPersons.java @@ -1,4 +1,4 @@ -package seedu.addressbook.testutil; +package seedu.addressbook.util; import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; @@ -10,24 +10,24 @@ */ public class TypicalTestPersons { - public static TestPerson claude, gates, jobs, donald, hopper; + public static TestPerson amy, bill, candy, donald, grace; public TypicalTestPersons() { try { - claude = new PersonBuilder().withName("Claude Shannon").withPhone("91234567", false) - .withEmail("cs@gmail.com", false).withAddress("1 Clementi Road", true).build(); + amy = new PersonBuilder().withName("Amy Buck").withPublicPhone("91234567") + .withPublicEmail("cs@gmail.com").withPublicAddress("1 Clementi Road").build(); - gates = new PersonBuilder().withName("Bill Gates").withPhone("92434567", false) - .withEmail("bg@gmail.com", false).withAddress("2 Clementi Road", false).build(); + bill = new PersonBuilder().withName("Bill Clint").withPublicPhone("92434567") + .withPublicEmail("bg@gmail.com").withPrivateAddress("2 Clementi Road").build(); - jobs = new PersonBuilder().withName("Steve Jobs").withPhone("91934267", true) - .withEmail("sj@gmail.com", true).withAddress("3 Clementi Road", false).build(); + candy = new PersonBuilder().withName("Candy Destiny").withPrivatePhone("91934267") + .withPublicEmail("sj@gmail.com").withPublicAddress("3 Clementi Road").build(); - donald = new PersonBuilder().withName("Donald Knuth").withPhone("91214567", true) - .withEmail("dk@gmail.com", false).withAddress("4 Clementi Road", true).build(); + donald = new PersonBuilder().withName("Donald Eillot").withPrivatePhone("91214567") + .withPrivateEmail("dk@gmail.com").withPublicAddress("4 Clementi Road").build(); - hopper = new PersonBuilder().withName("Grace Hopper").withPhone("83434567", true) - .withEmail("gh@gmail.com", true).withAddress("5 Clementi Road", true).build(); + grace = new PersonBuilder().withName("Grace Hopper").withPublicPhone("83434567") + .withPrivateEmail("gh@gmail.com").withPrivateAddress("5 Clementi Road").build(); } catch (IllegalValueException e) { e.printStackTrace(); @@ -46,7 +46,7 @@ public void loadAddressBookWithSampleData(AddressBook ab) { } public TestPerson[] getTypicalPersons() { - return new TestPerson[] { claude, gates, jobs, donald, hopper }; + return new TestPerson[] {amy, bill, candy, donald, grace}; } public AddressBook getTypicalAddressBook() { From 4fe6e4dc5ad757f829a62f71d0e60ad7daf2dce8 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 11 Dec 2016 12:04:46 +0800 Subject: [PATCH 08/23] Remove duplicate equals() method in UniquePersonList --- src/seedu/addressbook/data/person/UniquePersonList.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index 54cbb1978..1db335783 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -132,10 +132,4 @@ public boolean equals(Object other) { && this.internalList.equals(((UniquePersonList) other).internalList)); } - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof UniquePersonList // instanceof handles nulls - && this.internalList.equals(((UniquePersonList) other).internalList)); - } } From cb7db6900ba765dbfdf055c92c919cec151372cb Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 11 Dec 2016 18:34:06 +0800 Subject: [PATCH 09/23] Remove TestPerson class --- .../seedu/addressbook/util/PersonBuilder.java | 32 ++++++---- .../seedu/addressbook/util/TestPerson.java | 59 ------------------- .../addressbook/util/TypicalTestPersons.java | 26 ++++---- 3 files changed, 34 insertions(+), 83 deletions(-) delete mode 100644 test/java/seedu/addressbook/util/TestPerson.java diff --git a/test/java/seedu/addressbook/util/PersonBuilder.java b/test/java/seedu/addressbook/util/PersonBuilder.java index c56050e97..076ec1a23 100644 --- a/test/java/seedu/addressbook/util/PersonBuilder.java +++ b/test/java/seedu/addressbook/util/PersonBuilder.java @@ -1,58 +1,68 @@ package seedu.addressbook.util; +import seedu.addressbook.common.Utils; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.Address; import seedu.addressbook.data.person.Email; import seedu.addressbook.data.person.Name; +import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.Phone; +import seedu.addressbook.data.tag.UniqueTagList; /** * Factory class for building TestPerson */ public class PersonBuilder { - private TestPerson person; + private Name name; + private Phone phone; + private Email email; + private Address address; public PersonBuilder() { - this.person = new TestPerson(); + this.name = null; + this.phone = null; + this.email = null; + this.address = null; } public PersonBuilder withName(String name) throws IllegalValueException { - this.person.setName(new Name(name)); + this.name = new Name(name); return this; } public PersonBuilder withPrivatePhone(String phone) throws IllegalValueException { - this.person.setPhone(new Phone(phone, true)); + this.phone = new Phone(phone, true); return this; } public PersonBuilder withPublicPhone(String phone) throws IllegalValueException { - this.person.setPhone(new Phone(phone, false)); + this.phone = new Phone(phone, false); return this; } public PersonBuilder withPrivateEmail(String email) throws IllegalValueException { - this.person.setEmail(new Email(email, true)); + this.email = new Email(email, true); return this; } public PersonBuilder withPublicEmail(String email) throws IllegalValueException { - this.person.setEmail(new Email(email, false)); + this.email = new Email(email, false); return this; } public PersonBuilder withPrivateAddress(String address) throws IllegalValueException { - this.person.setAddress(new Address(address, true)); + this.address = new Address(address, true); return this; } public PersonBuilder withPublicAddress(String address) throws IllegalValueException { - this.person.setAddress(new Address(address, false)); + this.address = new Address(address, false); return this; } - public TestPerson build() { - return this.person; + public Person build() { + assert !Utils.isAnyNull(this.name, this.phone, this.email, this.address); + return new Person(this.name, this.phone, this.email, this.address, new UniqueTagList()); } } diff --git a/test/java/seedu/addressbook/util/TestPerson.java b/test/java/seedu/addressbook/util/TestPerson.java deleted file mode 100644 index c4df564b0..000000000 --- a/test/java/seedu/addressbook/util/TestPerson.java +++ /dev/null @@ -1,59 +0,0 @@ -package seedu.addressbook.util; - -import seedu.addressbook.data.person.Address; -import seedu.addressbook.data.person.Email; -import seedu.addressbook.data.person.Name; -import seedu.addressbook.data.person.Phone; -import seedu.addressbook.data.person.ReadOnlyPerson; -import seedu.addressbook.data.tag.UniqueTagList; - -public class TestPerson implements ReadOnlyPerson { - - private Name name; - private Phone phone; - private Email email; - private Address address; - - private final UniqueTagList tags; - - public TestPerson() { - tags = new UniqueTagList(); - } - - public Name getName() { - return name; - } - - public Phone getPhone() { - return phone; - } - - public Email getEmail() { - return email; - } - - public Address getAddress() { - return address; - } - - public void setName(Name name) { - this.name = name; - } - - public void setPhone(Phone phone) { - this.phone = phone; - } - - public void setEmail(Email email) { - this.email = email; - } - - public void setAddress(Address address) { - this.address = address; - } - - public UniqueTagList getTags() { - return new UniqueTagList(tags); - } - -} diff --git a/test/java/seedu/addressbook/util/TypicalTestPersons.java b/test/java/seedu/addressbook/util/TypicalTestPersons.java index ce76150a9..48e92b5bc 100644 --- a/test/java/seedu/addressbook/util/TypicalTestPersons.java +++ b/test/java/seedu/addressbook/util/TypicalTestPersons.java @@ -10,23 +10,23 @@ */ public class TypicalTestPersons { - public static TestPerson amy, bill, candy, donald, grace; + public static Person amy, bill, candy, donald, grace; public TypicalTestPersons() { try { - amy = new PersonBuilder().withName("Amy Buck").withPublicPhone("91234567") - .withPublicEmail("cs@gmail.com").withPublicAddress("1 Clementi Road").build(); + amy = new PersonBuilder().withName("Amy Buck").withPublicPhone("91119111") + .withPublicEmail("ab@gmail.com").withPublicAddress("1 Clementi Road").build(); - bill = new PersonBuilder().withName("Bill Clint").withPublicPhone("92434567") - .withPublicEmail("bg@gmail.com").withPrivateAddress("2 Clementi Road").build(); + bill = new PersonBuilder().withName("Bill Clint").withPublicPhone("92229222") + .withPublicEmail("bc@gmail.com").withPrivateAddress("2 Clementi Road").build(); - candy = new PersonBuilder().withName("Candy Destiny").withPrivatePhone("91934267") - .withPublicEmail("sj@gmail.com").withPublicAddress("3 Clementi Road").build(); + candy = new PersonBuilder().withName("Candy Destiny").withPrivatePhone("93339333") + .withPublicEmail("cd@gmail.com").withPublicAddress("3 Clementi Road").build(); - donald = new PersonBuilder().withName("Donald Eillot").withPrivatePhone("91214567") - .withPrivateEmail("dk@gmail.com").withPublicAddress("4 Clementi Road").build(); + donald = new PersonBuilder().withName("Donald Eillot").withPrivatePhone("94449444") + .withPrivateEmail("de@gmail.com").withPublicAddress("4 Clementi Road").build(); - grace = new PersonBuilder().withName("Grace Hopper").withPublicPhone("83434567") + grace = new PersonBuilder().withName("Grace Hopper").withPublicPhone("95559555") .withPrivateEmail("gh@gmail.com").withPrivateAddress("5 Clementi Road").build(); } catch (IllegalValueException e) { @@ -37,7 +37,7 @@ public TypicalTestPersons() { public void loadAddressBookWithSampleData(AddressBook ab) { try { - for (TestPerson t : getTypicalPersons()) { + for (Person t : getTypicalPersons()) { ab.addPerson(new Person(t)); } } catch (UniquePersonList.DuplicatePersonException e) { @@ -45,8 +45,8 @@ public void loadAddressBookWithSampleData(AddressBook ab) { } } - public TestPerson[] getTypicalPersons() { - return new TestPerson[] {amy, bill, candy, donald, grace}; + public Person[] getTypicalPersons() { + return new Person[] {amy, bill, candy, donald, grace}; } public AddressBook getTypicalAddressBook() { From 3d247be98c41d39bcbea256045731c527a38ff5e Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 11 Dec 2016 18:40:00 +0800 Subject: [PATCH 10/23] Refactor FindCommandTest --- .../addressbook/commands/FindCommandTest.java | 47 ++++++++++--------- ...alTestPersons.java => TypicalPersons.java} | 4 +- 2 files changed, 27 insertions(+), 24 deletions(-) rename test/java/seedu/addressbook/util/{TypicalTestPersons.java => TypicalPersons.java} (96%) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 6a5e12cf0..b54ea976b 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -18,7 +18,7 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.util.TestUtil; -import seedu.addressbook.util.TypicalTestPersons; +import seedu.addressbook.util.TypicalPersons; /** * Test class for the Find Command @@ -32,52 +32,55 @@ public class FindCommandTest { private AddressBook unmutatedAddressBook; @Before public void setUp() { - this.addressBook = new TypicalTestPersons().getTypicalAddressBook(); - this.unmutatedAddressBook = new TypicalTestPersons().getTypicalAddressBook(); + this.addressBook = new TypicalPersons().getTypicalAddressBook(); + this.unmutatedAddressBook = new TypicalPersons().getTypicalAddressBook(); } @Test - public void execute_find_matchesOnlyIfCaseSensitive() throws IllegalValueException { - List expectedOne = TestUtil.createList(new Person(TypicalTestPersons.amy)); - List expectedZero = Collections.emptyList(); - - String[] caseSensitiveKeywords = {"Amy"}; - String[] caseInsensitiveKeywords = {"aMy"}; + public void execute_sameWordSameCase_matched() throws IllegalValueException { + List expected = TestUtil.createList(new Person(TypicalPersons.amy)); + + String[] keywordsWithMatchingCase = {"Amy"}; - FindCommand command = createFindCommand(caseSensitiveKeywords); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedOne), + FindCommand command = createFindCommand(keywordsWithMatchingCase); + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), unmutatedAddressBook, addressBook); + } + + @Test + public void execute_sameWordDifferentCase_notMatched() throws IllegalValueException { + List expected = Collections.emptyList(); + + String[] keywordsWithNonMatchingCase = {"aMy"}; - command = createFindCommand(caseInsensitiveKeywords); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedZero), + FindCommand command = createFindCommand(keywordsWithNonMatchingCase); + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), unmutatedAddressBook, addressBook); - - } + + @Test public void execute_find_matchesOnlyFullWordsInNames() throws IllegalValueException { - List expectedZero = Collections.emptyList(); + List expected = Collections.emptyList(); String[] keywords = {"my"}; FindCommand command = createFindCommand(keywords); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedZero), + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), unmutatedAddressBook, addressBook); - } @Test public void execute_find_multipleMatches() throws IllegalValueException { - List expectedTwo = TestUtil.createList(new Person(TypicalTestPersons.amy), - new Person(TypicalTestPersons.bill)); + List expected = TestUtil.createList(new Person(TypicalPersons.amy), + new Person(TypicalPersons.bill)); String[] keywords = {"Amy", "Bill"}; FindCommand command = createFindCommand(keywords); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expectedTwo), + assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), unmutatedAddressBook, addressBook); - } /** diff --git a/test/java/seedu/addressbook/util/TypicalTestPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java similarity index 96% rename from test/java/seedu/addressbook/util/TypicalTestPersons.java rename to test/java/seedu/addressbook/util/TypicalPersons.java index 48e92b5bc..cd5be8596 100644 --- a/test/java/seedu/addressbook/util/TypicalTestPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -8,11 +8,11 @@ /** * Class to generate typical test persons */ -public class TypicalTestPersons { +public class TypicalPersons { public static Person amy, bill, candy, donald, grace; - public TypicalTestPersons() { + public TypicalPersons() { try { amy = new PersonBuilder().withName("Amy Buck").withPublicPhone("91119111") .withPublicEmail("ab@gmail.com").withPublicAddress("1 Clementi Road").build(); From 4ab716327aa98c1cdd1c6787410e10686e112316 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 11 Dec 2016 22:43:57 +0800 Subject: [PATCH 11/23] Refactor FindCommandTest --- .../data/person/UniquePersonList.java | 2 +- .../addressbook/commands/FindCommandTest.java | 27 +++++-------------- .../addressbook/util/TypicalPersons.java | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index 1db335783..47ede54a3 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -124,7 +124,7 @@ public void clear() { public Iterator iterator() { return internalList.iterator(); } - + @Override public boolean equals(Object other) { return other == this // short circuit if same object diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index b54ea976b..0867acdba 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -9,9 +9,7 @@ import java.util.Set; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; @@ -25,9 +23,6 @@ */ public class FindCommandTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private AddressBook addressBook; private AddressBook unmutatedAddressBook; @@ -44,7 +39,7 @@ public void execute_sameWordSameCase_matched() throws IllegalValueException { FindCommand command = createFindCommand(keywordsWithMatchingCase); assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + unmutatedAddressBook, addressBook); } @Test @@ -55,32 +50,30 @@ public void execute_sameWordDifferentCase_notMatched() throws IllegalValueExcept FindCommand command = createFindCommand(keywordsWithNonMatchingCase); assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + unmutatedAddressBook, addressBook); } - - @Test - public void execute_find_matchesOnlyFullWordsInNames() throws IllegalValueException { + public void execute_partialKeyword_notMatched() throws IllegalValueException { List expected = Collections.emptyList(); String[] keywords = {"my"}; FindCommand command = createFindCommand(keywords); assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + unmutatedAddressBook, addressBook); } @Test - public void execute_find_multipleMatches() throws IllegalValueException { + public void execute_multipleKeywords_matched() throws IllegalValueException { List expected = TestUtil.createList(new Person(TypicalPersons.amy), - new Person(TypicalPersons.bill)); + new Person(TypicalPersons.bill)); String[] keywords = {"Amy", "Bill"}; FindCommand command = createFindCommand(keywords); assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + unmutatedAddressBook, addressBook); } /** @@ -95,12 +88,6 @@ private void assertCommandBehavior(Command command, String expectedMessage, assertEquals(expectedAddressBook, actualAddressBook); } - - /** - * Creates a new find command. - * - * @param keywords to search for in the names' of persons - */ private FindCommand createFindCommand(String[] keywords) { final Set keywordSet = new HashSet<>(Arrays.asList(keywords)); FindCommand command = new FindCommand(keywordSet); diff --git a/test/java/seedu/addressbook/util/TypicalPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java index cd5be8596..56280a5bd 100644 --- a/test/java/seedu/addressbook/util/TypicalPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -35,7 +35,7 @@ public TypicalPersons() { } } - public void loadAddressBookWithSampleData(AddressBook ab) { + private void loadAddressBookWithSampleData(AddressBook ab) { try { for (Person t : getTypicalPersons()) { ab.addPerson(new Person(t)); From acc592766a9486a9061da4e28740b511d158653a Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 18 Dec 2016 13:11:54 +0800 Subject: [PATCH 12/23] Refactor FindCommandTest --- .../addressbook/commands/FindCommandTest.java | 37 ++++++++----------- .../addressbook/util/TypicalPersons.java | 4 +- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 0867acdba..d0d0be692 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -24,11 +24,11 @@ public class FindCommandTest { private AddressBook addressBook; - private AddressBook unmutatedAddressBook; + + private final List EMPTY_LIST = Collections.emptyList(); @Before public void setUp() { this.addressBook = new TypicalPersons().getTypicalAddressBook(); - this.unmutatedAddressBook = new TypicalPersons().getTypicalAddressBook(); } @Test @@ -38,53 +38,46 @@ public void execute_sameWordSameCase_matched() throws IllegalValueException { String[] keywordsWithMatchingCase = {"Amy"}; FindCommand command = createFindCommand(keywordsWithMatchingCase); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + assertCommandBehavior(command, expected, addressBook); } @Test public void execute_sameWordDifferentCase_notMatched() throws IllegalValueException { - List expected = Collections.emptyList(); - String[] keywordsWithNonMatchingCase = {"aMy"}; FindCommand command = createFindCommand(keywordsWithNonMatchingCase); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + assertCommandBehavior(command, EMPTY_LIST, addressBook); } @Test - public void execute_partialKeyword_notMatched() throws IllegalValueException { - List expected = Collections.emptyList(); - + public void execute_partialKeyword_notMatched() throws IllegalValueException { String[] keywords = {"my"}; FindCommand command = createFindCommand(keywords); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + assertCommandBehavior(command, EMPTY_LIST, addressBook); } - + @Test public void execute_multipleKeywords_matched() throws IllegalValueException { List expected = TestUtil.createList(new Person(TypicalPersons.amy), - new Person(TypicalPersons.bill)); + new Person(TypicalPersons.bill), + new Person(TypicalPersons.candy)); - String[] keywords = {"Amy", "Bill"}; + String[] keywords = {"Amy", "Bill", "Destiny"}; FindCommand command = createFindCommand(keywords); - assertCommandBehavior(command, Command.getMessageForPersonListShownSummary(expected), - unmutatedAddressBook, addressBook); + assertCommandBehavior(command, expected, addressBook); } /** * Executes the find command, and checks that the execution was what we had expected. */ - private void assertCommandBehavior(Command command, String expectedMessage, - AddressBook expectedAddressBook, AddressBook actualAddressBook) { - + private void assertCommandBehavior(Command command, List expectedPersonList, AddressBook actualAddressBook) { + CommandResult result = command.execute(); + AddressBook expectedAddressBook = new TypicalPersons().getTypicalAddressBook(); - assertEquals(expectedMessage, result.feedbackToUser); + assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser); assertEquals(expectedAddressBook, actualAddressBook); } diff --git a/test/java/seedu/addressbook/util/TypicalPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java index 56280a5bd..4d87de812 100644 --- a/test/java/seedu/addressbook/util/TypicalPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -37,8 +37,8 @@ public TypicalPersons() { private void loadAddressBookWithSampleData(AddressBook ab) { try { - for (Person t : getTypicalPersons()) { - ab.addPerson(new Person(t)); + for (Person p : getTypicalPersons()) { + ab.addPerson(new Person(p)); } } catch (UniquePersonList.DuplicatePersonException e) { assert false : "not possible"; From 6793926c9c0073ce19da10f501df57a4f2987fb2 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 18 Dec 2016 13:17:31 +0800 Subject: [PATCH 13/23] Remove empty line at top of assertCommandBehavior --- test/java/seedu/addressbook/commands/FindCommandTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index d0d0be692..b8fe51d79 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -73,7 +73,6 @@ public void execute_multipleKeywords_matched() throws IllegalValueException { * Executes the find command, and checks that the execution was what we had expected. */ private void assertCommandBehavior(Command command, List expectedPersonList, AddressBook actualAddressBook) { - CommandResult result = command.execute(); AddressBook expectedAddressBook = new TypicalPersons().getTypicalAddressBook(); From a90bdb73de70543336aaeeaa77fef50fffb2202e Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 25 Dec 2016 21:14:30 +0800 Subject: [PATCH 14/23] Refactor TypicalPersons.java and shift instantiating a FindCommand in FindCommandTest to asserCommandBehavior method --- .../addressbook/commands/FindCommandTest.java | 33 +++++------- .../addressbook/util/TypicalPersons.java | 52 +++++++------------ 2 files changed, 33 insertions(+), 52 deletions(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index b8fe51d79..5fc408b8e 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -27,53 +27,48 @@ public class FindCommandTest { private final List EMPTY_LIST = Collections.emptyList(); - @Before public void setUp() { + @Before + public void setUp() { this.addressBook = new TypicalPersons().getTypicalAddressBook(); } @Test public void execute_sameWordSameCase_matched() throws IllegalValueException { - List expected = TestUtil.createList(new Person(TypicalPersons.amy)); - + List expected = TestUtil.createList(new Person(TypicalPersons.amy())); String[] keywordsWithMatchingCase = {"Amy"}; - FindCommand command = createFindCommand(keywordsWithMatchingCase); - assertCommandBehavior(command, expected, addressBook); + assertCommandBehavior(keywordsWithMatchingCase, expected, addressBook); } @Test public void execute_sameWordDifferentCase_notMatched() throws IllegalValueException { - String[] keywordsWithNonMatchingCase = {"aMy"}; - - FindCommand command = createFindCommand(keywordsWithNonMatchingCase); - assertCommandBehavior(command, EMPTY_LIST, addressBook); + String[] keywordsWithNonMatchingCase = {"aMy"}; + assertCommandBehavior(keywordsWithNonMatchingCase, EMPTY_LIST, addressBook); } @Test public void execute_partialKeyword_notMatched() throws IllegalValueException { String[] keywords = {"my"}; - - FindCommand command = createFindCommand(keywords); - assertCommandBehavior(command, EMPTY_LIST, addressBook); + assertCommandBehavior(keywords, EMPTY_LIST, addressBook); } @Test public void execute_multipleKeywords_matched() throws IllegalValueException { - List expected = TestUtil.createList(new Person(TypicalPersons.amy), - new Person(TypicalPersons.bill), - new Person(TypicalPersons.candy)); + List expected = TestUtil.createList(new Person(TypicalPersons.amy()), + new Person(TypicalPersons.bill()), + new Person(TypicalPersons.candy())); String[] keywords = {"Amy", "Bill", "Destiny"}; - - FindCommand command = createFindCommand(keywords); - assertCommandBehavior(command, expected, addressBook); + assertCommandBehavior(keywords, expected, addressBook); } /** * Executes the find command, and checks that the execution was what we had expected. */ - private void assertCommandBehavior(Command command, List expectedPersonList, AddressBook actualAddressBook) { + private void assertCommandBehavior(String[] keywords, List expectedPersonList, AddressBook actualAddressBook) { + FindCommand command = createFindCommand(keywords); CommandResult result = command.execute(); + AddressBook expectedAddressBook = new TypicalPersons().getTypicalAddressBook(); assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser); diff --git a/test/java/seedu/addressbook/util/TypicalPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java index 4d87de812..29badc33a 100644 --- a/test/java/seedu/addressbook/util/TypicalPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -3,50 +3,36 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.Person; -import seedu.addressbook.data.person.UniquePersonList; /** * Class to generate typical test persons */ public class TypicalPersons { - public static Person amy, bill, candy, donald, grace; - - public TypicalPersons() { - try { - amy = new PersonBuilder().withName("Amy Buck").withPublicPhone("91119111") - .withPublicEmail("ab@gmail.com").withPublicAddress("1 Clementi Road").build(); - - bill = new PersonBuilder().withName("Bill Clint").withPublicPhone("92229222") - .withPublicEmail("bc@gmail.com").withPrivateAddress("2 Clementi Road").build(); - - candy = new PersonBuilder().withName("Candy Destiny").withPrivatePhone("93339333") - .withPublicEmail("cd@gmail.com").withPublicAddress("3 Clementi Road").build(); - - donald = new PersonBuilder().withName("Donald Eillot").withPrivatePhone("94449444") - .withPrivateEmail("de@gmail.com").withPublicAddress("4 Clementi Road").build(); - - grace = new PersonBuilder().withName("Grace Hopper").withPublicPhone("95559555") - .withPrivateEmail("gh@gmail.com").withPrivateAddress("5 Clementi Road").build(); - - } catch (IllegalValueException e) { - e.printStackTrace(); - assert false : "not possible"; - } + public static Person amy() throws IllegalValueException { + return new PersonBuilder().withName("Amy Buck").withPublicPhone("91119111") + .withPublicEmail("ab@gmail.com").withPublicAddress("1 Clementi Road").build(); } - - private void loadAddressBookWithSampleData(AddressBook ab) { + + public static Person bill() throws IllegalValueException { + return new PersonBuilder().withName("Bill Clint").withPublicPhone("92229222") + .withPublicEmail("bc@gmail.com").withPrivateAddress("2 Clementi Road").build(); + } + + public static Person candy() throws IllegalValueException { + return new PersonBuilder().withName("Candy Destiny").withPrivatePhone("93339333") + .withPublicEmail("cd@gmail.com").withPublicAddress("3 Clementi Road").build(); + } + + private void loadAddressBookWithSampleData(AddressBook ab) { try { - for (Person p : getTypicalPersons()) { + Person[] sampleData = new Person[] {amy(), bill(), candy()}; + for (Person p : sampleData) { ab.addPerson(new Person(p)); } - } catch (UniquePersonList.DuplicatePersonException e) { + } catch (IllegalValueException e) { assert false : "not possible"; - } - } - - public Person[] getTypicalPersons() { - return new Person[] {amy, bill, candy, donald, grace}; + } } public AddressBook getTypicalAddressBook() { From f7e7607fa6795719d4fc622c457fa9a6b7c7945a Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Sun, 25 Dec 2016 21:16:54 +0800 Subject: [PATCH 15/23] Rename assertCommandBehavior to assertFindCommandBehavior --- .../seedu/addressbook/commands/FindCommandTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 5fc408b8e..7e97d7a17 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -37,19 +37,19 @@ public void execute_sameWordSameCase_matched() throws IllegalValueException { List expected = TestUtil.createList(new Person(TypicalPersons.amy())); String[] keywordsWithMatchingCase = {"Amy"}; - assertCommandBehavior(keywordsWithMatchingCase, expected, addressBook); + assertFindCommandBehavior(keywordsWithMatchingCase, expected, addressBook); } @Test public void execute_sameWordDifferentCase_notMatched() throws IllegalValueException { String[] keywordsWithNonMatchingCase = {"aMy"}; - assertCommandBehavior(keywordsWithNonMatchingCase, EMPTY_LIST, addressBook); + assertFindCommandBehavior(keywordsWithNonMatchingCase, EMPTY_LIST, addressBook); } @Test public void execute_partialKeyword_notMatched() throws IllegalValueException { String[] keywords = {"my"}; - assertCommandBehavior(keywords, EMPTY_LIST, addressBook); + assertFindCommandBehavior(keywords, EMPTY_LIST, addressBook); } @Test @@ -59,13 +59,13 @@ public void execute_multipleKeywords_matched() throws IllegalValueException { new Person(TypicalPersons.candy())); String[] keywords = {"Amy", "Bill", "Destiny"}; - assertCommandBehavior(keywords, expected, addressBook); + assertFindCommandBehavior(keywords, expected, addressBook); } /** * Executes the find command, and checks that the execution was what we had expected. */ - private void assertCommandBehavior(String[] keywords, List expectedPersonList, AddressBook actualAddressBook) { + private void assertFindCommandBehavior(String[] keywords, List expectedPersonList, AddressBook actualAddressBook) { FindCommand command = createFindCommand(keywords); CommandResult result = command.execute(); From fbc8f42a0ed628bb67b4f378d6fd184bce8f9229 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Tue, 27 Dec 2016 12:29:57 +0800 Subject: [PATCH 16/23] Remove PersonBuilder and make TypicalPersons fields non-static --- .../seedu/addressbook/util/PersonBuilder.java | 68 ------------------- .../addressbook/util/TypicalPersons.java | 41 +++++++---- 2 files changed, 26 insertions(+), 83 deletions(-) delete mode 100644 test/java/seedu/addressbook/util/PersonBuilder.java diff --git a/test/java/seedu/addressbook/util/PersonBuilder.java b/test/java/seedu/addressbook/util/PersonBuilder.java deleted file mode 100644 index 076ec1a23..000000000 --- a/test/java/seedu/addressbook/util/PersonBuilder.java +++ /dev/null @@ -1,68 +0,0 @@ -package seedu.addressbook.util; - -import seedu.addressbook.common.Utils; -import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.person.Address; -import seedu.addressbook.data.person.Email; -import seedu.addressbook.data.person.Name; -import seedu.addressbook.data.person.Person; -import seedu.addressbook.data.person.Phone; -import seedu.addressbook.data.tag.UniqueTagList; - -/** - * Factory class for building TestPerson - */ -public class PersonBuilder { - - private Name name; - private Phone phone; - private Email email; - private Address address; - - public PersonBuilder() { - this.name = null; - this.phone = null; - this.email = null; - this.address = null; - } - - public PersonBuilder withName(String name) throws IllegalValueException { - this.name = new Name(name); - return this; - } - - public PersonBuilder withPrivatePhone(String phone) throws IllegalValueException { - this.phone = new Phone(phone, true); - return this; - } - - public PersonBuilder withPublicPhone(String phone) throws IllegalValueException { - this.phone = new Phone(phone, false); - return this; - } - - public PersonBuilder withPrivateEmail(String email) throws IllegalValueException { - this.email = new Email(email, true); - return this; - } - - public PersonBuilder withPublicEmail(String email) throws IllegalValueException { - this.email = new Email(email, false); - return this; - } - - public PersonBuilder withPrivateAddress(String address) throws IllegalValueException { - this.address = new Address(address, true); - return this; - } - - public PersonBuilder withPublicAddress(String address) throws IllegalValueException { - this.address = new Address(address, false); - return this; - } - - public Person build() { - assert !Utils.isAnyNull(this.name, this.phone, this.email, this.address); - return new Person(this.name, this.phone, this.email, this.address, new UniqueTagList()); - } -} diff --git a/test/java/seedu/addressbook/util/TypicalPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java index 29badc33a..8cf07b07f 100644 --- a/test/java/seedu/addressbook/util/TypicalPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -2,39 +2,50 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.Address; +import seedu.addressbook.data.person.Email; +import seedu.addressbook.data.person.Name; import seedu.addressbook.data.person.Person; +import seedu.addressbook.data.person.Phone; +import seedu.addressbook.data.tag.UniqueTagList; /** * Class to generate typical test persons */ public class TypicalPersons { - public static Person amy() throws IllegalValueException { - return new PersonBuilder().withName("Amy Buck").withPublicPhone("91119111") - .withPublicEmail("ab@gmail.com").withPublicAddress("1 Clementi Road").build(); - } - - public static Person bill() throws IllegalValueException { - return new PersonBuilder().withName("Bill Clint").withPublicPhone("92229222") - .withPublicEmail("bc@gmail.com").withPrivateAddress("2 Clementi Road").build(); - } + public Person amy, bill, candy; - public static Person candy() throws IllegalValueException { - return new PersonBuilder().withName("Candy Destiny").withPrivatePhone("93339333") - .withPublicEmail("cd@gmail.com").withPublicAddress("3 Clementi Road").build(); + public TypicalPersons() { + try { + amy = new Person(new Name("Amy Buck"), new Phone("91119111", false), new Email("ab@gmail.com", false), + new Address("1 Clementi Road", false), new UniqueTagList()); + bill = new Person(new Name("Bill Clint"), new Phone("92229222", false), new Email("bc@gmail.com", false), + new Address("2 Clementi Road", false), new UniqueTagList()); + candy = new Person(new Name("Candy Destiny"), new Phone("93339333", false), new Email("cd@gmail.com", false), + new Address("3 Clementi Road", false), new UniqueTagList()); + } catch (IllegalValueException e) { + e.printStackTrace(); + assert false : "not possible"; + } + + } private void loadAddressBookWithSampleData(AddressBook ab) { try { - Person[] sampleData = new Person[] {amy(), bill(), candy()}; - for (Person p : sampleData) { + for (Person p : this.getTypicalPersons()) { ab.addPerson(new Person(p)); } } catch (IllegalValueException e) { assert false : "not possible"; } } - + + public Person[] getTypicalPersons() { + return new Person[]{amy, bill, candy}; + } + public AddressBook getTypicalAddressBook() { AddressBook ab = new AddressBook(); loadAddressBookWithSampleData(ab); From 71d0d8442d99bd4b8bf997d0e11320fb53c4dfa8 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Tue, 27 Dec 2016 12:31:32 +0800 Subject: [PATCH 17/23] Refactor FindCommandTest by inlining test methods --- .../data/person/UniquePersonList.java | 1 - .../addressbook/commands/FindCommandTest.java | 43 ++++++------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index 47ede54a3..bd85a891f 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -131,5 +131,4 @@ public boolean equals(Object other) { || (other instanceof UniquePersonList // instanceof handles nulls && this.internalList.equals(((UniquePersonList) other).internalList)); } - } diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 7e97d7a17..a0b3f1d6e 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -24,55 +24,40 @@ public class FindCommandTest { private AddressBook addressBook; + private TypicalPersons td; private final List EMPTY_LIST = Collections.emptyList(); @Before public void setUp() { this.addressBook = new TypicalPersons().getTypicalAddressBook(); + this.td = new TypicalPersons(); } @Test - public void execute_sameWordSameCase_matched() throws IllegalValueException { - List expected = TestUtil.createList(new Person(TypicalPersons.amy())); - String[] keywordsWithMatchingCase = {"Amy"}; + public void execute() throws IllegalValueException { + //same word, same case: matched + assertFindCommandBehavior(new String[]{"Amy"}, TestUtil.createList(td.amy)); - assertFindCommandBehavior(keywordsWithMatchingCase, expected, addressBook); - } - - @Test - public void execute_sameWordDifferentCase_notMatched() throws IllegalValueException { - String[] keywordsWithNonMatchingCase = {"aMy"}; - assertFindCommandBehavior(keywordsWithNonMatchingCase, EMPTY_LIST, addressBook); - } - - @Test - public void execute_partialKeyword_notMatched() throws IllegalValueException { - String[] keywords = {"my"}; - assertFindCommandBehavior(keywords, EMPTY_LIST, addressBook); - } - - @Test - public void execute_multipleKeywords_matched() throws IllegalValueException { - List expected = TestUtil.createList(new Person(TypicalPersons.amy()), - new Person(TypicalPersons.bill()), - new Person(TypicalPersons.candy())); + //same word, different case: not matched + assertFindCommandBehavior(new String[]{"aMy"}, EMPTY_LIST); - String[] keywords = {"Amy", "Bill", "Destiny"}; - assertFindCommandBehavior(keywords, expected, addressBook); + //partial word: not matched + assertFindCommandBehavior(new String[]{"my"}, EMPTY_LIST); + + //multiple words: matched + assertFindCommandBehavior(new String[]{"Amy", "Bill", "Destiny"}, TestUtil.createList(td.amy, td.bill, td.candy)); } + /** * Executes the find command, and checks that the execution was what we had expected. */ - private void assertFindCommandBehavior(String[] keywords, List expectedPersonList, AddressBook actualAddressBook) { + private void assertFindCommandBehavior(String[] keywords, List expectedPersonList) { FindCommand command = createFindCommand(keywords); CommandResult result = command.execute(); - AddressBook expectedAddressBook = new TypicalPersons().getTypicalAddressBook(); - assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser); - assertEquals(expectedAddressBook, actualAddressBook); } private FindCommand createFindCommand(String[] keywords) { From 349fb151e31edb6e1ffe6dadc243a5b592dc281d Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Tue, 27 Dec 2016 12:37:55 +0800 Subject: [PATCH 18/23] Remove unused imports --- test/java/seedu/addressbook/commands/FindCommandTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index a0b3f1d6e..8027e1cf9 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -13,7 +13,6 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.util.TestUtil; import seedu.addressbook.util.TypicalPersons; From 94f4cbdc109fde7acd607e5db1d11e07b8dd176e Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Thu, 29 Dec 2016 18:38:24 +0800 Subject: [PATCH 19/23] Add new test cases --- .../addressbook/commands/FindCommandTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 8027e1cf9..b809f4ad9 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -17,9 +17,6 @@ import seedu.addressbook.util.TestUtil; import seedu.addressbook.util.TypicalPersons; -/** - * Test class for the Find Command - */ public class FindCommandTest { private AddressBook addressBook; @@ -45,12 +42,18 @@ public void execute() throws IllegalValueException { assertFindCommandBehavior(new String[]{"my"}, EMPTY_LIST); //multiple words: matched - assertFindCommandBehavior(new String[]{"Amy", "Bill", "Destiny"}, TestUtil.createList(td.amy, td.bill, td.candy)); + assertFindCommandBehavior(new String[]{"Amy", "Bill", "Candy", "Destiny"}, TestUtil.createList(td.amy, td.bill, td.candy)); + + //repeated keywords: matched + assertFindCommandBehavior(new String[]{"Amy", "Amy"}, TestUtil.createList(td.amy)); + + //Keyword matching a word in address: not matched + assertFindCommandBehavior(new String[]{"Clementi"}, EMPTY_LIST); + } - /** - * Executes the find command, and checks that the execution was what we had expected. + * Executes the find command for the given keywords and verifies the result matches the persons in the expectedPersonList exactly. */ private void assertFindCommandBehavior(String[] keywords, List expectedPersonList) { FindCommand command = createFindCommand(keywords); From 0f539cc48639e7a983503f3c05c2aef709ab86a8 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Thu, 29 Dec 2016 18:41:36 +0800 Subject: [PATCH 20/23] Remove trailing empty lines --- src/seedu/addressbook/data/tag/UniqueTagList.java | 1 - test/java/seedu/addressbook/commands/FindCommandTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/seedu/addressbook/data/tag/UniqueTagList.java b/src/seedu/addressbook/data/tag/UniqueTagList.java index 7e2509f51..0d423846f 100644 --- a/src/seedu/addressbook/data/tag/UniqueTagList.java +++ b/src/seedu/addressbook/data/tag/UniqueTagList.java @@ -166,5 +166,4 @@ public boolean equals(Object other) { || (other instanceof UniqueTagList // instanceof handles nulls && this.internalList.equals(((UniqueTagList) other).internalList)); } - } diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index b809f4ad9..a6ed06e66 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -49,7 +49,6 @@ public void execute() throws IllegalValueException { //Keyword matching a word in address: not matched assertFindCommandBehavior(new String[]{"Clementi"}, EMPTY_LIST); - } /** From 642a760ac0990d4adfad0e85b58566d290709e93 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Fri, 30 Dec 2016 19:21:06 +0800 Subject: [PATCH 21/23] Fix coding style --- src/seedu/addressbook/data/AddressBook.java | 2 +- .../addressbook/data/tag/UniqueTagList.java | 3 +- .../addressbook/commands/FindCommandTest.java | 41 ++++++++----------- .../addressbook/util/TypicalPersons.java | 23 +++++------ 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index e3e4356d4..6a37d752d 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -143,7 +143,7 @@ public UniquePersonList getAllPersons() { public UniqueTagList getAllTags() { return new UniqueTagList(allTags); } - + @Override public boolean equals(Object other) { return other == this // short circuit if same object diff --git a/src/seedu/addressbook/data/tag/UniqueTagList.java b/src/seedu/addressbook/data/tag/UniqueTagList.java index 0d423846f..419edd861 100644 --- a/src/seedu/addressbook/data/tag/UniqueTagList.java +++ b/src/seedu/addressbook/data/tag/UniqueTagList.java @@ -159,11 +159,12 @@ public void setTags(UniqueTagList replacement) { public Iterator iterator() { return internalList.iterator(); } - + @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof UniqueTagList // instanceof handles nulls && this.internalList.equals(((UniqueTagList) other).internalList)); } + } diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index a6ed06e66..2c9b26784 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -19,45 +19,39 @@ public class FindCommandTest { - private AddressBook addressBook; - private TypicalPersons td; - - private final List EMPTY_LIST = Collections.emptyList(); - - @Before - public void setUp() { - this.addressBook = new TypicalPersons().getTypicalAddressBook(); - this.td = new TypicalPersons(); - } + private final AddressBook addressBook = new TypicalPersons().getTypicalAddressBook(); + private final TypicalPersons td = new TypicalPersons(); @Test public void execute() throws IllegalValueException { //same word, same case: matched - assertFindCommandBehavior(new String[]{"Amy"}, TestUtil.createList(td.amy)); - + assertFindCommandBehavior(new String[]{"Amy"}, Arrays.asList(td.amy)); + //same word, different case: not matched - assertFindCommandBehavior(new String[]{"aMy"}, EMPTY_LIST); - + assertFindCommandBehavior(new String[]{"aMy"}, Collections.emptyList()); + //partial word: not matched - assertFindCommandBehavior(new String[]{"my"}, EMPTY_LIST); - + assertFindCommandBehavior(new String[]{"my"}, Collections.emptyList()); + //multiple words: matched - assertFindCommandBehavior(new String[]{"Amy", "Bill", "Candy", "Destiny"}, TestUtil.createList(td.amy, td.bill, td.candy)); - + assertFindCommandBehavior(new String[]{"Amy", "Bill", "Candy", "Destiny"}, + Arrays.asList(td.amy, td.bill, td.candy)); + //repeated keywords: matched - assertFindCommandBehavior(new String[]{"Amy", "Amy"}, TestUtil.createList(td.amy)); - + assertFindCommandBehavior(new String[]{"Amy", "Amy"}, Arrays.asList(td.amy)); + //Keyword matching a word in address: not matched - assertFindCommandBehavior(new String[]{"Clementi"}, EMPTY_LIST); + assertFindCommandBehavior(new String[]{"Clementi"}, Collections.emptyList()); } /** - * Executes the find command for the given keywords and verifies the result matches the persons in the expectedPersonList exactly. + * Executes the find command for the given keywords and verifies + * the result matches the persons in the expectedPersonList exactly. */ private void assertFindCommandBehavior(String[] keywords, List expectedPersonList) { FindCommand command = createFindCommand(keywords); CommandResult result = command.execute(); - + assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser); } @@ -67,4 +61,5 @@ private FindCommand createFindCommand(String[] keywords) { command.setData(addressBook, Collections.emptyList()); return command; } + } diff --git a/test/java/seedu/addressbook/util/TypicalPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java index 8cf07b07f..64e0d99c8 100644 --- a/test/java/seedu/addressbook/util/TypicalPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -15,40 +15,39 @@ public class TypicalPersons { public Person amy, bill, candy; - + public TypicalPersons() { try { - amy = new Person(new Name("Amy Buck"), new Phone("91119111", false), new Email("ab@gmail.com", false), + amy = new Person(new Name("Amy Buck"), new Phone("91119111", false), new Email("ab@gmail.com", false), new Address("1 Clementi Road", false), new UniqueTagList()); - bill = new Person(new Name("Bill Clint"), new Phone("92229222", false), new Email("bc@gmail.com", false), + bill = new Person(new Name("Bill Clint"), new Phone("92229222", false), new Email("bc@gmail.com", false), new Address("2 Clementi Road", false), new UniqueTagList()); - candy = new Person(new Name("Candy Destiny"), new Phone("93339333", false), new Email("cd@gmail.com", false), - new Address("3 Clementi Road", false), new UniqueTagList()); + candy = new Person(new Name("Candy Destiny"), new Phone("93339333", false), + new Email("cd@gmail.com", false), new Address("3 Clementi Road", false), new UniqueTagList()); } catch (IllegalValueException e) { e.printStackTrace(); assert false : "not possible"; } - - } - - private void loadAddressBookWithSampleData(AddressBook ab) { + + private void loadAddressBookWithSampleData(AddressBook ab) { try { for (Person p : this.getTypicalPersons()) { ab.addPerson(new Person(p)); } } catch (IllegalValueException e) { assert false : "not possible"; - } + } } - + public Person[] getTypicalPersons() { return new Person[]{amy, bill, candy}; } - + public AddressBook getTypicalAddressBook() { AddressBook ab = new AddressBook(); loadAddressBookWithSampleData(ab); return ab; } + } From 1dd21bb8cf111e25a654a9e95045a85e1151beb6 Mon Sep 17 00:00:00 2001 From: DesmondAng Date: Fri, 30 Dec 2016 19:35:03 +0800 Subject: [PATCH 22/23] Remove unused imports --- test/java/seedu/addressbook/commands/FindCommandTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 2c9b26784..4c05446b0 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -8,13 +8,11 @@ import java.util.List; import java.util.Set; -import org.junit.Before; import org.junit.Test; import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.ReadOnlyPerson; -import seedu.addressbook.util.TestUtil; import seedu.addressbook.util.TypicalPersons; public class FindCommandTest { From ce4feb59f1642cf4df9d101e31ceb82aaeb1ef66 Mon Sep 17 00:00:00 2001 From: Ang Wei Hao Desmond Date: Mon, 2 Jan 2017 12:59:53 +0800 Subject: [PATCH 23/23] Remove trailing whitespaces --- src/seedu/addressbook/data/tag/UniqueTagList.java | 2 +- test/java/seedu/addressbook/commands/FindCommandTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/seedu/addressbook/data/tag/UniqueTagList.java b/src/seedu/addressbook/data/tag/UniqueTagList.java index 419edd861..cfea05b86 100644 --- a/src/seedu/addressbook/data/tag/UniqueTagList.java +++ b/src/seedu/addressbook/data/tag/UniqueTagList.java @@ -166,5 +166,5 @@ public boolean equals(Object other) { || (other instanceof UniqueTagList // instanceof handles nulls && this.internalList.equals(((UniqueTagList) other).internalList)); } - + } diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index 4c05446b0..f21b1e8e7 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -32,7 +32,7 @@ public void execute() throws IllegalValueException { assertFindCommandBehavior(new String[]{"my"}, Collections.emptyList()); //multiple words: matched - assertFindCommandBehavior(new String[]{"Amy", "Bill", "Candy", "Destiny"}, + assertFindCommandBehavior(new String[]{"Amy", "Bill", "Candy", "Destiny"}, Arrays.asList(td.amy, td.bill, td.candy)); //repeated keywords: matched @@ -43,7 +43,7 @@ public void execute() throws IllegalValueException { } /** - * Executes the find command for the given keywords and verifies + * Executes the find command for the given keywords and verifies * the result matches the persons in the expectedPersonList exactly. */ private void assertFindCommandBehavior(String[] keywords, List expectedPersonList) {