### Question:
ProjectService implements SearchableEntityService { public SearchResponse findByCode(String code) { try { return searchClientService.performFilterByOneField(SEARCH_INDEX_NAME, SEARCH_INDEX_TYPE, FIELD_CODE, code); } catch (SearchIndexMissingException e) { return null; } }  @Override StreamingOutput getAll(Integer from, Integer size, String[] fieldsToRemove); @Override List<Map<String, Object>> getAll(); @Override Map<String, Object> get(String id); @Override String create(Map<String, Object> entity); @Override void create(String id, Map<String, Object> entity); @Override void update(String id, Map<String, Object> entity); @Override void delete(String id); SearchResponse findByCode(String code); SearchResponse findByTypeSpecificCode(String codeName, String codeValue); @Override ListRequest listRequestInit(); @Override ListRequest listRequestNext(ListRequest previous); @Override BulkRequestBuilder prepareBulkRequest(); @Override void updateSearchIndex(BulkRequestBuilder brb, String id, Map<String, Object> entity); @Override void deleteOldFromSearchIndex(Date timestamp); static final String FIELD_CODE; static final String FIELD_NAME; static final String FIELD_TYPE_SPECIFIC_CODE; static final String SEARCH_INDEX_NAME; static final String SEARCH_INDEX_TYPE; }### Answer:
@Test public void findByCode() throws Exception { Client client = prepareESClientForUnitTest("ProjectServiceTest_5"); ProjectService tested = getTested(client); try { { indexDelete(ProjectService.SEARCH_INDEX_NAME); SearchResponse sr = tested.findByCode("jbosstools"); Assert.assertNull(sr); } indexCreate(ProjectService.SEARCH_INDEX_NAME); { SearchResponse sr = tested.findByCode("jbosstools"); Assert.assertEquals(0, sr.getHits().getTotalHits()); } indexInsertDocument(ProjectService.SEARCH_INDEX_NAME, ProjectService.SEARCH_INDEX_TYPE, "10", "{\"code\":\"jbosstools\"}"); indexInsertDocument(ProjectService.SEARCH_INDEX_NAME, ProjectService.SEARCH_INDEX_TYPE, "20", "{\"code\":\"jbossas\"}"); indexInsertDocument(ProjectService.SEARCH_INDEX_NAME, ProjectService.SEARCH_INDEX_TYPE, "30", "{\"code\":\"aerogear\"}"); indexFlushAndRefresh(ProjectService.SEARCH_INDEX_NAME); { SearchResponse sr = tested.findByCode("jbossas"); Assert.assertEquals(1, sr.getHits().getTotalHits()); Assert.assertEquals("20", sr.getHits().getHits()[0].getId()); sr = tested.findByCode("jbosstools"); Assert.assertEquals(1, sr.getHits().getTotalHits()); Assert.assertEquals("10", sr.getHits().getHits()[0].getId()); sr = tested.findByCode("spring"); Assert.assertEquals(0, sr.getHits().getTotalHits()); } } finally { indexDelete(ProjectService.SEARCH_INDEX_NAME); finalizeESClientForUnitTest(); } }