KeywordCollection implements Iterable<KeywordInfo> { public double getAverageScore() { double sum = 0; for (KeywordInfo keywordInfo : keywords.values()) { if (keywordInfo.hasScore()) { sum += keywordInfo.getScore(); } } return keywords.isEmpty() ? 0.0 : sum / keywords.size(); } KeywordCollection(CampaignConfiguration campaignConfiguration); void add(KeywordInfo info); void addAll(Collection<KeywordInfo> infos); int size(); boolean contains(Keyword keyword); Set<Keyword> getKeywords(); CampaignConfiguration getCampaignConfiguration(); Set<String> getContainingKeywordTexts(); Set<KeywordMatchType> getContainingMatchTypes(); List<KeywordInfo> getListSortedByScore(); List<KeywordInfo> getListSortedByKeyword(); KeywordCollection getBest(int count); double getAverageScore(); @Override Iterator<KeywordInfo> iterator(); @Override String toString();  }
@Test public void averageZeroNotDivideByZero() { KeywordCollection collection = new KeywordCollection(campaignSettings); assertEquals("Expected 0", collection.getAverageScore(), 0.0, 0.0001); }