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