### Question:
MemAddressBook implements GlobalAddressBook { @Override public String addContact(Contact contact) { if(contact.getFirstName() == null || contact.getFirstName().trim().length() < 1) { throw new InvalidContactException(); } contact.setFirstName(contact.getFirstName().trim()); if(contact.getSurname() != null) { contact.setSurname(contact.getSurname().trim()); } if(checkDuplicate(contact)) { throw new InvalidContactException(); } String id = idGenerator.newId(); contact.setId(id); addressBookMap.put(id, contact); return id; }  @Override String addContact(Contact contact); @Override Contact getContact(String contactId); IdGenerator getIdGenerator(); void setIdGenerator(IdGenerator idGenerator); @Override List<Contact> getAll(); @Override void deleteContact(String id);  }### Answer:
@Test public void testAddContact() { defaultContact.setFirstName("Pedro"); when(generatorMock.newId()).thenReturn("newId"); String contactId = addressBook.addContact(defaultContact); assertEquals("newId", contactId); verify(generatorMock, times(1)).newId(); }
@Test(expected = InvalidContactException.class) public void testAddWithoutFirstName() { defaultContact.setSurname("Ballesteros"); addressBook.addContact(defaultContact); }
@Test(expected = InvalidContactException.class) public void testAddBlankFirstName() { defaultContact.setFirstName(" "); defaultContact.setSurname("Ballesteros"); addressBook.addContact(defaultContact); }
@Test(expected = InvalidContactException.class) public void testAddEmptyFirstName() { defaultContact.setFirstName(""); defaultContact.setSurname("Ballesteros"); addressBook.addContact(defaultContact); }