View Javadoc
1   package org.apache.maven.lifecycle.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * 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, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.util.List;
19  
20  import org.apache.maven.execution.MavenSession;
21  import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
22  import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
23  import org.junit.jupiter.api.Test;
24  
25  import static org.junit.jupiter.api.Assertions.assertEquals;
26  import static org.junit.jupiter.api.Assertions.assertNotNull;
27  import static org.junit.jupiter.api.Assertions.assertSame;
28  
29  public class BuildListCalculatorTest
30  {
31  
32      @Test
33      public void testCalculateProjectBuilds()
34          throws Exception
35      {
36          LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = getTaskSegmentCalculator();
37          BuildListCalculator buildListCalculator = new BuildListCalculator();
38          final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
39          List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
40          final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
41          final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
42          assertEquals( 3, taskSegments.size(), "Stub data contains 3 segments" );
43          assertEquals( 6, segments.size(), "Stub data contains 6 items" );
44          final ProjectSegment build = segments.get( 0 );
45          assertNotNull( build );
46  
47          for ( ProjectSegment segment : segments )
48          {
49              assertSame( session, segment.getSession() );
50          }
51      }
52  
53      private static LifecycleTaskSegmentCalculator getTaskSegmentCalculator()
54      {
55          return new LifecycleTaskSegmentCalculatorStub();
56      }
57  
58  }