ModelValidation { public FormValidation validateJob(final String referenceJobName) { if (NO_REFERENCE_JOB.equals(referenceJobName) || StringUtils.isBlank(referenceJobName) || jenkins.getJob(referenceJobName).isPresent()) { return FormValidation.ok(); } return FormValidation.error(Messages.FieldValidator_Error_ReferenceJobDoesNotExist()); } ModelValidation(); @VisibleForTesting  ModelValidation(final JenkinsFacade jenkins); ComboBoxModel getAllCharsets(); Charset getCharset(@CheckForNull final String charset); void ensureValidId(final String id); FormValidation validateId(final String id); FormValidation validateCharset(final String reportEncoding); ListBoxModel getAllSeverityFilters(); ListBoxModel getAllTrendChartTypes(); ComboBoxModel getAllJobs(); FormValidation validateJob(final String referenceJobName); @SuppressWarnings("WeakerAccess") FormValidation validateThreshold(@QueryParameter final int threshold); FormValidation validateHealthy(final int healthy, final int unhealthy); FormValidation validateUnhealthy(final int healthy, final int unhealthy); FormValidation doCheckPattern(@AncestorInPath final AbstractProject<?, ?> project,
            @QueryParameter final String pattern); FormValidation doCheckSourceDirectory(@AncestorInPath final AbstractProject<?, ?> project,
            @QueryParameter final String sourceDirectory);  }
@Test void doCheckReferenceJobShouldBeOkWithValidValues() { JenkinsFacade jenkins = mock(JenkinsFacade.class); Job<?, ?> job = mock(Job.class); String jobName = "referenceJob"; when(jenkins.getJob(jobName)).thenReturn(Optional.of(job)); ModelValidation model = new ModelValidation(jenkins); assertThat(model.validateJob(jobName)).isOk(); assertThat(model.validateJob(NO_REFERENCE_JOB)).isOk(); assertThat(model.validateJob("")).isOk(); }
@Test void doCheckReferenceJobShouldBeNOkWithInvalidValue() { String referenceJob = "referenceJob"; JenkinsFacade jenkins = mock(JenkinsFacade.class); when(jenkins.getJob(referenceJob)).thenReturn(Optional.empty()); ModelValidation model = new ModelValidation(jenkins); assertThat(model.validateJob(referenceJob)) .isError() .hasMessage("There is no such job - maybe the job has been renamed?"); }