Search in sources :

Example 1 with ValidationResult

use of ch.acanda.eclipse.pmd.ui.model.ValidationResult in project eclipse-pmd by acanda.

the class AddRuleSetConfigurationModelTest method validateWorkspaceConfigurationWithProjectOutsideWorkspace.

/**
 * Verifies that a rule set configuration in a project outside of the workspace does not produce an error in the
 * "Add Rule Set Configuration" wizard.
 */
@Test
public void validateWorkspaceConfigurationWithProjectOutsideWorkspace() throws IOException {
    final Path ruleSetFile = createRuleSetFile();
    final IProject project = mock(IProject.class);
    final IWorkspace workspace = mock(IWorkspace.class);
    final IWorkspaceRoot root = mock(IWorkspaceRoot.class);
    when(project.getWorkspace()).thenReturn(workspace);
    when(workspace.getRoot()).thenReturn(root);
    when(root.getProject(anyString())).thenReturn(project);
    when(project.getLocationURI()).thenReturn(ruleSetFile.getParent().toUri());
    final AddRuleSetConfigurationModel model = new AddRuleSetConfigurationModel(project);
    model.setWorkspaceTypeSelected(true);
    model.setName("X");
    model.setLocation("ProjectX/" + ruleSetFile.getName(ruleSetFile.getNameCount() - 1));
    final ValidationResult validationResult = new ValidationResult();
    model.validate(AddRuleSetConfigurationModel.LOCATION, validationResult);
    if (validationResult.hasErrors()) {
        final String msg = "The validation should not result in any errors " + "if the project is located outside the workspace. First error: ";
        fail(msg + validationResult.getFirstErrorMessage());
    }
}
Also used : Path(java.nio.file.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) Matchers.anyString(org.mockito.Matchers.anyString) ValidationResult(ch.acanda.eclipse.pmd.ui.model.ValidationResult) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

ValidationResult (ch.acanda.eclipse.pmd.ui.model.ValidationResult)1 Path (java.nio.file.Path)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1