1 |
dl |
1.1 |
/* |
2 |
|
|
* Written by members of JCP JSR-166 Expert Group and released to the |
3 |
|
|
* public domain. Use, modify, and redistribute this code in any way |
4 |
|
|
* without acknowledgement. Other contributors include Andrew Wright, |
5 |
|
|
* Jeffrey Hayes, Pat Fischer, Mike Judd. |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
import junit.framework.*; |
9 |
|
|
import java.util.concurrent.Semaphore; |
10 |
|
|
|
11 |
dl |
1.2 |
public class ThreadLocalTest extends JSR166TestCase { |
12 |
dl |
1.1 |
public static void main(String[] args) { |
13 |
|
|
junit.textui.TestRunner.run(suite()); |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
public static Test suite() { |
17 |
|
|
return new TestSuite(ThreadLocalTest.class); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
static ThreadLocal tl = new ThreadLocal() { |
21 |
|
|
public Object initialValue() { |
22 |
|
|
return new Integer(1); |
23 |
|
|
} |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
|
|
27 |
|
|
public void testRemove() { |
28 |
|
|
Integer one = new Integer(1); |
29 |
|
|
Integer two = new Integer(2); |
30 |
|
|
assertEquals(tl.get(), one); |
31 |
|
|
tl.set(two); |
32 |
|
|
assertEquals(tl.get(), two); |
33 |
|
|
tl.remove(); |
34 |
|
|
assertEquals(tl.get(), one); |
35 |
|
|
} |
36 |
|
|
} |
37 |
|
|
|