FileDocCategorySizeDatePackage
ThreadLocalTest.javaAPI DocAndroid 1.5 API3090Wed May 06 22:41:02 BST 2009tests.api.java.util.concurrent

ThreadLocalTest

public class ThreadLocalTest extends JSR166TestCase

Fields Summary
static ThreadLocal
tl
static InheritableThreadLocal
itl
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run(suite());        
    
public static junit.framework.Testsuite()

        return new TestSuite(ThreadLocalTest.class);
    
public voidtestGenericITL()
InheritableThreadLocal propagates generic values.

        final int threadCount = 10;
        final int x[] = new int[threadCount];
        Thread progenitor = new ITLThread(x);
        try {
            progenitor.start();
            progenitor.join();
            for(int i = 0; i < threadCount; i++) {
                assertEquals(i, x[i]);
            }
        } catch(InterruptedException e) {
            unexpectedException();
        }
    
public voidtestRemove()
remove causes next access to return initial value


                 
       
        assertEquals(tl.get(), one);
        tl.set(two);
        assertEquals(tl.get(), two);
        tl.remove();
        assertEquals(tl.get(), one);
    
public voidtestRemoveITL()
remove in InheritableThreadLocal causes next access to return initial value

        assertEquals(itl.get(), zero);
        itl.set(two);
        assertEquals(itl.get(), two);
        itl.remove();
        assertEquals(itl.get(), zero);