@Test public void should_fail_with_bad_regular_expression() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("[" + HeaderCheck.class.getSimpleName() + "] Unable to compile the regular expression: *"); HeaderCheck check = new HeaderCheck(); check.headerFormat = "*"; check.isRegularExpression = true; check.init(); }
@Override public void init() { if (isRegularExpression) { try { searchPattern = Pattern.compile(headerFormat, Pattern.DOTALL); } catch (RuntimeException e) { throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e); } } else { expectedLines = headerFormat.split("(?:\r)?\n|\r"); } }
HeaderCheck extends AbstractPageCheck { @Override public void init() { if (isRegularExpression) { try { searchPattern = Pattern.compile(headerFormat, Pattern.DOTALL); } catch (RuntimeException e) { throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e); } } else { expectedLines = headerFormat.split("(?:\r)?\n|\r"); } } }
HeaderCheck extends AbstractPageCheck { @Override public void init() { if (isRegularExpression) { try { searchPattern = Pattern.compile(headerFormat, Pattern.DOTALL); } catch (RuntimeException e) { throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e); } } else { expectedLines = headerFormat.split("(?:\r)?\n|\r"); } }  }
HeaderCheck extends AbstractPageCheck { @Override public void init() { if (isRegularExpression) { try { searchPattern = Pattern.compile(headerFormat, Pattern.DOTALL); } catch (RuntimeException e) { throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e); } } else { expectedLines = headerFormat.split("(?:\r)?\n|\r"); } }  @Override void init(); @Override void startDocument(List<Node> nodes); }
HeaderCheck extends AbstractPageCheck { @Override public void init() { if (isRegularExpression) { try { searchPattern = Pattern.compile(headerFormat, Pattern.DOTALL); } catch (RuntimeException e) { throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e); } } else { expectedLines = headerFormat.split("(?:\r)?\n|\r"); } }  @Override void init(); @Override void startDocument(List<Node> nodes); @RuleProperty(
    key = "headerFormat",
    description = "Expected copyright and license header (plain text)",
    defaultValue = DEFAULT_HEADER_FORMAT,
    type = "TEXT")
  public String headerFormat; @RuleProperty(
    key = "isRegularExpression",
    description = "Whether the headerFormat is a regular expression",
    defaultValue = "false")
  public boolean isRegularExpression; }