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

MockNodeChangeListener

public class MockNodeChangeListener extends Object implements NodeChangeListener

Fields Summary
private Object
addLock
private Object
removeLock
private int
added
private int
removed
private int
testNum
public static final int
TEST_GET_CHILD
public static final int
TEST_GET_PARENT
boolean
addResult
boolean
removeResult
Constructors Summary
public MockNodeChangeListener(int test)


       
        testNum = test;
    
public MockNodeChangeListener()


    
Methods Summary
public voidchildAdded(java.util.prefs.NodeChangeEvent e)


        synchronized (addLock) {
            switch (testNum) {
            case TEST_GET_CHILD:
                Preferences child = e.getChild();
                if (child == null) {
                    addResult = false;
                } else {
                    if (child.name() == "mock1") {
                        addResult = true;
                    }
                }
                break;
            case TEST_GET_PARENT:
                Preferences parent = e.getParent();
                if (parent == null) {
                    addResult = false;
                } else {
                    if (parent.name() == "mock") {
                        addResult = true;
                    }
                }

                break;
            }
            ++added;
            addLock.notifyAll();
        }
    
public voidchildRemoved(java.util.prefs.NodeChangeEvent e)

        synchronized (removeLock) {
            switch (testNum) {
            case TEST_GET_CHILD:
                Preferences child = e.getChild();
                if (child == null) {
                    removeResult = false;
                } else {
                    if (child.name() == "mock1") {
                        removeResult = true;
                    }
                }
                break;
            case TEST_GET_PARENT:
                Preferences parent = e.getParent();
                if (parent == null) {
                    addResult = false;
                } else {
                    if (parent.name() == "mock") {
                        addResult = true;
                    }
                }

                break;
            }
            removed++;
            removeLock.notifyAll();
        }
    
public booleangetAddResult()

        synchronized (addLock) {
            return addResult;
        }
    
public intgetAdded()

        synchronized (addLock) {
            return added;
        }
    
public booleangetRemoveResult()

        synchronized (removeLock) {
            return removeResult;
        }
    
public intgetRemoved()

        synchronized (removeLock) {
            return removed;
        }
    
public voidreset()

        added = 0;
        removed = 0;
    
public voidwaitForEvent()

        try {
            synchronized (addLock) {
                addLock.wait(500);
            }
        } catch (InterruptedException e) {
        }