### Question:
IntercomMetricCollector implements MetricCollector { @Override public void convertExistingContactToUser(final String contactId, final MetricUser metricUser) { final User intercomUser = createIntercomUser(metricUser); try { final Contact contact = Contact.findByUserID(contactId); logger.debug("Converting existing Intercom contact {} with id {} to user: {} - {}", contact, contactId, intercomUser); Contact.convert(contact, intercomUser); } catch (final Exception e) { logger.debug("Error converting existing Intercom contact to user: {}", e.getMessage()); throw new MetricException(e.getMessage()); } } IntercomMetricCollector(final String personalAccessToken); @Override void createOrganisation(final MetricOrganisation organisation); @Override void updateOrganisation(final MetricOrganisation organisation); @Override void tagOrganisation(final String tagName, final MetricOrganisation metricOrganisation); @Override void createUser(final MetricUser user); @Override void updateUser(final MetricUser user); @Override void addCustomAttributesToUser(final String userId, final Map<String, Object> customAttributes); @Override void addOrganisationToUser(final String userId, final String organisationId); @Override void removeOrganisationFromUser(final String userId, final String organisationId); @Override void deleteUser(final String userId); @Override void sendMetric(final Metric metric); @Override MetricUser getUser(final String userId); @Override void convertExistingContactToUser(final String contactId, final MetricUser metricUser);  }### Answer:
@Test public void shouldConvertExistingContactToUser_withContactIdMetricUser() throws Exception { final String contactId = randomId(); final MetricUser metricUser = randomMetricUser(); final Contact mockContact = mock(Contact.class); when(Contact.findByUserID(contactId)).thenReturn(mockContact); intercomMetricCollector.convertExistingContactToUser(contactId, metricUser); final ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class); verifyStatic(Contact.class); Contact.convert(eq(mockContact), userCaptor.capture()); final User intercomUser = userCaptor.getValue(); assertThat(intercomUser.getId(), is(metricUser.id())); assertThat(intercomUser.getUserId(), is(metricUser.id())); assertThat(intercomUser.getCompanyCollection().getPage().size(), is(metricUser.organisationIds().size())); intercomUser.getCompanyCollection().getPage() .forEach(company -> assertTrue(metricUser.organisationIds().contains(company.getCompanyID()))); }
@Test public void shouldNotConvertExistingContactToUser_withFindContactException() { final String contactId = randomId(); final MetricUser metricUser = randomMetricUser(); when(Contact.findByUserID(contactId)).thenThrow(IntercomException.class); MetricException actualException = null; try { intercomMetricCollector.convertExistingContactToUser(contactId, metricUser); } catch (final MetricException e) { actualException = e; } assertNotNull(actualException); verifyStatic(Contact.class, never()); Contact.convert(any(Contact.class), any(User.class)); }