### Question:
GlobalAddressBook { public String addContact(Contact contact) { 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 public void testAddContact() { Contact contact = new Contact(); contact.setFirstName("Pedro"); addressBook.addContact(contact); List<Contact> contacts = addressBook.getAll(); assertEquals(1, contacts.size()); assertEquals("Pedro", contacts.get(0).getFirstName()); }
@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()); assertTrue(generatorMock.verifyNextId(1)); }
@Test public void testAddContact() { Contact contact = new Contact(); contact.setFirstName("Pedro"); addressBook.setIdGenerator(new GeneratorIdStub("newId")); addressBook.addContact(contact); List<Contact> contacts = addressBook.getAll(); assertEquals(1, contacts.size()); assertEquals("Pedro", contacts.get(0).getFirstName()); }
@Test public void testAddContact() { expectedContact.setFirstName("Pedro"); when(generatorMock.newId()).thenReturn("newId"); addressBook.addContact(expectedContact); List<Contact> contacts = addressBook.getAll(); assertEquals(1, contacts.size()); assertEquals("Pedro", contacts.get(0).getFirstName()); verify(generatorMock, times(1)).newId(); }