-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests for FindCommand class #110 #120
Changes from all commits
809a9ff
cb04f84
228696b
d664932
d40448b
1680011
ba2d41d
4fe6e4d
cb7db69
3d247be
4ab7163
acc5927
6793926
a90bdb7
f7e7607
fbc8f42
71d0d84
349fb15
94f4cbd
0f539cc
642a760
1dd21bb
ce4feb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 3 blank lines here? |
||
//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()); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra blank line |
||
/** | ||
* 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; | ||
} | ||
|
||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We did some tweaks to Typical persons in level 4 (see this) |
||
|
||
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; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two blank lines?