22
33import com .intellij .openapi .project .Project ;
44import com .intellij .openapi .vfs .VirtualFile ;
5- import org .apache .commons .io .FilenameUtils ;
65import org .junit .Before ;
76import org .junit .Test ;
87
1615public class ProjectFilePathsTest {
1716
1817 private static final String UNIX_PROJECT_BASE_PATH = "/the/base-project/path" ;
19- private static final String WINDOWS_PROJECT_BASE_PATH = "c:/some-where/a-project" ;
2018
2119 private ProjectFilePaths underTest ;
2220
@@ -43,94 +41,6 @@ public void aPathWithNoCommonElementsCanBeMadeProjectRelative() {
4341 is (equalTo (UNIX_PROJECT_BASE_PATH + "/../../../somewhere/else/entirely/another-project/rules.xml" )));
4442 }
4543
46- @ Test
47- public void directoryTraversalsInARelativePathShouldNotBeAlteredByTokenisation () {
48- assertThat (underTest .tokenise (UNIX_PROJECT_BASE_PATH + "/../a-path/to/checkstyle.xml" ),
49- is (equalTo ("$PROJECT_DIR$/../a-path/to/checkstyle.xml" )));
50- }
51-
52- @ Test
53- public void aUnixLocationContainingTheProjectPathShouldBeDetokenisedCorrectly () {
54- assertThat (underTest .detokenise (UNIX_PROJECT_BASE_PATH + "/a-path/to/checkstyle.xml" ),
55- is (equalTo (UNIX_PROJECT_BASE_PATH + "/a-path/to/checkstyle.xml" )));
56- }
57-
58- @ Test
59- public void aUnixLocationContainingTheProjectPathTokenShouldBeDetokenisedCorrectly () {
60- assertThat (underTest .detokenise ("$PROJECT_DIR$/a-path/to/checkstyle.xml" ),
61- is (equalTo (UNIX_PROJECT_BASE_PATH + "/a-path/to/checkstyle.xml" )));
62- }
63-
64- @ Test
65- public void directoryTraversalsInARelativePathShouldNotBeAlteredByDetokenisation () {
66- assertThat (underTest .detokenise (UNIX_PROJECT_BASE_PATH + "/../a-path/to/checkstyle.xml" ),
67- is (equalTo (UNIX_PROJECT_BASE_PATH + "/../a-path/to/checkstyle.xml" )));
68- }
69-
70- @ Test
71- public void aUnixLocationWhereTheProjectPathIsNotUsedShouldBeUnalteredByTokenisation () {
72- assertThat (underTest .tokenise ("/a-volume/a-path/to/checkstyle.xml" ),
73- is (equalTo ("/a-volume/a-path/to/checkstyle.xml" )));
74- }
75-
76- @ Test
77- public void aUnixLocationWhereTheProjectPathIsNotUsedShouldBeUnalteredByDetokenisation () {
78- assertThat (underTest .detokenise ("/a-volume/a-path/to/checkstyle.xml" ),
79- is (equalTo ("/a-volume/a-path/to/checkstyle.xml" )));
80- }
81-
82- @ Test
83- public void aUnixLocationWhereTheProjectPathIsNotUsedAndTheFileExistsInAPartiallyMatchingSiblingDirectoryShouldBeUnalteredByTokenisation () {
84- assertThat (underTest .tokenise (UNIX_PROJECT_BASE_PATH + "-sibling/a-path/to/checkstyle.xml" ),
85- is (equalTo (UNIX_PROJECT_BASE_PATH + "-sibling/a-path/to/checkstyle.xml" )));
86- }
87-
88- @ Test
89- public void aUnixLocationWhereTheProjectPathIsNotUsedAndTheFileExistsInAPartiallyMatchingSiblingDirectoryShouldBeUnalteredByDetokenisation () {
90- assertThat (underTest .detokenise (UNIX_PROJECT_BASE_PATH + "-sibling/a-path/to/checkstyle.xml" ),
91- is (equalTo (UNIX_PROJECT_BASE_PATH + "-sibling/a-path/to/checkstyle.xml" )));
92- }
93-
94- @ Test
95- public void theProjectDirectoryShouldBeTokenisedInDescriptorForWindowsPaths () {
96- underTest = projectFilePathsForWindows ();
97-
98- assertThat (underTest .tokenise ("c:\\ some-where\\ a-project\\ a\\ file\\ location-in\\ checkstyle.xml" ),
99- is (equalTo ("$PROJECT_DIR$/a/file/location-in/checkstyle.xml" )));
100- }
101-
102- @ Test
103- public void aWindowsLocationContainingTheProjectPathTokenShouldBeDetokenisedCorrectly () {
104- underTest = projectFilePathsForWindows ();
105-
106- assertThat (underTest .detokenise ("$PROJECT_DIR$\\ a\\ file\\ location\\ checkstyle.xml" ),
107- is (equalTo ("c:\\ some-where\\ a-project\\ a\\ file\\ location\\ checkstyle.xml" )));
108- }
109-
110- @ Test
111- public void aWindowsLocationContainingTheProjectPathShouldBeDetokenisedCorrectly () {
112- underTest = projectFilePathsForWindows ();
113-
114- assertThat (underTest .detokenise ("c:\\ some-where\\ a-project\\ a\\ file\\ location\\ checkstyle.xml" ),
115- is (equalTo ("c:\\ some-where\\ a-project\\ a\\ file\\ location\\ checkstyle.xml" )));
116- }
117-
118- @ Test
119- public void aWindowsLocationWhereTheProjectPathIsNotUsedShouldNotBeAlteredByTokenisation () {
120- underTest = projectFilePathsForWindows ();
121-
122- assertThat (underTest .tokenise ("c:\\ a\\ file\\ location\\ checkstyle.xml" ),
123- is (equalTo ("c:/a/file/location/checkstyle.xml" )));
124- }
125-
126- @ Test
127- public void aWindowsLocationWhereTheProjectPathIsNotUsedShouldNotBeAlteredByDetokenisation () {
128- underTest = projectFilePathsForWindows ();
129-
130- assertThat (underTest .detokenise ("c:\\ a\\ file\\ location\\ checkstyle.xml" ),
131- is (equalTo ("c:\\ a\\ file\\ location\\ checkstyle.xml" )));
132- }
133-
13444 private ProjectFilePaths projectFilePathsForUnix () {
13545 Project project = mock (Project .class );
13646 VirtualFile projectBaseFile = mock (VirtualFile .class );
@@ -142,22 +52,4 @@ private ProjectFilePaths projectFilePathsForUnix() {
14252 return ProjectFilePaths .testInstanceWith (project , '/' , File ::getAbsolutePath , projectPaths );
14353 }
14454
145- private ProjectFilePaths projectFilePathsForWindows () {
146- Project project = mock (Project .class );
147- VirtualFile projectBaseFile = mock (VirtualFile .class );
148- ProjectPaths projectPaths = mock (ProjectPaths .class );
149-
150- when (projectBaseFile .getPath ()).thenReturn (WINDOWS_PROJECT_BASE_PATH );
151- when (projectPaths .projectPath (project )).thenReturn (projectBaseFile );
152-
153- return ProjectFilePaths .testInstanceWith (project , '\\' , file -> {
154- // a nasty hack to pretend we're on a Windows box when required...
155- if (file .getPath ().startsWith ("c:" )) {
156- return file .getPath ().replace ('/' , '\\' ).replaceAll ("\\ \\ \\ \\ " , "\\ \\ " );
157- }
158-
159- return FilenameUtils .separatorsToUnix (file .getPath ());
160- }, projectPaths );
161- }
162-
16355}
0 commit comments