PatternExtract { public String getText() { if (words == null) { return ""; } return words.stream().map(w -> w.getCoveredText()).collect(Collectors.joining(" ")); } PatternExtract(final Entity from, final Entity to, final int start, final int end); Entity getFrom(); Entity getTo(); int getStart(); int getEnd(); void setWordTokens(final List<WordToken> words); List<WordToken> getWordTokens(); boolean contains(final String documentText, final String... needles); String getCoveredText(final String documentText); String getText(); boolean isEmpty();  }
@Test public void testGetText() { pe.setWordTokens(Collections.singletonList(token)); Assert.assertEquals("token", pe.getText()); pe.setWordTokens(Arrays.asList(token, token)); Assert.assertEquals("token token", pe.getText()); }