FileDocCategorySizeDatePackage
MockPreferenceChangeListener.javaAPI DocAndroid 1.5 API3134Wed May 06 22:41:04 BST 2009org.apache.harmony.prefs.tests.java.util.prefs

MockPreferenceChangeListener

public class MockPreferenceChangeListener extends Object implements PreferenceChangeListener

Fields Summary
private Object
lock
private int
changed
private boolean
addDispatched
public static final int
TEST_GET_KEY
public static final int
TEST_GET_NEW_VALUE
public static final int
TEST_GET_NODE
boolean
result
int
testNum
Constructors Summary
public MockPreferenceChangeListener()

    
    
      
        
    
public MockPreferenceChangeListener(int test)

        testNum = test;
    
Methods Summary
public intgetChanged()

        synchronized (lock) {

            if (!addDispatched) {
                try {
                    // TODO: don't know why must add limitation
                    lock.wait(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            addDispatched = false;
            return changed;
        }
    
public booleangetResult()

        synchronized (lock) {

            if (!addDispatched) {
                try {
                    // TODO: don't know why must add limitation
                    lock.wait(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            addDispatched = false;
            return result;
        }
    
public voidpreferenceChange(java.util.prefs.PreferenceChangeEvent pce)

        synchronized (lock) {
            switch(testNum) {
                case TEST_GET_KEY:
                    if(pce != null) {
                        if(pce.getKey().equals("key_int")) {
                            result = true;
                        }
                    } 
                    break;
                case TEST_GET_NEW_VALUE:
                    if(pce != null) {
                        if(pce.getNewValue().equals(new Integer(Integer.MAX_VALUE).toString())) {
                            result = true;
                        }
                    }                     
                    break;
                case TEST_GET_NODE:
                    if(pce != null) {
                        if("mock".equals(pce.getNode().name())) {
                            result = true;
                        }
                    }                     
    
                    break;
            }
            changed++;
            addDispatched = true;
            lock.notifyAll();
        }
    
public voidreset()

        changed = 0;
        result = false;
    
public voidwaitForEvent()

        waitForEvent(1);
    
public voidwaitForEvent(int count)

        for (int i = 0; i < count; i++) {
            try {
                synchronized (lock) {
                    lock.wait(500);
                }
            } catch (InterruptedException e) {
            }
        }