@Test public void count_MultipleWords_ShouldCreateConditionAndReturnDocuments() { when(solrTemplateMock.count(any(Query.class))).thenReturn(RESULT_COUNT); long actual = repository.count(SEARCH_TERM_TWO_WORDS); ArgumentCaptor<SimpleQuery> queryArgument = ArgumentCaptor.forClass(SimpleQuery.class); verify(solrTemplateMock, times(1)).count(queryArgument.capture()); verifyNoMoreInteractions(solrTemplateMock); SimpleQuery executedQuery = queryArgument.getValue(); Criteria executedCriteria = executedQuery.getCriteria(); List<Criteria> criteriaChain = executedCriteria.getCriteriaChain(); assertEquals(4, criteriaChain.size()); for (Criteria criteria: criteriaChain) { Field field = criteria.getField(); assertTrue(field.getName().equals(TodoDocument.FIELD_TITLE) || field.getName().equals(TodoDocument.FIELD_DESCRIPTION)); Set<Criteria.CriteriaEntry> entries = criteria.getCriteriaEntries(); assertEquals(1, entries.size()); Criteria.CriteriaEntry entry = entries.iterator().next(); assertEquals(Criteria.OperationKey.CONTAINS.getKey(), entry.getKey()); assertTrue(WORD_ONE.equals(entry.getValue()) || WORD_TWO.equals(entry.getValue())); } assertEquals(RESULT_COUNT, actual); }
@Override public long count(String searchTerm) { LOGGER.debug("Finding count for search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery countQuery = new SimpleQuery(conditions); return solrTemplate.count(countQuery); }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public long count(String searchTerm) { LOGGER.debug("Finding count for search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery countQuery = new SimpleQuery(conditions); return solrTemplate.count(countQuery); } }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public long count(String searchTerm) { LOGGER.debug("Finding count for search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery countQuery = new SimpleQuery(conditions); return solrTemplate.count(countQuery); }  }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public long count(String searchTerm) { LOGGER.debug("Finding count for search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery countQuery = new SimpleQuery(conditions); return solrTemplate.count(countQuery); }  @Override long count(String searchTerm); @Override void update(Todo todoEntry); }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public long count(String searchTerm) { LOGGER.debug("Finding count for search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery countQuery = new SimpleQuery(conditions); return solrTemplate.count(countQuery); }  @Override long count(String searchTerm); @Override void update(Todo todoEntry);  }