Skip to content
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 ViewAllCommand and ViewCommand classes #111 #131

Merged
merged 44 commits into from
Jan 17, 2017
Merged
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
20e25f1
add unit test for view command
zzzzwen Dec 29, 2016
017b996
Add header comment
zzzzwen Dec 30, 2016
9d049e3
Add unit test for ViewAll command
zzzzwen Dec 30, 2016
f97c6b1
javadoc change
zzzzwen Dec 30, 2016
e942a7e
Move assertCommandResult method to TestUtil
zzzzwen Dec 30, 2016
42f0c7f
Extract TypicalPersons
zzzzwen Dec 30, 2016
b414b98
Conflict
zzzzwen Dec 30, 2016
7140ae2
Merge branch 'master' into 111-unit-test-view-viewall
zzzzwen Dec 30, 2016
5457976
Conflict resolving
zzzzwen Dec 30, 2016
ffd7b0f
Rework TypicalPersons
zzzzwen Dec 30, 2016
8b3d3a3
code quality
zzzzwen Dec 30, 2016
2486c44
Merge branch 'master' of https://github.com/se-edu/addressbook-level2
zzzzwen Jan 3, 2017
2d1260d
Update TypicalPersons
zzzzwen Jan 3, 2017
73147c3
Code style issues
zzzzwen Jan 3, 2017
915c4d9
Code quality
zzzzwen Jan 3, 2017
acfb6a3
Code Style and combine two test cases
zzzzwen Jan 4, 2017
ea54ab7
Grammar
zzzzwen Jan 4, 2017
3a068e6
Remove use of createList
zzzzwen Jan 4, 2017
2d4cf4f
Code Style
zzzzwen Jan 4, 2017
3048a59
rework getList
zzzzwen Jan 4, 2017
ea22dbf
extract method
zzzzwen Jan 4, 2017
5334baf
reorder message
zzzzwen Jan 4, 2017
defefe1
Code style
zzzzwen Jan 4, 2017
4d30dde
Code style
zzzzwen Jan 4, 2017
d64b9f4
Add one test case
zzzzwen Jan 4, 2017
261fcab
comment change
zzzzwen Jan 4, 2017
fe3fa09
extract local variable
zzzzwen Jan 4, 2017
b01b1e6
Remove list methods in TypicalPersons
zzzzwen Jan 4, 2017
39ad9a7
Remove unused import
zzzzwen Jan 4, 2017
d6a6987
javadoc and code style changes
zzzzwen Jan 4, 2017
d2e9c4d
code style change
zzzzwen Jan 5, 2017
449af76
code style changes
zzzzwen Jan 5, 2017
5fcc198
code style change
zzzzwen Jan 5, 2017
f565130
remove trailing whitespaces
zzzzwen Jan 5, 2017
f6c2d90
Code style
zzzzwen Jan 6, 2017
f584b82
code style
zzzzwen Jan 6, 2017
2a11bd5
Combine to generic methods
zzzzwen Jan 8, 2017
beef8ab
Code style changes
zzzzwen Jan 9, 2017
c3af8e8
code style changes
zzzzwen Jan 9, 2017
9c60233
Code style changes
zzzzwen Jan 9, 2017
b9db7e5
code style changes
zzzzwen Jan 13, 2017
5b654c4
Code style changes
zzzzwen Jan 15, 2017
b4aba03
code style changes
zzzzwen Jan 15, 2017
eb7f500
Code style changes
zzzzwen Jan 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions test/java/seedu/addressbook/commands/ViewCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ public void execute_invalidIndex_returnsInvalidIndexMessage() {
assertViewErrorInvalidIndex(typicalAddressBook, listWithAllTypicalPersons, -1);
assertViewErrorInvalidIndex(typicalAddressBook, listWithAllTypicalPersons, 0);
assertViewErrorInvalidIndex(typicalAddressBook, listWithAllTypicalPersons,
listWithAllTypicalPersons.size() + 1);
listWithAllTypicalPersons.size() + 1);
}

