### Question:
CustomerSync { public boolean syncWithDataLayer(ExternalCustomer externalCustomer) { CustomerMatches customerMatches; if (externalCustomer.isCompany()) { customerMatches = loadCompany(externalCustomer); } else { customerMatches = loadPerson(externalCustomer); } Customer customer = customerMatches.getCustomer(); if (customer == null) { customer = new Customer(); customer.setExternalId(externalCustomer.getExternalId()); customer.setMasterExternalId(externalCustomer.getExternalId()); } populateFields(externalCustomer, customer); boolean created = false; if (customer.getInternalId() == null) { customer = createCustomer(customer); created = true; } else { updateCustomer(customer); } updateContactInfo(externalCustomer, customer); if (customerMatches.hasDuplicates()) { for (Customer duplicate : customerMatches.getDuplicates()) { updateDuplicate(externalCustomer, duplicate); } } updateRelations(externalCustomer, customer); updatePreferredStore(externalCustomer, customer); return created; } CustomerSync(CustomerDataLayer customerDataLayer);  CustomerSync(CustomerDataAccess db); boolean syncWithDataLayer(ExternalCustomer externalCustomer); CustomerMatches loadCompany(ExternalCustomer externalCustomer); CustomerMatches loadPerson(ExternalCustomer externalCustomer);  }### Answer:
@Test public void syncCompanyByExternalId(){ String externalId = "12345"; ExternalCustomer externalCustomer = createExternalCompany(); externalCustomer.setExternalId(externalId); Customer customer = createCustomerWithSameCompanyAs(externalCustomer); customer.setExternalId(externalId); CustomerDataLayer db = mock(CustomerDataLayer.class); when(db.findByExternalId(externalId)).thenReturn(customer); CustomerSync sut = new CustomerSync(db); boolean created = sut.syncWithDataLayer(externalCustomer); assertFalse(created); ArgumentCaptor<Customer> argument = ArgumentCaptor.forClass(Customer.class); verify(db, atLeastOnce()).updateCustomerRecord(argument.capture()); Customer updatedCustomer = argument.getValue(); assertEquals(externalCustomer.getName(), updatedCustomer.getName()); assertEquals(externalCustomer.getExternalId(), updatedCustomer.getExternalId()); assertNull(updatedCustomer.getMasterExternalId()); assertEquals(externalCustomer.getCompanyNumber(), updatedCustomer.getCompanyNumber()); assertEquals(externalCustomer.getPostalAddress(), updatedCustomer.getAddress()); assertEquals(externalCustomer.getShoppingLists(), updatedCustomer.getShoppingLists()); assertEquals(CustomerType.COMPANY, updatedCustomer.getCustomerType()); assertNull(updatedCustomer.getPreferredStore()); }