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

MockAbstractPreferences

public class MockAbstractPreferences extends AbstractPreferences

Fields Summary
static final int
NORMAL
static final int
backingException
static final int
runtimeException
static final int
returnNull
int
result
Properties
attr
Map
childs
private int
flushedTimes
private int
syncTimes
Constructors Summary
protected MockAbstractPreferences(AbstractPreferences parent, String name)


         
        this(parent, name, false);

    
protected MockAbstractPreferences(AbstractPreferences parent, String name, boolean newNode)

        super(parent, name);
        super.newNode = newNode;
        if (parent instanceof MockAbstractPreferences) {
            ((MockAbstractPreferences) parent).addChild(this);
        }
    
Methods Summary
private voidaddChild(org.apache.harmony.prefs.tests.java.util.prefs.MockAbstractPreferences c)

        childs.put(c.name(), c);
    
public java.util.prefs.AbstractPreferences[]cachedChildrenImpl()

        return super.cachedChildren();
    
private voidcheckException()

        switch (result) {
        case NORMAL:
            return;
        case backingException:
            throw new BackingStoreException("test");
        case runtimeException:
            throw new MockRuntimeException("test");
        }
    
public java.util.prefs.AbstractPreferenceschildSpi(java.lang.String name)

        try {
            checkException();
        } catch (BackingStoreException e) {
        }
        if (result == returnNull)
            return null;
        AbstractPreferences r = childs.get(name);
        if (r == null) {
            r = new MockAbstractPreferences(this, name, true);

        }
        return r;
    
public java.lang.String[]childrenNamesSpi()

        checkException();
        if (result == returnNull)
            return null;
        String[] r = new String[childs.size()];
        childs.keySet().toArray(r);
        return r;
    
public voidflushSpi()

        checkException();
        flushedTimes++;
    
public java.util.prefs.AbstractPreferencesgetChildImpl(java.lang.String name)

        return super.getChild(name);
    
public intgetFlushedTimes()

        return flushedTimes;
    
public java.lang.ObjectgetLock()

        return lock;
    
public booleangetNewNode()

        return newNode;
    
public java.lang.StringgetSpi(java.lang.String key)

        try {
            checkException();
        } catch (BackingStoreException e) {
        }
        if (null == key) {
            return null;
        }
        return result == returnNull ? null : attr.getProperty(key);
    
public intgetSyncTimes()

        return syncTimes;
    
public booleanisRemovedImpl()

        return super.isRemoved();
    
public java.lang.String[]keysSpi()

        checkException();
        Set<Object> keys = attr.keySet();
        String[] results = new String[keys.size()];
        keys.toArray(results);
        return result == returnNull ? null : results;
    
public java.lang.Objectlock()

        return lock;
    
public voidprotectedAbstractMethod()

        try {
            childrenNamesSpi();
        } catch (BackingStoreException e) {
        }
        childSpi("mock");
        try {
            flushSpi();
        } catch (BackingStoreException e1) {
        }
        getSpi(null);
        isRemoved();
        try {
            keysSpi();
        } catch (BackingStoreException e2) {
        }
        putSpi(null, null);
        try {
            removeNodeSpi();
        } catch (BackingStoreException e3) {
        }
        removeSpi(null);
        try {
            syncSpi();
        } catch (BackingStoreException e4) {
        }
    
public java.util.prefs.AbstractPreferencespublicChildSpi(java.lang.String name)

        return childSpi(name);
    
public voidputSpi(java.lang.String name, java.lang.String value)

        try {
            checkException();
        } catch (BackingStoreException e) {
        }
        if (name == null || value == null) {
            return;
        }
        attr.put(name, value);
    
protected voidremoveNodeSpi()

        checkException();
        ((MockAbstractPreferences) parent()).childs.remove(name());
    
public voidremoveSpi(java.lang.String key)

        try {
            checkException();
        } catch (BackingStoreException e) {
        }
        if (null == key) {
            return;
        }
        attr.remove(key);
    
public voidresetFlushedTimes()

        flushedTimes = 0;
    
public voidresetSyncTimes()

        syncTimes = 0;
    
public voidsetResult(int r)

        result = r;
    
public voidsyncSpi()

        checkException();
        syncTimes++;