### Question:
DictionaryPresenter { void search(String word) { boolean isLatinAlphabet; if (word.isEmpty()) { return; } word = word.toLowerCase(Locale.ROOT); if (SpellChecker.ALPHABET_LATIN.indexOf(word.charAt(0)) >= 0) { isLatinAlphabet = true; } else if (SpellChecker.ALPHABET_CYRILLIC.indexOf(word.charAt(0)) >= 0) { isLatinAlphabet = false; } else { dictionaryView.showMessage(R.string.invalid_input); dictionaryView.setMessageVisible(); return; } SozlikDbModel result = sozlikDao.getTranslation(word); if (result != null) { dictionaryView.showTranslation(result.getId()); } else if (word.length() >= WORD_MIN_LENGTH) { List<SozlikDbModel> listOfResults = spellChecker.check(word, isLatinAlphabet); dictionaryView.showMessage(listOfResults.isEmpty() ? R.string.suggestion_not_found : R.string.suggestion_found); dictionaryView.setMessageVisible(); dictionaryView.showResults(listOfResults); } else { dictionaryView.showMessage(R.string.suggestion_not_found); dictionaryView.setMessageVisible(); } } DictionaryPresenter(SozlikDao sozlikDao, PackageHelper packageHelper, SpellChecker spellChecker); void setView(DictionaryView dictionaryView);  }### Answer:
@Test public void whenSearchWordNotFoundButSuggestionsFoundShowSuggestions() { List<SozlikDbModel> list = new ArrayList<>(); list.add(new SozlikDbModel()); when(sozlikDaoMock.getTranslation(SOME_WORD)).thenReturn(null); when(spellCheckerMock.check(SOME_WORD, true)).thenReturn(list); dictionaryPresenter.search(SOME_WORD); verify(dictionaryViewMock, times(1)).showMessage(R.string.suggestion_found); verify(dictionaryViewMock, times(1)).setMessageVisible(); verify(dictionaryViewMock, times(1)).showResults(list); verifyNoMoreInteractions(dictionaryViewMock); }
@Test public void whenSearchWordAndSuggestionsNotFoundShowNoResults() { List<SozlikDbModel> list = new ArrayList<>(); when(sozlikDaoMock.getTranslation(SOME_WORD)).thenReturn(null); when(sozlikDaoMock.getSuggestions('%' + SOME_WORD + '%')).thenReturn(list); dictionaryPresenter.search(SOME_WORD); verify(dictionaryViewMock, times(1)).showMessage(R.string.suggestion_not_found); verify(dictionaryViewMock, times(1)).setMessageVisible(); verify(dictionaryViewMock, times(1)).showResults(list); verifyNoMoreInteractions(dictionaryViewMock); }
@Test public void whenSearchWordNotFoundAndLessThanMinimalShowNoResults() { dictionaryPresenter.search(BELOW_MIN_WIDTH_WORD); verify(dictionaryViewMock, times(1)).showMessage(R.string.suggestion_not_found); verify(dictionaryViewMock, times(1)).setMessageVisible(); verifyNoMoreInteractions(dictionaryViewMock); }
@Test public void whenSearchWordIsEmptyDoNothing() { dictionaryPresenter.search(""); verifyNoMoreInteractions(dictionaryViewMock); }
@Test public void whenSearchWordFoundShowTranslation() { int id = 1; SozlikDbModel result = new SozlikDbModel(); result.setId(id); when(sozlikDaoMock.getTranslation(SOME_WORD)).thenReturn(result); dictionaryPresenter.search(SOME_WORD); verify(dictionaryViewMock, times(1)).showTranslation(id); verifyNoMoreInteractions(dictionaryViewMock); }