### Question:
GlobalAddressBook { public String addContact(Contact contact) { if(contact.getFirstName() == null || contact.getFirstName().trim().length() < 1) { throw new InvalidContactException(); } contact.setFirstName(contact.getFirstName().trim()); String firstName = contact.getFirstName(); for(Contact existingContact: addressBookMap.values()) { String existingFirstName = existingContact.getFirstName(); if(firstName.equalsIgnoreCase(existingFirstName)) { throw new InvalidContactException(); } } String id = idGenerator.newId(); contact.setId(id); addressBookMap.put(id, contact); return id; }  String addContact(Contact contact); List<Contact> getAll(); Contact getContact(String contactId); IdGenerator getIdGenerator(); void setIdGenerator(IdGenerator idGenerator);  }### Answer:
@Test public void testAddContact() { expectedContact.setFirstName("Pedro"); addressBook.addContact(expectedContact); List<Contact> contacts = addressBook.getAll(); assertEquals(1, contacts.size()); assertEquals("Pedro", contacts.get(0).getFirstName()); }
@Test(expected=InvalidContactException.class) public void testAddWithoutFirstName() { expectedContact.setSurname("Ballesteros"); addressBook.addContact(expectedContact); }
@Test(expected=InvalidContactException.class) public void testAddBlankFirstName() { expectedContact.setFirstName(" "); expectedContact.setSurname("Ballesteros"); addressBook.addContact(expectedContact); }
@Test(expected=InvalidContactException.class) public void testAddEmptyFirstName() { expectedContact.setFirstName(""); expectedContact.setSurname("Ballesteros"); addressBook.addContact(expectedContact); }
@Test public void testAddDuplicateNameDifferentSurname() { Contact c1 = new Contact(); c1.setFirstName("Pedro"); c1.setSurname("Herranz"); Contact c2 = new Contact(); c2.setFirstName("Pedro"); c2.setSurname("Ballesteros"); String actualId1 = addressBook.addContact(c1); String actualId2 = addressBook.addContact(c2); }