001package org.apache.maven.model.merge; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023import static org.junit.Assert.assertEquals; 024import static org.junit.Assert.assertNull; 025 026import java.util.Collections; 027 028import org.apache.maven.model.Model; 029import org.apache.maven.model.Prerequisites; 030import org.apache.maven.model.Profile; 031import org.junit.Test; 032 033public class MavenModelMergerTest 034{ 035 private MavenModelMerger modelMerger = new MavenModelMerger(); 036 037 // modelVersion is neither inherited nor injected 038 @Test 039 public void testMergeModel_ModelVersion() 040 { 041 Model parent = new Model(); 042 parent.setModelVersion( "4.0.0" ); 043 Model model = new Model(); 044 modelMerger.mergeModel_ModelVersion( model, parent, false, null ); 045 assertNull( model.getModelVersion() ); 046 047 model.setModelVersion( "5.0.0" ); 048 modelMerger.mergeModel_ModelVersion( model, parent, false, null ); 049 assertEquals( "5.0.0", model.getModelVersion() ); 050 } 051 052 // ArtifactId is neither inherited nor injected 053 @Test 054 public void testMergeModel_ArtifactId() 055 { 056 Model parent = new Model(); 057 parent.setArtifactId( "PARENT" ); 058 Model model = new Model(); 059 modelMerger.mergeModel_ArtifactId( model, parent, false, null ); 060 assertNull( model.getArtifactId() ); 061 062 model.setArtifactId( "MODEL" ); 063 modelMerger.mergeModel_ArtifactId( model, parent, false, null ); 064 assertEquals( "MODEL", model.getArtifactId() ); 065 } 066 067 // Prerequisites are neither inherited nor injected 068 @Test 069 public void testMergeModel_Prerequisites() 070 { 071 Model parent = new Model(); 072 parent.setPrerequisites( new Prerequisites() ); 073 Model model = new Model(); 074 modelMerger.mergeModel_Prerequisites( model, parent, false, null ); 075 assertNull( model.getPrerequisites() ); 076 077 Prerequisites modelPrerequisites = new Prerequisites(); 078 modelPrerequisites.setMaven( "3.0" ); 079 model.setPrerequisites( modelPrerequisites ); 080 modelMerger.mergeModel_Prerequisites( model, parent, false, null ); 081 assertEquals( modelPrerequisites, model.getPrerequisites() ); 082 } 083 084 // Profiles are neither inherited nor injected 085 @Test 086 public void testMergeModel_Profiles() 087 { 088 Model parent = new Model(); 089 parent.setProfiles( Collections.singletonList( new Profile() ) );; 090 Model model = new Model(); 091 modelMerger.mergeModel_Profiles( model, parent, false, null ); 092 assertEquals( 0, model.getProfiles().size() ); 093 094 Profile modelProfile = new Profile(); 095 modelProfile.setId( "MODEL" ); 096 model.setProfiles( Collections.singletonList( modelProfile ) ); 097 modelMerger.mergeModel_Prerequisites( model, parent, false, null ); 098 assertEquals( Collections.singletonList( modelProfile ), model.getProfiles() ); 099 } 100 101}