CommonSimilarWordCalculator implements Serializable { public int calcSimilarWordNumber(List<String> findWords, List<String> inWords) { Preconditions.checkNotNull(findWords); Preconditions.checkNotNull(inWords); int similarWordCount = 0; for (String word : findWords) { if (similarityChecker.containsSimilarString(inWords, word, minWordSimilarity)) { ++similarWordCount; } } return similarWordCount; } CommonSimilarWordCalculator(double minWordSimilarity); int calcSimilarWordNumber(List<String> findWords, List<String> inWords); double calcSimilarWordRatio(List<String> findWords, List<String> inWords); void setMinWordSimilarity(float minWordSimilarity); void setSimilarityChecker(StringSimilarityChecker similarityChecker); @Override String toString();  }
@Test(expected = NullPointerException.class) public void calcSimilarWordNumber_FindWords_NULL() { calculator.calcSimilarWordNumber(null, ImmutableList.of("A")); }
@Test(expected = NullPointerException.class) public void calcSimilarWordNumber_InWords_NULL() { calculator.calcSimilarWordNumber(ImmutableList.of("A"), null); }
@Test public void calcSimilarWordNumber() { List<String> findWords = ImmutableList.of("electronics", "department", "university", "warsaw"); when(similarityChecker.containsSimilarString(inWords, "electronics", MIN_WORD_SIMILARITY)).thenReturn(false); when(similarityChecker.containsSimilarString(inWords, "departments", MIN_WORD_SIMILARITY)).thenReturn(false); when(similarityChecker.containsSimilarString(inWords, "university", MIN_WORD_SIMILARITY)).thenReturn(true); when(similarityChecker.containsSimilarString(inWords, "warsaw", MIN_WORD_SIMILARITY)).thenReturn(true); int numberOfSimilarWords = calculator.calcSimilarWordNumber(findWords, inWords); assertEquals(2, numberOfSimilarWords); }