@Test
public void execute_personNotInAddressBook_returnsPersonNotInAddressBookMessage() throws Exception {
// generate list with person not in addressbook, add to list
ReadOnlyPerson someone = new Person(new Name("me"),
new Phone("123", true),
new Email("[email protected]", true),
new Address("nus", false),
new UniqueTagList(Collections.emptySet()));
ReadOnlyPerson stranger = new Person(new Name("me"),
new Phone("123", true),
new Email("[email protected]", true),
new Address("nus", false),
new UniqueTagList(Collections.emptySet()));
List<ReadOnlyPerson> listWithExtraPerson
= new ArrayList<ReadOnlyPerson>(listWithAllTypicalPersons);
listWithExtraPerson.add(someone);
listWithExtraPerson.add(stranger);

// empty addressbook
assertViewErrorPersonNotInAddressBook(emptyAddressBook, listWithExtraPerson, 1);

// non-empty addressbook
assertViewErrorPersonNotInAddressBook(typicalAddressBook, listWithExtraPerson,
listWithExtraPerson.size());
listWithExtraPerson.size());
}

@Test
Expand All @@ -74,8 +74,8 @@ public void execute_validIndex_returnsPersonDetails() {
// person with all private information
assertViewSuccess(typicalAddressBook, listWithAllTypicalPersons, 4);

// addressbook has more people than the list
// This can happen when view from filtered list caused by some commands(eg. FindCommand)
// addressbook has more people than the list.
// this can happen when a command causes the list to show only a sub-set of persons(e.g. FindCommand).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full sentences should start with a upper case letter too. :-) So it should either a full sentence starting with a upper case letter and ending with a full stop, or just a short phrase starting with a lower case letter and no full stop at the end.

assertViewSuccess(typicalAddressBook, listWithSomeTypicalPersons, 1);
}

Expand All @@ -84,19 +84,19 @@ public void execute_validIndex_returnsPersonDetails() {
* invalid index.
*/
private void assertViewErrorInvalidIndex(AddressBook addressBook, List<ReadOnlyPerson> relevantPersons,
int targetVisibleIndex) {
int targetVisibleIndex) {
assertViewError(addressBook, relevantPersons, targetVisibleIndex,
Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

/**
* Asserts that the details of person at specific index cannot be retrieved due to
* person not existing in the addressbook.
*/
private void assertViewErrorPersonNotInAddressBook(AddressBook addressBook, List<ReadOnlyPerson> relevantPersons,
int targetVisibleIndex) {
int targetVisibleIndex) {
assertViewError(addressBook, relevantPersons, targetVisibleIndex,
Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
}

/**
Expand All @@ -107,24 +107,24 @@ private void assertViewErrorPersonNotInAddressBook(AddressBook addressBook, List
* @param targetVisibleIndex one-indexed position of the target person in the list
*/
private void assertViewSuccess(AddressBook addressBook, List<ReadOnlyPerson> relevantPersons,
int targetVisibleIndex) {
// Get person to be viewed (targetVisibleIndex - 1 because index is one-indexed)
int targetVisibleIndex) {
// get person to be viewed (targetVisibleIndex - 1 because index is one-indexed)
ReadOnlyPerson personToBeViewed = relevantPersons.get(targetVisibleIndex - 1);

String expectedMessage = String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS,
personToBeViewed.getAsTextHidePrivate());
personToBeViewed.getAsTextHidePrivate());
assertViewBehavior(new ViewCommand(targetVisibleIndex), addressBook, relevantPersons, expectedMessage);

expectedMessage = String.format(ViewAllCommand.MESSAGE_VIEW_PERSON_DETAILS,
personToBeViewed.getAsTextShowAll());
personToBeViewed.getAsTextShowAll());
assertViewBehavior(new ViewAllCommand(targetVisibleIndex), addressBook, relevantPersons, expectedMessage);
}

/**
* Asserts that the Viewcommand and ViewAllcommand reports the given error for the given input.
*/
private static void assertViewError(AddressBook addressBook, List<ReadOnlyPerson> relevantPersons,
int targetVisibleIndex, String expectedMessage) {
int targetVisibleIndex, String expectedMessage) {
assertViewBehavior(new ViewCommand(targetVisibleIndex), addressBook, relevantPersons, expectedMessage);
assertViewBehavior(new ViewAllCommand(targetVisibleIndex), addressBook, relevantPersons, expectedMessage);
}
Expand All @@ -143,11 +143,11 @@ private static void assertViewBehavior(Command viewCommand, AddressBook addressB
viewCommand.setData(addressBook, relevantPersons);
CommandResult result = viewCommand.execute();

// Feedback message is as expected and there are no relevant persons returned
// feedback message is as expected and there are no relevant persons returned.
assertEquals(expectedMessage, result.feedbackToUser);
assertEquals(Optional.empty(), result.getRelevantPersons());

// Address book was not modified
// addressbook was not modified.
assertEquals(expectedAddressBook.getAllPersons(), addressBook.getAllPersons());
}

Expand Down