Search in sources :

Example 1 with ProjectFilePaths

use of org.infernus.idea.checkstyle.util.ProjectFilePaths in project checkstyle-idea by jshiell.

the class RelativeFileConfigurationLocationTest method setUp.

@Before
public void setUp() {
    ProjectPaths projectPaths = mock(ProjectPaths.class);
    Function<File, String> absolutePathOf = file -> {
        // a nasty hack to pretend we're on a Windows box when required...
        if (file.getPath().startsWith("c:")) {
            return file.getPath().replace('/', '\\').replaceAll("\\\\\\\\", "\\\\");
        }
        return FilenameUtils.separatorsToUnix(file.getPath());
    };
    ProjectFilePaths testProjectFilePaths = new ProjectFilePaths(project, '/', absolutePathOf, projectPaths);
    when(project.getService(ProjectFilePaths.class)).thenReturn(testProjectFilePaths);
    when(projectBase.getPath()).thenReturn(PROJECT_BASE_PATH);
    when(projectPaths.projectPath(project)).thenReturn(projectBase);
    underTest = new RelativeFileConfigurationLocation(project);
    underTest.setLocation("aLocation");
    underTest.setDescription("aDescription");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) ProjectPaths(org.infernus.idea.checkstyle.util.ProjectPaths) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Function(java.util.function.Function) File(java.io.File) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Project(com.intellij.openapi.project.Project) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) FilenameUtils(org.apache.commons.io.FilenameUtils) ProjectFilePaths(org.infernus.idea.checkstyle.util.ProjectFilePaths) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ProjectPaths(org.infernus.idea.checkstyle.util.ProjectPaths) ProjectFilePaths(org.infernus.idea.checkstyle.util.ProjectFilePaths) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Before(org.junit.Before)

Example 2 with ProjectFilePaths

use of org.infernus.idea.checkstyle.util.ProjectFilePaths in project checkstyle-idea by jshiell.

the class ConfigurationLocationTest method testSorting.

@Test
public void testSorting() {
    final Project project = mock(Project.class);
    when(project.getService(ProjectFilePaths.class)).thenReturn(new ProjectFilePaths(project));
    List<ConfigurationLocation> list = new ArrayList<>();
    FileConfigurationLocation fcl = new FileConfigurationLocation(project, ConfigurationType.LOCAL_FILE);
    fcl.setDescription("descB");
    fcl.setLocation("locB");
    list.add(fcl);
    RelativeFileConfigurationLocation rfcl1 = new RelativeFileConfigurationLocation(project);
    rfcl1.setDescription("descA");
    rfcl1.setLocation("locA");
    list.add(rfcl1);
    list.add(new BundledConfigurationLocation(BundledConfig.SUN_CHECKS, project));
    RelativeFileConfigurationLocation rfcl2 = new RelativeFileConfigurationLocation(project);
    rfcl2.setDescription("descC");
    rfcl2.setLocation("locC");
    list.add(rfcl2);
    list.add(new BundledConfigurationLocation(BundledConfig.GOOGLE_CHECKS, project));
    Collections.sort(list);
    assertEquals(BundledConfigurationLocation.class, list.get(0).getClass());
    assertTrue(list.get(0).getDescription().contains("Sun Checks"));
    assertTrue(list.contains(new BundledConfigurationLocation(BundledConfig.SUN_CHECKS, project)));
    assertEquals(BundledConfigurationLocation.class, list.get(1).getClass());
    assertTrue(list.get(1).getDescription().contains("Google Checks"));
    assertTrue(list.contains(new BundledConfigurationLocation(BundledConfig.GOOGLE_CHECKS, project)));
    assertEquals(RelativeFileConfigurationLocation.class, list.get(2).getClass());
    assertEquals("descA", list.get(2).getDescription());
    assertEquals(FileConfigurationLocation.class, list.get(3).getClass());
    assertEquals("descB", list.get(3).getDescription());
    assertEquals(RelativeFileConfigurationLocation.class, list.get(4).getClass());
    assertEquals("descC", list.get(4).getDescription());
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFilePaths(org.infernus.idea.checkstyle.util.ProjectFilePaths) Test(org.junit.Test)

Example 3 with ProjectFilePaths

use of org.infernus.idea.checkstyle.util.ProjectFilePaths in project checkstyle-idea by jshiell.

the class FileConfigurationLocationTest method useWindowsFilePaths.

private FileConfigurationLocation useWindowsFilePaths() {
    reset(project);
    ProjectFilePaths testProjectFilePaths = testProjectFilePaths('\\');
    when(project.getService(ProjectFilePaths.class)).thenReturn(testProjectFilePaths);
    when(projectPaths.projectPath(project)).thenReturn(projectBase);
    when(projectPaths.projectPath(project)).thenReturn(projectBase);
    when(projectBase.getPath()).thenReturn("c:/some-where/a-project");
    return new FileConfigurationLocation(project);
}
Also used : ProjectFilePaths(org.infernus.idea.checkstyle.util.ProjectFilePaths)

Example 4 with ProjectFilePaths

use of org.infernus.idea.checkstyle.util.ProjectFilePaths in project checkstyle-idea by jshiell.

the class FileConfigurationLocationTest method useUnixPaths.

private FileConfigurationLocation useUnixPaths() {
    reset(project);
    ProjectFilePaths testProjectFilePaths = testProjectFilePaths('/');
    when(project.getService(ProjectFilePaths.class)).thenReturn(testProjectFilePaths);
    when(projectPaths.projectPath(project)).thenReturn(projectBase);
    when(projectBase.getPath()).thenReturn(PROJECT_BASE_PATH);
    return new FileConfigurationLocation(project);
}
Also used : ProjectFilePaths(org.infernus.idea.checkstyle.util.ProjectFilePaths)

Aggregations

ProjectFilePaths (org.infernus.idea.checkstyle.util.ProjectFilePaths)4 Project (com.intellij.openapi.project.Project)2 Test (org.junit.Test)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 Function (java.util.function.Function)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Matchers.is (org.hamcrest.Matchers.is)1 ProjectPaths (org.infernus.idea.checkstyle.util.ProjectPaths)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 Mock (org.mockito.Mock)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1