1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.apache.maven.lifecycle.internal;
16  
17  import junit.framework.TestCase;
18  import org.apache.maven.lifecycle.Schedule;
19  import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub;
20  import org.apache.maven.plugin.MojoExecution;
21  
22  /**
23   * @author Kristian Rosenvold
24   */
25  public class ExecutionPlanItemTest
26      extends TestCase
27  {
28  
29      public void testSetComplete()
30          throws Exception
31      {
32          ExecutionPlanItem item = createExecutionPlanItem( "testMojo", null );
33          item.setComplete();  // This itself is a valid test
34          assertTrue( item.isDone() );
35      }
36  
37      public void testWaitUntilDone()
38          throws Exception
39      {
40  
41          final ExecutionPlanItem item =
42              createExecutionPlanItem( "testMojo", createExecutionPlanItem( "testMojo2", null ) );
43          new Thread( new Runnable()
44          {
45              public void run()
46              {
47                  item.setComplete();
48              }
49          } ).start();
50          item.waitUntilDone();
51      }
52  
53  
54      public static ExecutionPlanItem createExecutionPlanItem( String mojoDescription, ExecutionPlanItem downStream )
55      {
56          return createExecutionPlanItem( mojoDescription, downStream, null );
57      }
58  
59      public static ExecutionPlanItem createExecutionPlanItem( String mojoDescription, ExecutionPlanItem downStream,
60                                                               Schedule schedule )
61      {
62          return new ExecutionPlanItem( new MojoExecution( MojoExecutorStub.createMojoDescriptor( mojoDescription ) ),
63                                        schedule );
64      }
65  
66  
67  }