GroovyExpressionMatcher implements Serializable { public Object run(final Matcher matcher, final IssueBuilder builder, final int lineNumber, final String fileName) { if (compileScriptIfNotYetDone()) { Binding binding = compiled.getBinding(); binding.setVariable("matcher", matcher); binding.setVariable("builder", builder); binding.setVariable("lineNumber", lineNumber); binding.setVariable("fileName", fileName); return runScript(); } return Optional.empty(); } GroovyExpressionMatcher(final String script); Script compile(); @SuppressWarnings("all") Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder, final int lineNumber,
            final String fileName); Object run(final Matcher matcher, final IssueBuilder builder, final int lineNumber, final String fileName);  }
@Test void shouldCreateScriptIfSourceCodeIsValid() { assertThat(createMatcher(TRUE_SCRIPT).run()).isEqualTo(true); assertThat(createMatcher(FALSE_SCRIPT).run()).isEqualTo(false); }
@Test void shouldThrow() { GroovyExpressionMatcher matcher = new GroovyExpressionMatcher(EXCEPTION_PARSER_SCRIPT); assertThat(matcher.run(null, new IssueBuilder(), 0, FILE_NAME)).isEqualTo(Optional.empty()); }
@Test void shouldCreateIssueWithLineNumberAndFileName() { GroovyExpressionMatcher matcher = new GroovyExpressionMatcher( "return builder.setLineStart(lineNumber).setFileName(fileName).buildOptional()"); Object result = matcher.run(null, new IssueBuilder(), 15, FILE_NAME); assertThat(result).isEqualTo(new IssueBuilder().setLineStart(15).setFileName("File.txt").buildOptional()); }