-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add testutil classes to facilitate testing * Add TestMain class to facilitate testing of commands * Add equals() methond in AddressBook, UniquePersonList and UniqueTagList * Add FindCommandTest and CommandTest * Fix code style * Add indentation for equals() method * Reimplement FindCommandTest without use of TestMain * Remove duplicate equals() method in UniquePersonList * Remove TestPerson class * Refactor FindCommandTest * Refactor FindCommandTest * Refactor FindCommandTest * Remove empty line at top of assertCommandBehavior * Refactor TypicalPersons.java and shift instantiating a FindCommand in FindCommandTest to asserCommandBehavior method * Rename assertCommandBehavior to assertFindCommandBehavior * Remove PersonBuilder and make TypicalPersons fields non-static * Refactor FindCommandTest by inlining test methods * Remove unused imports * Add new test cases * Remove trailing empty lines * Fix coding style * Remove unused imports * Remove trailing whitespaces
- Loading branch information
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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.Test; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
import seedu.addressbook.util.TypicalPersons; | ||
|
||
public class FindCommandTest { | ||
|
||
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"}, Arrays.asList(td.amy)); | ||
|
||
//same word, different case: not matched | ||
assertFindCommandBehavior(new String[]{"aMy"}, Collections.emptyList()); | ||
|
||
//partial word: not matched | ||
assertFindCommandBehavior(new String[]{"my"}, Collections.emptyList()); | ||
|
||
//multiple words: matched | ||
assertFindCommandBehavior(new String[]{"Amy", "Bill", "Candy", "Destiny"}, | ||
Arrays.asList(td.amy, td.bill, td.candy)); | ||
|
||
//repeated keywords: matched | ||
assertFindCommandBehavior(new String[]{"Amy", "Amy"}, Arrays.asList(td.amy)); | ||
|
||
//Keyword matching a word in address: not matched | ||
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. | ||
*/ | ||
private void assertFindCommandBehavior(String[] keywords, List<ReadOnlyPerson> expectedPersonList) { | ||
FindCommand command = createFindCommand(keywords); | ||
CommandResult result = command.execute(); | ||
|
||
assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser); | ||
} | ||
|
||
private FindCommand createFindCommand(String[] keywords) { | ||
final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords)); | ||
FindCommand command = new FindCommand(keywordSet); | ||
command.setData(addressBook, Collections.emptyList()); | ||
return command; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package seedu.addressbook.util; | ||
|
||
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 Person amy, bill, candy; | ||
|
||
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 { | ||
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; | ||
} | ||
|
||
} |