View Javadoc

1   package org.apache.maven.plugin.idea;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * @author Dennis Lundberg
26   */
27  public class IdeaMojoTestCase
28      extends TestCase
29  {
30      private IdeaMojo mojo;
31  
32      protected void setUp()
33          throws Exception
34      {
35          mojo = new IdeaMojo();
36      }
37  
38      public void testToRelative()
39      {
40          String relativePath;
41  
42          relativePath = mojo.toRelative( "C:\\dev\\voca\\gateway",
43                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
44          assertEquals( "Test toRelative child, backslash", "parser/gateway-parser.iml", relativePath );
45  
46          relativePath = mojo.toRelative( "C:\\dev\\voca\\gateway\\",
47                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
48          assertEquals( "Test toRelative child, trailing backslash", "parser/gateway-parser.iml", relativePath );
49  
50          relativePath = mojo.toRelative( "C:/dev/voca/gateway",
51                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
52          assertEquals( "Test toRelative child, slash", "parser/gateway-parser.iml", relativePath );
53  
54          relativePath = mojo.toRelative( "C:/dev/voca/gateway/",
55                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
56          assertEquals( "Test toRelative child, trailing slash", "parser/gateway-parser.iml", relativePath );
57  
58          // Tests for MIDEA-102
59          relativePath = mojo.toRelative( "C:\\foo\\master",
60                                          "C:\\foo\\child" );
61          assertEquals( "Test toRelative sibling, no trailing backspace", "../child", relativePath );
62  
63          relativePath = mojo.toRelative( "C:\\foo\\master\\",
64                                          "C:\\foo\\child" );
65          assertEquals( "Test toRelative sibling, first trailing backspace", "../child", relativePath );
66  
67          relativePath = mojo.toRelative( "C:\\foo\\master",
68                                          "C:\\foo\\child\\" );
69          assertEquals( "Test toRelative sibling, second trailing backspace", "../child", relativePath );
70  
71          relativePath = mojo.toRelative( "C:\\foo\\master\\",
72                                          "C:\\foo\\child\\" );
73          assertEquals( "Test toRelative sibling, both trailing backspace", "../child", relativePath );
74  
75          // Tests for MIDEA-103
76          relativePath = mojo.toRelative( "/myproject/myproject",
77                                          "/myproject/myproject-module1/myproject-module1.iml" );
78          assertEquals( "Test parent matches prefix of child, no trailing slash", "../myproject-module1/myproject-module1.iml", relativePath );
79  
80          relativePath = mojo.toRelative( "/myproject/myproject/",
81                                          "/myproject/myproject-module1/myproject-module1.iml" );
82          assertEquals( "Test parent matches prefix of child, trailing slash", "../myproject-module1/myproject-module1.iml", relativePath );
83      }
84  }