use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveProjectLocation.
/**
* Verifies that {@link LocationResolver#resolve(Location, IProject)} resolves the location in a project context
* correctly.
*/
@Test
public void resolveProjectLocation() throws URISyntaxException {
final Location location = new Location("path/pmd.xml", LocationContext.PROJECT);
final IProject project = mock(IProject.class);
when(project.getLocationURI()).thenReturn(new URI("file:///workspace/project/"));
final String result = LocationResolver.resolve(location, project);
assertEquals("The resolved location should be the project's path with the location's path appended", Paths.get("/workspace", "project", "path", "pmd.xml"), Paths.get(result));
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsFileSystemLocationWithMissingFile.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not resolve the loacation in a
* file system context when the file is mossing.
*/
@Test
public void resolveIfExistsFileSystemLocationWithMissingFile() {
final Location location = new Location("/tmp/pmd.xml", LocationContext.FILE_SYSTEM);
final IProject project = mock(IProject.class);
final Optional<String> result = LocationResolver.resolveIfExists(location, project);
assertFalse("The location should not resolve", result.isPresent());
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsWorkspaceLocationWithMissingProject.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
* workspace context if the project does not exist.
*/
@Test
public void resolveIfExistsWorkspaceLocationWithMissingProject() {
final Location location = new Location("MissingProject/pmd.xml", LocationContext.WORKSPACE);
final IProject project = mock(IProject.class);
final IWorkspace workspace = mock(IWorkspace.class);
final IWorkspaceRoot workspaceRoot = mock(IWorkspaceRoot.class);
when(project.getWorkspace()).thenReturn(workspace);
when(workspace.getRoot()).thenReturn(workspaceRoot);
when(workspaceRoot.getProject("MissingProject")).thenReturn(project);
when(project.getLocationURI()).thenReturn(null);
final Optional<String> result = LocationResolver.resolveIfExists(location, project);
assertFalse("The location should not resolve", result.isPresent());
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveFileSystemLocation.
/**
* Verifies that {@link LocationResolver#resolve(Location, IProject)} resolves the location in a file system context
* correctly.
*/
@Test
public void resolveFileSystemLocation() {
final Location location = new Location("/some/path/pmd.xml", LocationContext.FILE_SYSTEM);
final IProject project = mock(IProject.class);
final String result = LocationResolver.resolve(location, project);
assertEquals("The resolved location should just be the path", "/some/path/pmd.xml", result);
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class RuleSetsCacheTest method secondGetLoadsWhenProjectRuleSetsWereChanged.
/**
* Verifies that the second cache access loads the rule sets if the project model's rule sets have been changed
* after the first access.
*/
@Test
public void secondGetLoadsWhenProjectRuleSetsWereChanged() throws Exception {
final WorkspaceModel workspaceModel = getWorkspaceModel();
final RuleSetsCache cache = new RuleSetsCache(getCacheLoaderMock(), workspaceModel);
cache.getRuleSets(PROJECT_NAME_1);
final RuleSetModel ruleSetModel = new RuleSetModel("abc", new Location("path", LocationContext.WORKSPACE));
workspaceModel.getOrCreateProject(PROJECT_NAME_1).setRuleSets(Arrays.asList(ruleSetModel));
final RuleSets actualRuleSets = cache.getRuleSets(PROJECT_NAME_1);
assertSame("Second cache access should reload rule sets", RULE_SETS_FOO_2, actualRuleSets);
}
Aggregations