1 package org.apache.maven.plugin.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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
65 }
66 session = defaultLegacySupport.getSession();
67 }
68
69 public MavenSession getSession() {
70 return session;
71 }
72 }
73
74 }