### Question:
SimpleParser implements Serializable { public void parse(String input, SimpleParserCallback callback) { SimpleParserCallbackContext ctx = new SimpleParserCallbackContext(input); callback.documentStarts(); if (tokens.isEmpty()) { ctx.setEndp(input.length()); callback.documentEnds(ctx); return; } Pattern pattern = preparePattern(); Matcher matcher = pattern.matcher(input); int ind = 0; while (matcher.find(ind)) { int start = matcher.start(); String token = matcher.group(); ctx.setEndp(start); callback.tokenFound(ctx, token); ind = start + token.length(); ctx.setStartp(ind); } ctx.setStartp(ind); ctx.setEndp(input.length()); callback.documentEnds(ctx); } SimpleParser(String... tokens); void parse(String input, SimpleParserCallback callback);  }### Answer:
@Test public void parseTest1() { final AtomicInteger tokenCount = new AtomicInteger(0); SimpleParser simpleParser = new SimpleParser("--", " simpleParser.parse(input, new SimpleParserCallback() { public void tokenFound(SimpleParserCallbackContext ctx, String token) { System.out.println("Token " + ("\n".equals(token) ? "NL" : token) + " - " + ctx.getTextBefore() + " :" + ctx); tokenCount.incrementAndGet(); } public void documentStarts() { } public void documentEnds(SimpleParserCallbackContext ctx) { System.out.println("End - " + ctx.getTextBefore()); } }); Assert.assertEquals(20, tokenCount.get()); }