XmlValidatorManager implements ValidatorManager { @Override public Map<String, ValidationReport> validate(final Project project, final File projectDir, final Props additionalProps) { final Props nonNullAdditionalProps = additionalProps == null ? new Props() : additionalProps; final Map<String, ValidationReport> reports = new LinkedHashMap<>(); for (final Entry<String, ProjectValidator> validator : this.validators.entrySet()) { reports.put(validator.getKey(), validator.getValue().validateProject(project, projectDir, nonNullAdditionalProps)); logger.info("Validation status of validator " + validator.getKey() + " is " + reports.get(validator.getKey()).getStatus()); } return reports; } XmlValidatorManager(final Props props); @Override void loadValidators(final Props props, final Logger log); @Override String getCacheKey(final Project project, final File projectDir, final Props props); @Override Map<String, ValidationReport> validate(final Project project, final File projectDir, final Props additionalProps); @Override List<String> getValidatorsInfo(); static final String VALIDATOR_TAG; static final String CLASSNAME_ATTR; static final String ITEM_TAG; }
@Test public void testValidateProjectValidator() throws Exception { final Project project = mock(Project.class); final File projectDir = mock(File.class); final Props props = new Props(); final ProjectValidator mockValidator = mock(ProjectValidator.class); final XmlValidatorManager manager = new XmlValidatorManager(props); final ValidationReport sampleReport = new ValidationReport(); when(mockValidator.validateProject(project, projectDir, props)).thenReturn(sampleReport); Map<String, ProjectValidator> mockedValidators = new HashMap(); mockedValidators.put("TEST", mockValidator); Field validatorsField = manager.getClass().getDeclaredField("validators"); validatorsField.setAccessible(true); FieldSetter.setField(manager, validatorsField, mockedValidators); Map<String, ValidationReport> expectedResultingReports = new HashMap(); expectedResultingReports.put("TEST", sampleReport); assertEquals(expectedResultingReports, manager.validate(project, projectDir, props)); }