### Question:
ActiveDirectorySearchCriteriaBuilderImpl extends SearchCriteriaBuilder { @Override public void translateFilter() { String searchTest = getQueryRequest().getSearchText(); if (searchTest != null && !searchTest.isEmpty()) { this.searchFilter = searchTest; return; } this.searchFilter = translateFilter(getQueryRequest().getSearchSentence()); }  @Override void translateFields(); @Override void translateSortKeys(); @Override void translateFilter(); @Override String translateField(FieldInfo field); @Override SearchCriteria get();  }### Answer:
@Test public void testTranslateFilterInjectedByUser() { when(queryRequest.getSearchText()).thenReturn("STAM"); activeDirectorySearchCriteriaBuilder.translateFilter(); verify(activeDirectorySearchCriteriaBuilder, times(0)).translateFilter(any(Word.class)); }
@Test public void testTranslateFilter() { when(queryRequest.getSearchText()).thenReturn(null); QueryAssembler assembler = new QueryAssembler(); Sentence gabiSentence = assembler.addPhrase(FieldType.FIRST_NAME, PhraseOperator.EQUAL, "gabi") .addPhrase(FieldType.CITY, PhraseOperator.EQUAL, "TLV") .closeSentence(SentenceOperator.AND); Sentence motySentence = assembler.addPhrase(FieldType.FIRST_NAME, PhraseOperator.EQUAL, "moty") .addPhrase(FieldType.CITY, PhraseOperator.EQUAL, "ITA") .closeSentence(SentenceOperator.AND); Sentence combinedSentence = assembler.addSentence(motySentence) .addSentence(gabiSentence) .closeSentence(SentenceOperator.OR); when(queryRequest.getSearchSentence()).thenReturn(combinedSentence); activeDirectorySearchCriteriaBuilder.translateFilter(); SearchCriteria searchCriteria = activeDirectorySearchCriteriaBuilder.get(); assertTrue(searchCriteria.getSearchFilter().equals("(|(&(givenName=moty)(l=ITA))(&(givenName=gabi)(l=TLV)))")); }
@Test(expected = ParsingException.class) public void testTranslateEmptyFilterPhraseValue() { Phrase phrase = mock(Phrase.class); doReturn("").when(activeDirectorySearchCriteriaBuilder).translatePhrase(phrase); activeDirectorySearchCriteriaBuilder.translateFilter(phrase); verify(activeDirectorySearchCriteriaBuilder, times(1)).translatePhrase(phrase); }
@Test(expected = ParsingException.class) public void testTranslateEmptyFilterPhrase() { Phrase phrase = null; doReturn("").when(activeDirectorySearchCriteriaBuilder).translatePhrase(phrase); activeDirectorySearchCriteriaBuilder.translateFilter(phrase); verify(activeDirectorySearchCriteriaBuilder, times(1)).translatePhrase(phrase); }