### Question:
IntercomMetricCollector implements MetricCollector { @Override public void removeOrganisationFromUser(final String userId, final String organisationId) { try { final User intercomUser = findIntercomUserByUserId(userId); final Company company = new Company(); company.setCompanyID(organisationId); intercomUser.removeCompany(company); User.update(intercomUser); } catch (final Exception e) { logger.warn("Error removing organisation with id: {} from Intercom user with id: {} - {} ", organisationId, userId, 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 shouldRemoveOrganisationFromUser_withUserIdAndOrganisationId() throws Exception { final String userId = randomId(); final Map<String, String> params = new HashMap<>(); params.put("user_id", userId); final String organisationId = randomId(); final User mockUser = mock(User.class); when(User.find(params)).thenReturn(mockUser); final Company mockCompany = mock(Company.class); when(Company.find(organisationId)).thenReturn(mockCompany); intercomMetricCollector.removeOrganisationFromUser(userId, organisationId); final ArgumentCaptor<Company> companyCaptor = ArgumentCaptor.forClass(Company.class); verify(mockUser).removeCompany(companyCaptor.capture()); assertThat(companyCaptor.getValue().getCompanyID(), is(organisationId)); verifyStatic(User.class); User.update(mockUser); }
@Test public void shouldNotRemoveOrganisationFromUser_withUserIdAndOrganisationIdAndIntercomFindUserException() { final String userId = randomId(); final Map<String, String> params = new HashMap<>(); params.put("user_id", userId); final String organisationId = randomId(); when(User.find(params)).thenThrow(IntercomException.class); intercomMetricCollector.removeOrganisationFromUser(userId, organisationId); verifyStatic(User.class, never()); User.update(any(User.class)); }