Not enough Code in Contact class for Tests. (validation and compareTo)
I got poor result for testing
That should be better explained! Right now i have failed tests for comparator (CompareContactTest.class) and validation (AddContactTest.class), because of missing code.
- Explain pls the model. i see you allow duplicated contacts. Why? What a difference between unique, common and all contacts? And so on...
REFACTORING:
AddressBook:
Why should it be a problem, that address book is empty? Just empty output would be ok in my opinion.
public void printContacts() {
if (getContacts() != null && !getContacts().isEmpty()) {
System.out.println(this);
} else {
throw new EmptyAddressBookException(Constants.Exceptions.EMPTY_ADDRESS_BOOK_ERROR_MSG);
}
}
I would define all containers as final. For Example AddressBook:
final List<Contact> contacts = new ArrayList<>();
private String name;
public AddressBook(final String name) {
this.name = name;
}
public void printContacts() {
for (final Contact c : this.contacts){
System.out.println(c);
}
}
AddressBookController:
public void printUniqueContacts() {
Set<Contact> uniqueContacts = getUniqueContacts();
Iterator<Contact> itr = uniqueContacts.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
it can be replaced with one line if you use java 8:
public void printUniqueContacts() {
getUniqueContacts().stream().forEach(c -> System.out.println(c));
}
---------------------
Add toString method to Contact and AddressBook. Otherwise you see only object references.