001    package org.apache.maven.lifecycle.internal;
002    /*
003     * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
004     * agreements. See the NOTICE file distributed with this work for additional information regarding
005     * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
006     * "License"); you may not use this file except in compliance with the License. You may obtain a
007     * copy of the License at
008     *
009     * http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software distributed under the License
012     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
013     * or implied. See the License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    import junit.framework.TestCase;
017    import org.apache.maven.lifecycle.MavenExecutionPlan;
018    import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
019    import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
020    import org.apache.maven.plugin.MojoExecution;
021    
022    import java.util.List;
023    
024    /**
025     * @author Kristian Rosenvold
026     */
027    public class PhaseRecorderTest extends TestCase
028    {
029        public void testObserveExecution() throws Exception {
030            PhaseRecorder phaseRecorder = new PhaseRecorder( ProjectDependencyGraphStub.A);
031            MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
032            final List<MojoExecution> executions = plan.getMojoExecutions();
033    
034            final MojoExecution mojoExecution1 = executions.get( 0 );
035            final MojoExecution mojoExecution2 = executions.get( 1 );
036            phaseRecorder.observeExecution( mojoExecution1 );
037    
038            assertTrue( ProjectDependencyGraphStub.A.hasLifecyclePhase( mojoExecution1.getLifecyclePhase() ));
039            assertFalse( ProjectDependencyGraphStub.A.hasLifecyclePhase( mojoExecution2.getLifecyclePhase() ));
040    
041            assertFalse( phaseRecorder.isDifferentPhase( mojoExecution1));
042            assertTrue( phaseRecorder.isDifferentPhase( mojoExecution2));
043    
044        }
045    
046    }