FileDocCategorySizeDatePackage
WeakReferenceTest.javaAPI DocAndroid 1.5 API3441Wed May 06 22:41:04 BST 2009tests.api.java.lang.ref

WeakReferenceTest

public class WeakReferenceTest extends TestCase

Fields Summary
static Boolean
bool
Constructors Summary
Methods Summary
protected voiddoneSuite()

        bool = null;
    
protected voidsetUp()

    
protected voidtearDown()

    
public voidtest_ConstructorLjava_lang_Object()

tests
java.lang.ref.WeakReference#WeakReference(java.lang.Object)

        bool = new Boolean(true);
        try {
            WeakReference wr = new WeakReference(bool);
            // Allow the finalizer to run to potentially enqueue
            Thread.sleep(1000);
            assertTrue("Initialization failed.", ((Boolean) wr.get())
                    .booleanValue());
        } catch (Exception e) {
            fail("Exception during test : " + e.getMessage());
        }
        // need a reference to bool so the jit does not optimize it away
        assertTrue("should always pass", bool.booleanValue());
    
public voidtest_ConstructorLjava_lang_ObjectLjava_lang_ref_ReferenceQueue()

tests
java.lang.ref.WeakReference#WeakReference(java.lang.Object, java.lang.ref.ReferenceQueue)

        ReferenceQueue rq = new ReferenceQueue();
        bool = new Boolean(true);
        try {
            // Allow the finalizer to run to potentially enqueue
            WeakReference wr = new WeakReference(bool, rq);
            assertTrue("Initialization failed.", ((Boolean) wr.get())
                    .booleanValue());
        } catch (Exception e) {
            fail("Exception during test : " + e.getMessage());
        }
        // need a reference to bool so the jit does not optimize it away
        assertTrue("should always pass", bool.booleanValue());

        boolean exception = false;
        try {
            new WeakReference(bool, null);
        } catch (NullPointerException e) {
            exception = true;
        }
        assertTrue("Should not throw NullPointerException", !exception);