WordCountService { public int getEnglishWordCount(String string) { int wordCount = 0; BreakIterator wordBreakIterator = BreakIterator.getWordInstance(Locale.ENGLISH); wordBreakIterator.setText(string); int start = wordBreakIterator.first(); int end = wordBreakIterator.next(); while (end != BreakIterator.DONE) { if (Character.isLetterOrDigit(string.charAt(start))) { wordCount += 1; } start = end; end = wordBreakIterator.next(); } return wordCount; }  int getEnglishWordCount(String string);  }
@Test public void testGetEnglishWordCount() { String string = ""; WordCountService instance = new WordCountService(); int expResult = 0; int result = instance.getEnglishWordCount(string); assertEquals(expResult, result); }
@Test public void testGetEnglishWordCountOne() { String string = "one"; WordCountService instance = new WordCountService(); int expResult = 1; int result = instance.getEnglishWordCount(string); assertEquals(expResult, result); }
@Test public void testGetEnglishWordCountMany() { String string = "many words in a sentence. second sentence"; WordCountService instance = new WordCountService(); int expResult = 7; int result = instance.getEnglishWordCount(string); assertEquals(expResult, result); }
@Test public void testGetEnglishWordCountPlacehodler() { String string = "{1} words"; WordCountService instance = new WordCountService(); int expResult = 2; int result = instance.getEnglishWordCount(string); assertEquals(expResult, result); }
@Test public void testGetEnglishWordCountComplexPlacehodler() { String string = "{numberOfSelectedRepositories, plural, =0{Repositories} =1{1 repository} other{# repositories}}"; WordCountService instance = new WordCountService(); int expResult = 9; int result = instance.getEnglishWordCount(string); assertEquals(expResult, result); }