### Question:
GrokPatternCompiler { public GrokMatcher compile(final String expression) { Objects.requireNonNull(expression, "expression can't be null"); LOG.info("Starting to compile grok matcher expression : {}", expression); ArrayList<GrokPattern> patterns = new ArrayList<>(); final String regex = compileRegex(expression, patterns); LOG.info("Grok expression compiled to regex : {}", regex); return new GrokMatcher(patterns, regex); } GrokPatternCompiler(final GrokPatternResolver resolver,
                               final boolean namedCapturesOnly); GrokMatcher compile(final String expression);  }### Answer:
@Test public void shouldCompileMatcherGivenSingleGrokPattern() { final GrokMatcher matcher = compiler.compile("%{ISO8601_TIMEZONE}"); Assert.assertNotNull(matcher); Assert.assertEquals("ISO8601_TIMEZONE", matcher.getGrokPattern(0).syntax()); }
@Test public void shouldCompileMatcherGivenMultipleGrokPatterns() { final GrokMatcher matcher = compiler.compile("%{ISO8601_TIMEZONE} %{LOGLEVEL} %{GREEDYDATA}"); Assert.assertNotNull(matcher); Assert.assertNotNull(matcher.getGrokPattern("ISO8601_TIMEZONE")); Assert.assertNotNull(matcher.getGrokPattern("LOGLEVEL")); Assert.assertNotNull(matcher.getGrokPattern("GREEDYDATA")); }
@Test public void shouldCompileMatcherGivenMultipleGrokPatternWithSemantic() { final GrokMatcher matcher = compiler.compile("%{ISO8601_TIMEZONE:timezone}"); Assert.assertNotNull(matcher); Assert.assertEquals("ISO8601_TIMEZONE", matcher.getGrokPattern(0).syntax()); Assert.assertEquals("timezone", matcher.getGrokPattern(0).semantic()); }
@Test public void shouldCompileMatcherGivenMultipleGrokPatternWithSemanticAndType() { final GrokMatcher matcher = compiler.compile("%{ISO8601_TIMEZONE:timezone:integer}"); Assert.assertNotNull(matcher); Assert.assertEquals("ISO8601_TIMEZONE", matcher.getGrokPattern(0).syntax()); Assert.assertEquals("timezone", matcher.getGrokPattern(0).semantic()); Assert.assertEquals(Type.INTEGER, matcher.getGrokPattern(0).type()); }