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  import java.io.File;
25  
26  /**
27   * @author Dennis Lundberg
28   */
29  public class IdeaMojoTestCase
30      extends TestCase
31  {
32      private IdeaMojo mojo;
33  
34      protected void setUp()
35          throws Exception
36      {
37          mojo = new IdeaMojo();
38      }
39  
40      public void testToRelative()
41      {
42          String relativePath;
43  
44          relativePath = mojo.toRelative( "C:\\dev\\voca\\gateway",
45                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
46          assertEquals( "Test toRelative child, backslash", "parser/gateway-parser.iml", relativePath );
47  
48          relativePath = mojo.toRelative( "C:\\dev\\voca\\gateway\\",
49                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
50          assertEquals( "Test toRelative child, trailing backslash", "parser/gateway-parser.iml", relativePath );
51  
52          relativePath = mojo.toRelative( "C:/dev/voca/gateway",
53                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
54          assertEquals( "Test toRelative child, slash", "parser/gateway-parser.iml", relativePath );
55  
56          relativePath = mojo.toRelative( "C:/dev/voca/gateway/",
57                                          "C:/dev/voca/gateway/parser/gateway-parser.iml" );
58          assertEquals( "Test toRelative child, trailing slash", "parser/gateway-parser.iml", relativePath );
59  
60          // Tests for MIDEA-102
61          relativePath = mojo.toRelative( "C:\\foo\\master",
62                                          "C:\\foo\\child" );
63          assertEquals( "Test toRelative sibling, no trailing backspace", "../child", relativePath );
64  
65          relativePath = mojo.toRelative( "C:\\foo\\master\\",
66                                          "C:\\foo\\child" );
67          assertEquals( "Test toRelative sibling, first trailing backspace", "../child", relativePath );
68  
69          relativePath = mojo.toRelative( "C:\\foo\\master",
70                                          "C:\\foo\\child\\" );
71          assertEquals( "Test toRelative sibling, second trailing backspace", "../child", relativePath );
72  
73          relativePath = mojo.toRelative( "C:\\foo\\master\\",
74                                          "C:\\foo\\child\\" );
75          assertEquals( "Test toRelative sibling, both trailing backspace", "../child", relativePath );
76  
77          // Tests for MIDEA-103
78          relativePath = mojo.toRelative( "/myproject/myproject",
79                                          "/myproject/myproject-module1/myproject-module1.iml" );
80          assertEquals( "Test parent matches prefix of child, no trailing slash", "../myproject-module1/myproject-module1.iml", relativePath );
81  
82          relativePath = mojo.toRelative( "/myproject/myproject/",
83                                          "/myproject/myproject-module1/myproject-module1.iml" );
84          assertEquals( "Test parent matches prefix of child, trailing slash", "../myproject-module1/myproject-module1.iml", relativePath );
85      }
86  }