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  
22  import java.io.File;
23  import java.io.IOException;
24  
25  import org.codehaus.plexus.util.Os;
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertFalse;
29  import static org.junit.jupiter.api.Assertions.assertTrue;
30  import static org.junit.jupiter.api.Assumptions.assumeTrue;
31  
32  
33  /**
34   * Test that validate the solution of MNG-6261 issue
35   *
36   */
37  public class FileModelSourceTest
38  {
39  
40      /**
41       * Test of equals method, of class FileModelSource.
42       */
43      @Test
44      public void testEquals()
45              throws Exception
46      {
47          File tempFile = createTempFile( "pomTest" );
48          FileModelSource instance = new FileModelSource( tempFile );
49  
50          assertFalse( instance.equals( null ) );
51          assertFalse( instance.equals( new Object() ) );
52          assertTrue( instance.equals( instance ) );
53          assertTrue( instance.equals( new FileModelSource( tempFile ) ) );
54      }
55  
56      @Test
57      public void testWindowsPaths()
58              throws Exception
59      {
60          assumeTrue( Os.isFamily( "Windows" ) );
61  
62          File upperCaseFile = createTempFile( "TESTE" );
63          String absolutePath = upperCaseFile.getAbsolutePath();
64          File lowerCaseFile = new File( absolutePath.toLowerCase() );
65  
66          FileModelSource upperCaseFileSource = new FileModelSource( upperCaseFile );
67          FileModelSource lowerCaseFileSource = new FileModelSource( lowerCaseFile );
68  
69          assertTrue( upperCaseFileSource.equals( lowerCaseFileSource ) );
70      }
71  
72      private File createTempFile( String name ) throws IOException
73      {
74          File tempFile = File.createTempFile( name, ".xml" );
75          tempFile.deleteOnExit();
76          return tempFile;
77      }
78  
79  }