SimpleAnalyser implements Analyser { @Override public AnalysisResult analyse(final String text, final String name) { List<String> lines = splitToList(text); Map<String, WordUse> map = IntStream.range(0, lines.size()) .parallel() .boxed() .flatMap(i -> lineRecords(lines, i)) .collect(groupingBy(AnalysisRecord::getNormalised, new AnalysisCollector())); List<WordUse> uses = map.values().stream() .sorted(WordStreamTool.WORD_COMPARATOR) .collect(toList()); return new AnalysisResult(name, uses, lines); }  @Override AnalysisResult analyse(final String text, final String name);  }
@Test public void testName() { AnalysisResult result = analyse(); assertEquals(NAME, result.getName(), "Name"); }
@Test public void testEmpty() { AnalysisResult result = analyse(); assertTrue(result.getOrderedUses().isEmpty(), "Uses"); }
@Test public void testSingle() { AnalysisResult result = analyse(WORD_1); validate(result, use(WORD_1, 1, LineReference.FIRST)); }
@Test public void testMulti() { AnalysisResult result = analyse(LINE_1, LINE_2); validate(result, use(WORD_1, 3, LineReference.FIRST, LineReference.SECOND), use(WORD_3, 2, LineReference.SECOND), use(WORD_2, 2, LineReference.FIRST)); }
@Test public void testExtraSpaces() { AnalysisResult result = analyse(LINE_WITH_SPACES); validate(result, use(WORD_1, 1, LineReference.FIRST), use(WORD_3, 1, LineReference.FIRST), use(WORD_2, 1, LineReference.FIRST)); }
@Test public void testSpanish() { AnalysisResult result = analyse(LINE_WITH_ACCENTS); validate(result, use(SPANISH_1, 1, LineReference.FIRST), use(SPANISH_2, 1, LineReference.FIRST), use(SPANISH_4, 1, LineReference.FIRST), use(SPANISH_3, 1, LineReference.FIRST)); }
@Test public void testMixedCase() { AnalysisResult result = analyse(UPPER_CASE, LOWER_CASE); validate(result, use(LOWER_CASE, 2, LineReference.FIRST, LineReference.SECOND)); }
@Test public void testLowerCase() { AnalysisResult result = analyse(LOWER_CASE, LOWER_CASE); validate(result, use(LOWER_CASE, 2, LineReference.FIRST, LineReference.SECOND)); }
@Test public void testUpperCase() { AnalysisResult result = analyse(UPPER_CASE, UPPER_CASE); validate(result, use(UPPER_CASE, 2, LineReference.FIRST, LineReference.SECOND)); }
@Test public void testUpperUpper() { AnalysisResult result = analyse(UPPER_UPPER); validate(result, use(UPPER_CASE, 2, LineReference.FIRST)); }
@Test public void testUpperLower() { AnalysisResult result = analyse(UPPER_LOWER); validate(result, use(LOWER_CASE, 2, LineReference.FIRST)); }
@Test public void testLowerLower() { AnalysisResult result = analyse(LOWER_LOWER); validate(result, use(LOWER_CASE, 2, LineReference.FIRST)); }