@Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    searchResult = new SolrSearchResult(0, null, null, null, null, 0, 0, null, searchQuery, null);
    lang.setIsocode("de");

    when(commonI18NService.getCurrentLanguage()).thenReturn(lang);
    when(searchQuery.getFacetSearchConfig()).thenReturn(facetSearchConfig);

    final HashMap<KeywordRedirectMatchType, KeywordRedirectHandler> map =
        new HashMap<KeywordRedirectMatchType, KeywordRedirectHandler>();
    map.put(KeywordRedirectMatchType.CONTAINS, new DefaultContainsKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.ENDS_WITH, new DefaultEndsWithKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.EXACT, new DefaultExactKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.REGEX, new DefaultRegexKeywordRedirectHandler());
    map.put(KeywordRedirectMatchType.STARTS_WITH, new DefaultStartsWithKeywordRedirectHandler());

    solrKeywordRedirectService.setRedirectHandlers(map);
    when(keywordRedirectSorter.sort(Mockito.<List<SolrFacetSearchKeywordRedirectModel>>any()))
        .thenAnswer(
            new Answer() {
              @Override
              public List<KeywordRedirectValue> answer(final InvocationOnMock invocation) {
                final Object[] args = invocation.getArguments();
                return (List<KeywordRedirectValue>) args[0];
              }
            });
  }
 private void defaultTestSingleMatch(
     final KeywordRedirectMatchType matchMode,
     final String matchWord,
     final String fullQueryText) {
   searchResult.setKeywordRedirects(Collections.<KeywordRedirectValue>emptyList());
   final List<SolrFacetSearchKeywordRedirectModel> matches =
       new ArrayList<SolrFacetSearchKeywordRedirectModel>();
   final SolrFacetSearchKeywordRedirectModel redirect = new SolrFacetSearchKeywordRedirectModel();
   final SolrAbstractKeywordRedirectModel redirectValue =
       prepareRedirect(redirect, matchWord, matchMode);
   final SolrFacetSearchKeywordRedirectModel redirectNoMatch =
       new SolrFacetSearchKeywordRedirectModel();
   prepareRedirect(redirectNoMatch, "noMatchMatch", matchMode);
   matches.add(redirect);
   matches.add(redirectNoMatch);
   when(solrFacetSearchKeywordDao.findKeywords(
           searchQuery.getFacetSearchConfig().getName(), lang.getIsocode()))
       .thenReturn(matches);
   // when(solrKeywordRedirectService.findKeywordRedirects(searchQuery)).thenReturn(matches);
   when(searchQuery.getUserQuery()).thenReturn(fullQueryText);
   solrKeywordRedirectService.attachKeywordRedirect(searchResult);
   assertThat(searchResult.getKeywordRedirects().size()).isEqualTo(1);
   for (final KeywordRedirectValue value : searchResult.getKeywordRedirects()) {
     assertThat(value.getRedirect() == redirectValue);
   }
 }
  @Test
  public void testProcess() {
    solrKeywordRedirectService.attachKeywordRedirect(searchResult);
    assertThat(searchResult.getKeywordRedirects()).isEmpty();

    defaultTestSingleMatch(KeywordRedirectMatchType.EXACT, "fullMatch", "fullMatch");
    defaultTestSingleMatch(
        KeywordRedirectMatchType.STARTS_WITH, "startsWith", "startsWithWithSomethingAfter");
    defaultTestSingleMatch(KeywordRedirectMatchType.ENDS_WITH, "startsWith", "endsWithstartsWith");
    defaultTestSingleMatch(KeywordRedirectMatchType.CONTAINS, "contains", "start contains end");
    defaultTestSingleMatch(KeywordRedirectMatchType.REGEX, "a[bc]{2,3}.+e", "abcc-e");
  }