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 |
public class ThreadLocalTest extends JSR166TestCase { |
12 |
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 |
/** |
28 |
* remove causes next access to return initial value |
29 |
*/ |
30 |
public void testRemove() { |
31 |
Integer one = new Integer(1); |
32 |
Integer two = new Integer(2); |
33 |
assertEquals(tl.get(), one); |
34 |
tl.set(two); |
35 |
assertEquals(tl.get(), two); |
36 |
tl.remove(); |
37 |
assertEquals(tl.get(), one); |
38 |
} |
39 |
} |
40 |
|