### Question:
ContributorProfileService { public SearchResponse findByContributorCode(String contributorCode) { try { return searchClientService.performFilterByOneField(SEARCH_INDEX_NAME, SEARCH_INDEX_TYPE, ContentObjectFields.SYS_CONTRIBUTORS, contributorCode); } catch (SearchIndexMissingException e) { return null; } }  boolean isContributorCodeTypesSupported(String contributorCodeType); String getContributorId(String contributorCodeType, String contributorCodeValue, boolean forceCreate); String createOrUpdateProfile(String contributorCodeType, String contributorCodeValue, boolean forceUpdate); SearchResponse findByContributorCode(String contributorCode); boolean deleteByContributorCode(String code); @TransactionAttribute(TransactionAttributeType.NEVER) int fullSynContributorsAndProfiles(String contributorCodeType, Integer start, Integer size); @TransactionAttribute(TransactionAttributeType.NEVER) int createOrUpdateAllProfiles(String contributorCodeType); void contributorDeletedEventHandler(@Observes ContributorDeletedEvent event); void contributorMergedEventHandler(@Observes ContributorMergedEvent event); void contributorCodeChangedEventHandler(@Observes ContributorCodeChangedEvent event); static final String FIELD_TSC_JBOSSORG_USERNAME; static final String FIELD_TSC_GITHUB_USERNAME; static final String SEARCH_INDEX_NAME; static final String SEARCH_INDEX_TYPE; }### Answer:
@Test public void findByContributorCode() throws Exception { Client client = prepareESClientForUnitTest("ContributorProfileServiceTest"); ContributorProfileService tested = getTested(client); try { { indexDelete(ContributorProfileService.SEARCH_INDEX_NAME); Assert.assertNull(tested.findByContributorCode(CODE_1)); Assert.assertNull(tested.findByContributorCode(CODE_1)); } indexDelete(ContributorProfileService.SEARCH_INDEX_NAME); initIndex(client); Thread.sleep(100); { SearchResponse sr = tested.findByContributorCode(CODE_1); Assert.assertEquals(0, sr.getHits().getTotalHits()); } indexInsertDocument(ContributorProfileService.SEARCH_INDEX_NAME, ContributorProfileService.SEARCH_INDEX_TYPE, "10", "{\"" + ContentObjectFields.SYS_CONTRIBUTORS + "\":[\"" + CODE_2 + "\"],\"displayName\":\"John Doe 2\"}"); indexInsertDocument(ContributorProfileService.SEARCH_INDEX_NAME, ContributorProfileService.SEARCH_INDEX_TYPE, "20", "{\"" + ContentObjectFields.SYS_CONTRIBUTORS + "\":[\"" + CODE_1 + "\"],\"displayName\":\"John Doe\"}"); indexInsertDocument(ContributorProfileService.SEARCH_INDEX_NAME, ContributorProfileService.SEARCH_INDEX_TYPE, "30", "{\"" + ContentObjectFields.SYS_CONTRIBUTORS + "\":[\"paul doe <t@te.org>\"],\"displayName\":\"Paul Doe\"}"); indexFlushAndRefresh(ContributorProfileService.SEARCH_INDEX_NAME); { SearchResponse sr = tested.findByContributorCode(CODE_1); Assert.assertEquals(1, sr.getHits().getTotalHits()); Assert.assertEquals("20", sr.getHits().getHits()[0].getId()); sr = tested.findByContributorCode(CODE_2); Assert.assertEquals(1, sr.getHits().getTotalHits()); Assert.assertEquals("10", sr.getHits().getHits()[0].getId()); sr = tested.findByContributorCode(CODE_3); Assert.assertEquals(0, sr.getHits().getTotalHits()); } } finally { indexDelete(ContributorProfileService.SEARCH_INDEX_NAME); finalizeESClientForUnitTest(); } }