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