forked from nusCS2113-AY1819S1/addressbook-level4
/
FindAddressCommandTest.java
90 lines (75 loc) · 4 KB
/
FindAddressCommandTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package seedu.address.logic.commands;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.CARL;
import static seedu.address.testutil.TypicalPersons.ELLE;
import static seedu.address.testutil.TypicalPersons.FIONA;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import seedu.address.logic.CommandHistory;
import seedu.address.model.EventBook;
import seedu.address.model.ExpenseBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.TaskBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.AddressContainsKeywordsPredicate;
/**
* Contains integration tests (interaction with the Model) for {@code FindAddressCommand}.
*/
public class FindAddressCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new ExpenseBook(),
new EventBook(), new TaskBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new ExpenseBook(), new EventBook(),
new TaskBook(), new UserPrefs());
private CommandHistory commandHistory = new CommandHistory();
@Test
public void equals() {
AddressContainsKeywordsPredicate firstPredicate =
new AddressContainsKeywordsPredicate(Collections.singletonList("first"));
AddressContainsKeywordsPredicate secondPredicate =
new AddressContainsKeywordsPredicate(Collections.singletonList("second"));
FindAddressCommand findFirstAddressCommand = new FindAddressCommand(firstPredicate);
FindAddressCommand findSecondAddressCommand = new FindAddressCommand(secondPredicate);
// same object -> returns true
assertTrue(findFirstAddressCommand.equals(findFirstAddressCommand));
// same values -> returns true
FindAddressCommand findFirstAddressCommandCopy = new FindAddressCommand(firstPredicate);
assertTrue(findFirstAddressCommand.equals(findFirstAddressCommandCopy));
// different types -> returns false
assertFalse(findFirstAddressCommand.equals(1));
// null -> returns false
assertFalse(findFirstAddressCommand.equals(null));
// different person -> returns false
assertFalse(findFirstAddressCommand.equals(findSecondAddressCommand));
}
@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
AddressContainsKeywordsPredicate predicate = preparePredicate(" ");
FindAddressCommand command = new FindAddressCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(command, model, commandHistory, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredPersonList());
}
@Test
public void execute_multipleKeywords_multiplePersonsFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3);
AddressContainsKeywordsPredicate predicate = preparePredicate("wall michegan tokyo");
FindAddressCommand command = new FindAddressCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(command, model, commandHistory, expectedMessage, expectedModel);
assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList());
}
/**
* Parses {@code userInput} into a {@code AddressContainsKeywordsPredicate}.
*/
private AddressContainsKeywordsPredicate preparePredicate(String userInput) {
return new AddressContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+")));
}
}