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;
20  
21  import java.util.List;
22  import java.util.Set;
23  
24  import org.apache.maven.api.services.Lookup;
25  import org.apache.maven.execution.BuildResumptionAnalyzer;
26  import org.apache.maven.execution.BuildResumptionDataRepository;
27  import org.apache.maven.execution.MavenSession;
28  import org.apache.maven.graph.GraphBuilder;
29  import org.apache.maven.internal.impl.DefaultSessionFactory;
30  import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
31  import org.apache.maven.model.Model;
32  import org.apache.maven.model.superpom.SuperPomProvider;
33  import org.apache.maven.plugin.LegacySupport;
34  import org.apache.maven.project.MavenProject;
35  import org.apache.maven.resolver.RepositorySystemSessionFactory;
36  import org.apache.maven.session.scope.internal.SessionScope;
37  import org.apache.maven.settings.Settings;
38  import org.junit.jupiter.api.Test;
39  
40  import static org.junit.jupiter.api.Assertions.assertEquals;
41  import static org.mockito.Mockito.mock;
42  import static org.mockito.Mockito.when;
43  
44  class DefaultMavenProfileValidationTest {
45  
46      @Test
47      void includesProfilesInjectedFromAnUnavailableParentProject() {
48          MavenProject project = new MavenProject();
49          project.getModel().setModelVersion("4.0.0");
50          project.setInjectedProfileIds("org.example:parent:1.0", List.of("parent-profile"));
51  
52          MavenSession session = mock(MavenSession.class);
53          when(session.getProjects()).thenReturn(List.of(project));
54          when(session.getSettings()).thenReturn(new Settings());
55  
56          SuperPomProvider superPomProvider = mock(SuperPomProvider.class);
57          when(superPomProvider.getSuperModel("4.0.0")).thenReturn(new Model());
58  
59          DefaultMaven maven = new DefaultMaven(
60                  mock(Lookup.class),
61                  mock(ExecutionEventCatapult.class),
62                  mock(LegacySupport.class),
63                  mock(SessionScope.class),
64                  mock(RepositorySystemSessionFactory.class),
65                  mock(GraphBuilder.class),
66                  mock(BuildResumptionAnalyzer.class),
67                  mock(BuildResumptionDataRepository.class),
68                  superPomProvider,
69                  mock(DefaultSessionFactory.class),
70                  null);
71  
72          assertEquals(Set.of("parent-profile"), maven.getAllProfiles(session));
73      }
74  }