View Javadoc
1   package org.apache.maven.model.building;
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  import java.io.File;
22  import java.io.IOException;
23  import static junit.framework.TestCase.assertFalse;
24  import static junit.framework.TestCase.assertTrue;
25  import org.apache.commons.lang3.SystemUtils;
26  import static org.junit.Assume.assumeTrue;
27  import org.junit.Test;
28  
29  /**
30   * Test that validate the solution of MNG-6261 issue
31   *
32   */
33  public class FileModelSourceTest
34  {
35  
36      /**
37       * Test of equals method, of class FileModelSource.
38       */
39      @Test
40      public void testEquals()
41              throws Exception 
42      {
43          File tempFile = createTempFile( "pomTest" );
44          FileModelSource instance = new FileModelSource( tempFile );
45  
46          assertFalse( instance.equals( null ) );
47          assertFalse( instance.equals( new Object() ) );
48          assertTrue( instance.equals( instance ) );
49          assertTrue( instance.equals( new FileModelSource( tempFile ) ) );
50      }
51  
52      @Test
53      public void testWindowsPaths() 
54              throws Exception 
55      {
56          assumeTrue( SystemUtils.IS_OS_WINDOWS );
57  
58          File upperCaseFile = createTempFile( "TESTE" );
59          String absolutePath = upperCaseFile.getAbsolutePath();
60          File lowerCaseFile = new File( absolutePath.toLowerCase() );
61          
62          FileModelSource upperCaseFileSouce = new FileModelSource( upperCaseFile );
63          FileModelSource lowerCaseFileSouce = new FileModelSource( lowerCaseFile );
64  
65          assertTrue( upperCaseFileSouce.equals( lowerCaseFileSouce ) );        
66      }
67  
68      private File createTempFile( String name ) throws IOException
69      {
70          File tempFile = File.createTempFile( name, ".xml" );
71          tempFile.deleteOnExit();
72          return tempFile;
73      }
74  
75  }