View Javadoc
1   package org.apache.maven.plugin.internal;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *  http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import junit.framework.TestCase;
22  import org.apache.maven.execution.DefaultMavenExecutionRequest;
23  import org.apache.maven.execution.MavenExecutionRequest;
24  import org.apache.maven.execution.MavenSession;
25  
26  import java.util.concurrent.CountDownLatch;
27  
28  /**
29   * @author Kristian Rosenvold
30   */
31  public class DefaultLegacySupportTest extends TestCase {
32      final CountDownLatch latch = new CountDownLatch(1);
33      final DefaultLegacySupport defaultLegacySupport = new DefaultLegacySupport();
34  
35      public void testSetSession() throws Exception {
36  
37          MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
38          MavenSession m1 = new MavenSession(null, null, mavenExecutionRequest, null);
39          defaultLegacySupport.setSession(m1);
40  
41          MyRunnable myRunnable = new MyRunnable();
42          Thread thread = new Thread(myRunnable);
43          thread.start();
44  
45          MavenSession m2 = new MavenSession(null, null, mavenExecutionRequest, null);
46          defaultLegacySupport.setSession(m2);
47          latch.countDown();
48          thread.join();
49          assertNull( myRunnable.getSession());
50      }
51  
52  
53      class MyRunnable implements Runnable {
54  
55          private volatile MavenSession session;
56  
57          public void run() {
58              try
59              {
60                  latch.await();
61              }
62              catch (InterruptedException ignore)
63              {
64                  // Test may fail if we get interrupted
65              }
66              session = defaultLegacySupport.getSession();
67          }
68  
69          public MavenSession getSession() {
70              return session;
71          }
72      }
73  
74  }