### Question:
BuildMonitorDescriptor extends ViewDescriptor { public FormValidation doCheckIncludeRegex(@QueryParameter String value) { String v = Util.fixEmpty(value); if (v != null) { try { Pattern.compile(v); } catch (PatternSyntaxException pse) { return FormValidation.error(pse.getMessage()); } } return FormValidation.ok(); } BuildMonitorDescriptor(); @Override String getDisplayName(); FormValidation doCheckIncludeRegex(@QueryParameter String value); @Override boolean configure(StaplerRequest req, JSONObject json); boolean getPermissionToCollectAnonymousUsageStatistics(); @SuppressWarnings("unused") // used in global.jelly void setPermissionToCollectAnonymousUsageStatistics(boolean collect);  }### Answer:
@Test public void form_validator_should_allow_valid_reg_ex_specifying_what_jobs_to_include() throws Exception { for (String regex : asFollows(null, "", ".*", "myproject-.*")) { assertThat(itShouldAllow(regex), validator.doCheckIncludeRegex(regex).kind, is(OK)); } }
@Test public void form_validator_should_advise_how_a_regex_could_be_improved() throws Exception { FormValidation result = validator.doCheckIncludeRegex(")"); assertThat(result.kind, is(ERROR)); assertThat(htmlDecoded(result.getMessage()), containsString("Unmatched closing ')'")); }