-
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 ViewAllCommand and ViewCommand classes #111 #131
Merged
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 017b996
Add header comment
zzzzwen 9d049e3
Add unit test for ViewAll command
zzzzwen f97c6b1
javadoc change
zzzzwen e942a7e
Move assertCommandResult method to TestUtil
zzzzwen 42f0c7f
Extract TypicalPersons
zzzzwen b414b98
Conflict
zzzzwen 7140ae2
Merge branch 'master' into 111-unit-test-view-viewall
zzzzwen 5457976
Conflict resolving
zzzzwen ffd7b0f
Rework TypicalPersons
zzzzwen 8b3d3a3
code quality
zzzzwen 2486c44
Merge branch 'master' of https://github.com/se-edu/addressbook-level2
zzzzwen 2d1260d
Update TypicalPersons
zzzzwen 73147c3
Code style issues
zzzzwen 915c4d9
Code quality
zzzzwen acfb6a3
Code Style and combine two test cases
zzzzwen ea54ab7
Grammar
zzzzwen 3a068e6
Remove use of createList
zzzzwen 2d4cf4f
Code Style
zzzzwen 3048a59
rework getList
zzzzwen ea22dbf
extract method
zzzzwen 5334baf
reorder message
zzzzwen defefe1
Code style
zzzzwen 4d30dde
Code style
zzzzwen d64b9f4
Add one test case
zzzzwen 261fcab
comment change
zzzzwen fe3fa09
extract local variable
zzzzwen b01b1e6
Remove list methods in TypicalPersons
zzzzwen 39ad9a7
Remove unused import
zzzzwen d6a6987
javadoc and code style changes
zzzzwen d2e9c4d
code style change
zzzzwen 449af76
code style changes
zzzzwen 5fcc198
code style change
zzzzwen f565130
remove trailing whitespaces
zzzzwen f6c2d90
Code style
zzzzwen f584b82
code style
zzzzwen 2a11bd5
Combine to generic methods
zzzzwen beef8ab
Code style changes
zzzzwen c3af8e8
code style changes
zzzzwen 9c60233
Code style changes
zzzzwen b9db7e5
code style changes
zzzzwen 5b654c4
Code style changes
zzzzwen b4aba03
code style changes
zzzzwen eb7f500
Code style changes
zzzzwen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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). | ||
assertViewSuccess(typicalAddressBook, listWithSomeTypicalPersons, 1); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
|
@@ -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()); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.