### Question:
AdditionFilter extends TokenFilter { @Override public Token next(Token aToken) throws IOException { Token token = input.next(aToken); if (token == null) return null; String tokenText = new String(token.termBuffer(), 0, token.termLength()); if (position.equals(PREFIX)) tokenText = addition.concat(tokenText); else tokenText = tokenText.concat(addition); token.setTermBuffer(tokenText.toCharArray(), 0, tokenText.length()); return token; } AdditionFilter(TokenStream input, String addition, Integer position); @Override Token next(Token aToken); Integer getPosition(); String getAddition(); static final Integer PREFIX; static final Integer POSTFIX; }### Answer:
@Test public void testNext() throws Exception{ Collection<Token> tokens = new ArrayList<Token>(); tokens.add(newToken("token1", 0, 6)); tokens.add(newToken("token2", 7, 13)); tokens.add(newToken("token3", 14, 20)); tokens.add(newToken("token4", 21, 27)); TokenStream tokenStream = new CollectionTokenStream(tokens); AdditionFilter filter = new AdditionFilter(tokenStream, "prefix_", AdditionFilter.PREFIX); Token nextToken = new Token(); filter.next(nextToken); assertEquals("prefix_token1", new String(nextToken.termBuffer(), 0, nextToken.termLength())); nextToken = filter.next(nextToken); assertEquals("prefix_token2", new String(nextToken.termBuffer(), 0, nextToken.termLength())); nextToken = filter.next(nextToken); assertEquals("prefix_token3", new String(nextToken.termBuffer(), 0, nextToken.termLength())); nextToken = filter.next(nextToken); assertEquals("prefix_token4", new String(nextToken.termBuffer(), 0, nextToken.termLength())); tokens = new ArrayList<Token>(); tokens.add(newToken("token1", 0, 6)); tokens.add(newToken("token2", 7, 13)); tokens.add(newToken("token3", 14, 20)); tokens.add(newToken("token4", 21, 27)); tokenStream = new CollectionTokenStream(tokens); filter = new AdditionFilter(tokenStream, "_postfix", AdditionFilter.POSTFIX); nextToken = filter.next(nextToken); assertEquals("token1_postfix", new String(nextToken.termBuffer(), 0, nextToken.termLength())); nextToken = filter.next(nextToken); assertEquals("token2_postfix", new String(nextToken.termBuffer(), 0, nextToken.termLength())); nextToken = filter.next(nextToken); assertEquals("token3_postfix", new String(nextToken.termBuffer(), 0, nextToken.termLength())); nextToken = filter.next(nextToken); assertEquals("token4_postfix", new String(nextToken.termBuffer(), 0, nextToken.termLength())); }