FileNameCheck extends SubscriptionVisitorCheck { @VisibleForTesting public void setFormat(String format) { this.format = format; }  @Override List<Tree.Kind> nodesToVisit(); @Override void visitFile(Tree tree); @Override void validateParameters(); @VisibleForTesting void setFormat(String format); static final String DEFAULT; }
@Test public void should_follow_a_custom_naming_convention_and_not_raise_an_issue() { FileNameCheck check = new FileNameCheck(); check.setFormat("^[a-z][-a-z]+\\.json$"); JSONCheckVerifier.verify(check, CheckTestUtils.getTestFile("sample.json")) .noMore(); }
@Test public void should_not_follow_a_custom_naming_convention_and_raise_an_issue() { FileNameCheck check = new FileNameCheck(); check.setFormat("^[a-z]+\\.json$"); JSONCheckVerifier.verify(check, CheckTestUtils.getTestFile("file-name.ko.json")) .next().withMessage("Rename this file to match this regular expression: ^[a-z]+\\.json$") .noMore(); }
@Test public void should_throw_an_illegal_state_exception_as_the_format_parameter_regular_expression_is_not_valid() { try { FileNameCheck check = new FileNameCheck(); check.setFormat("("); JSONCheckVerifier.verify(check, CheckTestUtils.getTestFile("sample.json")).noMore(); } catch (IllegalStateException e) { assertThat(e.getMessage()).isEqualTo("Check json:S1578 (File names should comply with a naming convention): " + "format parameter \"(\" is not a valid regular expression."); } }