View Javadoc
1   package org.apache.maven.model.merge;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *  http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNull;
25  
26  import java.util.Collections;
27  
28  import org.apache.maven.model.Model;
29  import org.apache.maven.model.Prerequisites;
30  import org.apache.maven.model.Profile;
31  import org.junit.Test;
32  
33  public class MavenModelMergerTest
34  {
35      private MavenModelMerger modelMerger = new MavenModelMerger();
36  
37      // modelVersion is neither inherited nor injected
38      @Test
39      public void testMergeModel_ModelVersion()
40      {
41          Model parent = new Model();
42          parent.setModelVersion( "4.0.0" );
43          Model model = new Model();
44          modelMerger.mergeModel_ModelVersion( model, parent, false, null );
45          assertNull( model.getModelVersion() );
46  
47          model.setModelVersion( "5.0.0" );
48          modelMerger.mergeModel_ModelVersion( model, parent, false, null );
49          assertEquals( "5.0.0", model.getModelVersion() );
50      }
51  
52      // ArtifactId is neither inherited nor injected
53      @Test
54      public void testMergeModel_ArtifactId()
55      {
56          Model parent = new Model();
57          parent.setArtifactId( "PARENT" );
58          Model model = new Model();
59          modelMerger.mergeModel_ArtifactId( model, parent, false, null );
60          assertNull( model.getArtifactId() );
61  
62          model.setArtifactId( "MODEL" );
63          modelMerger.mergeModel_ArtifactId( model, parent, false, null );
64          assertEquals( "MODEL", model.getArtifactId() );
65      }
66  
67      // Prerequisites are neither inherited nor injected
68      @Test
69      public void testMergeModel_Prerequisites()
70      {
71          Model parent = new Model();
72          parent.setPrerequisites( new Prerequisites() );
73          Model model = new Model();
74          modelMerger.mergeModel_Prerequisites( model, parent, false, null );
75          assertNull( model.getPrerequisites() );
76          
77          Prerequisites modelPrerequisites = new Prerequisites();
78          modelPrerequisites.setMaven( "3.0" );
79          model.setPrerequisites( modelPrerequisites );
80          modelMerger.mergeModel_Prerequisites( model, parent, false, null );
81          assertEquals( modelPrerequisites, model.getPrerequisites() );
82      }
83  
84      // Profiles are neither inherited nor injected
85      @Test
86      public void testMergeModel_Profiles()
87      {
88          Model parent = new Model();
89          parent.setProfiles( Collections.singletonList( new Profile() ) );;
90          Model model = new Model();
91          modelMerger.mergeModel_Profiles( model, parent, false, null );
92          assertEquals( 0, model.getProfiles().size() );
93          
94          Profile modelProfile = new Profile();
95          modelProfile.setId( "MODEL" );
96          model.setProfiles( Collections.singletonList( modelProfile ) );
97          modelMerger.mergeModel_Prerequisites( model, parent, false, null );
98          assertEquals( Collections.singletonList( modelProfile ), model.getProfiles() );
99      }
100 
101 }