ZipParser extends AbstractRegexParser { @Override public void parse(ParseContext parseContext) { Chunk currentChunk = parseContext.getCurrent(); Matcher matcher = ZIP.matcher(currentChunk.getText()); if(!matcher.matches()) { patternNotMatched(parseContext, ZIP); return; } MatchBuilder builder = new MatchBuilder(); builder.add(matcher) .add(parseContext) .add(MatchType.END_OF_INPUT) .add(ZIP,1, TokenType.ZIP) .add(ZIP,2,TokenType.PLUS4); handleMatch(builder.build(), ChunkType.COUNTY); }  @Override void parse(ParseContext parseContext);  }
@Test public void testParseSuccessChangesCurrentChunk() { String originalText = "280 Riverside Dr NY NY 10025 "; ParseContext context = new ParseContext(new Input("zip-chunk-state-change1", originalText)); Chunk initialChunk = context.getCurrent(); assertThat(initialChunk.getType()).isEqualTo(ChunkType.ORIGINAL_INPUT); parser.parse(context); assertThat(context.isParsed()).isFalse().as("ParseContext.isParsed should be"); assertThat(initialChunk.getType()).isEqualTo(ChunkType.COUNTY).as("Chunk.Type of initial Chunk:"); assertThat(initialChunk.contains(new Token(TokenType.ZIP, "10025", 23, 28))).isTrue().as("Initial Chunk contains:"); assertThat(initialChunk.tokenCount()).isEqualTo(1).as("Initial Chunk token count:"); Chunk actualChunk = context.getCurrent(); assertThat(actualChunk.getType()).isEqualTo(ChunkType.SUBSTRING); assertThat(actualChunk.getText()).isEqualTo("280 Riverside Dr NY NY"); }