Java 类java.util.prefs.AbstractPreferences 实例源码

项目:incubator-netbeans    文件:CodeStylePreferences.java   
@Override
        protected AbstractPreferences childSpi(String name) {
            if (prefs == null) {
                prefs = new HashMap<String, AbstractPreferences>(3);
            }
            AbstractPreferences p = prefs.get(name);
            if (p == null) {
//                root.cacheMisses++;
                Preferences r = delegate.node(name);
                p = new CachingPreferences(this, name, r);
//                ((CachingPreferences)p).root = this.root;
                prefs.put(name, p);
//            } else {
//                root.cacheHits++;
            }
            return p;
        }
项目:incubator-netbeans    文件:XMLHintPreferences.java   
@Override
protected AbstractPreferences childSpi(String name) {
    String escapedName = escape(name);
    NodeList nl = node.getElementsByTagName("node");

    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);

        if (n instanceof Element && escapedName.equals(((Element) n).getAttribute("name"))) {
            return new XMLHintPreferences(driver, this, name, (Element) n, node, true);
        }
    }

    Element nue = node.getOwnerDocument().createElement("node");

    nue.setAttribute("name", escapedName);

    return new XMLHintPreferences(driver, this, name, nue, node, false);
}
项目:Robot-Overlord-App    文件:MarginallyCleverPreferences.java   
/**
  * http://stackoverflow.com/a/24249709
  */
 @NotNull
 @Override
 protected AbstractPreferences childSpi(@NotNull String name) {
AbstractPreferences childPreferenceNode = (AbstractPreferences) children.get(name);
   boolean isChildRemoved = false;
   if (childPreferenceNode != null) {
     try {
       isChildRemoved = getIsRemoved(childPreferenceNode);
     } catch (ReflectiveOperationException e) {
       Log.error( e.getMessage() );
     }
   }
   if (childPreferenceNode == null || isChildRemoved) {
     final AbstractPreferences castedPreferences = new MarginallyCleverPreferences(this, name);
     childPreferenceNode = castedPreferences;
     children.put(name, childPreferenceNode);
   }
   return childPreferenceNode;
 }
项目:Robot-Overlord-App    文件:MarginallyCleverPreferences.java   
/**
  * http://stackoverflow.com/a/24249709
  *
  * @param name
  * @return
  */
 @NotNull
 @Override
 protected AbstractPreferences childSpi(@NotNull String name) {
AbstractPreferences childPreferenceNode = (AbstractPreferences) children.get(name);
   boolean isChildRemoved = false;
   if (childPreferenceNode != null) {
     try {
       isChildRemoved = getIsRemoved(childPreferenceNode);
     } catch (ReflectiveOperationException e) {
       Log.error( e.getMessage() );
     }
   }
   if (childPreferenceNode == null || isChildRemoved) {
     final AbstractPreferences castedPreferences = new MarginallyCleverPreferences(this, name);
     childPreferenceNode = castedPreferences;
     children.put(name, childPreferenceNode);
   }
   return childPreferenceNode;
 }
项目:In-the-Box-Fork    文件:PreferencesTest.java   
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "SecurityException checking missed.",
    method = "systemRoot",
    args = {}
)
public void testSystemRoot() {
    Preferences p = Preferences.systemRoot();
    assertTrue(p instanceof AbstractPreferences);
    assertEquals("/", p.absolutePath());
    assertSame(null, p.parent());
    assertFalse(p.isUserNode());
    assertEquals("", p.name());
    assertEquals("System Preference Node: " + p.absolutePath(), p
            .toString());
    // assertEquals(0, p.childrenNames().length);
    // assertEquals(0, p.keys().length);
}
项目:In-the-Box-Fork    文件:PreferencesTest.java   
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "SecurityException checking missed.",
    method = "userNodeForPackage",
    args = {java.lang.Class.class}
)
public void testUserNodeForPackage() throws BackingStoreException {
    Preferences p = Preferences.userNodeForPackage(Object.class);
    assertEquals("/java/lang", p.absolutePath());
    assertTrue(p instanceof AbstractPreferences);
    Preferences root = Preferences.userRoot();
    Preferences parent = root.node("java");
    assertSame(parent, p.parent());
    assertTrue(p.isUserNode());
    assertEquals("lang", p.name());
    assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
    assertEquals(0, p.childrenNames().length);
    assertEquals(0, p.keys().length);

    try {
        p = Preferences.userNodeForPackage(null);
        fail();
    } catch (NullPointerException e) {
    }
}
项目:In-the-Box-Fork    文件:PreferencesTest.java   
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "SecurityException checking missed.",
    method = "userRoot",
    args = {}
)
public void testUserRoot() {
    Preferences p = Preferences.userRoot();
    assertTrue(p instanceof AbstractPreferences);
    assertEquals("/", p.absolutePath());
    assertSame(null, p.parent());
    assertTrue(p.isUserNode());
    assertEquals("", p.name());
    assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
    // assertEquals(0, p.childrenNames().length);
    // assertEquals(p.keys().length, 0);
}
项目:In-the-Box-Fork    文件:PreferenceChangeEventTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Test is correct, functionality checked in separate Mock class.",
    method = "getKey",
    args = {}
)
public void testGetKey() {
    AbstractPreferences parent = (AbstractPreferences) Preferences
            .userNodeForPackage(Preferences.class);

    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");

    MockPreferenceChangeListener pl = new MockPreferenceChangeListener(
            MockPreferenceChangeListener.TEST_GET_KEY);
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
项目:In-the-Box-Fork    文件:PreferenceChangeEventTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Test is correct, functionality checked in separate Mock class.",
    method = "getNode",
    args = {}
)
public void testGetNode() {
    AbstractPreferences parent = (AbstractPreferences) Preferences
            .userNodeForPackage(Preferences.class);

    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");

    MockPreferenceChangeListener pl = new MockPreferenceChangeListener(
            MockPreferenceChangeListener.TEST_GET_NODE);
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();

    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
项目:In-the-Box-Fork    文件:AbstractPreferencesTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "parent",
    args = {}
)
public void testParent() throws BackingStoreException {
    AbstractPreferences node = (AbstractPreferences) pref.node("First node/sub node");

    assertTrue(node.parent().name().compareTo("First node") == 0);

    pref.removeNode();

    try {
        node.parent();
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
        //expected
    }
}
项目:cn1    文件:PreferencesTest.java   
public void testUserNodeForPackage() throws BackingStoreException {
    Preferences p = Preferences.userNodeForPackage(Object.class);
    assertEquals("/java/lang", p.absolutePath());
    assertTrue(p instanceof AbstractPreferences);
    Preferences root = Preferences.userRoot();
    Preferences parent = root.node("java");
    assertSame(parent, p.parent());
    assertTrue(p.isUserNode());
    assertEquals("lang", p.name());
    assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
    assertEquals(0, p.childrenNames().length);
    assertEquals(0, p.keys().length);

    try {
        Preferences.userNodeForPackage(null);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
项目:freeVM    文件:PreferencesTest.java   
public void testUserNodeForPackage() throws BackingStoreException {
    Preferences p = Preferences.userNodeForPackage(Object.class);
    assertEquals("/java/lang", p.absolutePath());
    assertTrue(p instanceof AbstractPreferences);
    Preferences root = Preferences.userRoot();
    Preferences parent = root.node("java");
    assertSame(parent, p.parent());
    assertTrue(p.isUserNode());
    assertEquals("lang", p.name());
    assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
    assertEquals(0, p.childrenNames().length);
    assertEquals(0, p.keys().length);

    try {
        p = Preferences.userNodeForPackage(null);
        fail();
    } catch (NullPointerException e) {
    }
}
项目:freeVM    文件:PreferencesTest.java   
public void testUserNodeForPackage() throws BackingStoreException {
    Preferences p = Preferences.userNodeForPackage(Object.class);
    assertEquals("/java/lang", p.absolutePath());
    assertTrue(p instanceof AbstractPreferences);
    Preferences root = Preferences.userRoot();
    Preferences parent = root.node("java");
    assertSame(parent, p.parent());
    assertTrue(p.isUserNode());
    assertEquals("lang", p.name());
    assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
    assertEquals(0, p.childrenNames().length);
    assertEquals(0, p.keys().length);

    try {
        Preferences.userNodeForPackage(null);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
项目:incubator-netbeans    文件:InheritedPreferences.java   
@Override
protected AbstractPreferences childSpi(String name) {
    Preferences storedNode = stored != null ? stored.node(name) : null;
    if (storedNode != null) {
        return new InheritedPreferences(null, storedNode);
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:AdjustConfigurationPanel.java   
protected AbstractPreferences childSpi(String name) {
    ModifiedPreferences result = subNodes.get(name);

    if (result == null) {
        subNodes.put(name, result = new ModifiedPreferences(this, name));
    }

    return result;
}
项目:incubator-netbeans    文件:AuxiliaryConfigBasedPreferencesProvider.java   
@Override
protected AbstractPreferences childSpi(String name) {
    synchronized (AuxiliaryConfigBasedPreferencesProvider.this) {
        String nuePath = path + "/" + name;
        if (!getChildrenNames().contains(name)) {
            AuxiliaryConfigBasedPreferencesProvider.this.createdNodes.add(nuePath);
        }

        return new AuxiliaryConfigBasedPreferences(this, name, nuePath);
    }
}
项目:incubator-netbeans    文件:AuxiliaryConfigBasedPreferencesProvider.java   
@Override
protected AbstractPreferences getChild(final String nodeName) throws BackingStoreException {
    try {
        return ProjectManager.mutex(false, project).readAccess(new ExceptionAction<AbstractPreferences>() {
            public AbstractPreferences run() throws BackingStoreException {
                return AuxiliaryConfigBasedPreferences.super.getChild(nodeName);
            }
        });
    } catch (MutexException ex) {
        throw (BackingStoreException) ex.getException();
    }
}
项目:incubator-netbeans    文件:InheritedPreferences.java   
@Override
protected AbstractPreferences childSpi(String name) {
    Preferences storedNode = stored != null ? stored.node(name) : null;
    if (storedNode != null) {
        return new InheritedPreferences(null, storedNode);
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:ProjectAwareCodeStylePreferences.java   
public Preferences getPreferences() {
    synchronized (this) {
        Preferences prefs = useProject ? projectPrefs : globalPrefs;
        // to support tests that don't use editor.mimelookup.impl
        return prefs == null ? AbstractPreferences.systemRoot() : prefs;
    }
}
项目:incubator-netbeans    文件:ProxyPreferences.java   
@Override
    protected AbstractPreferences childSpi(String name) {
//        Preferences [] nueDelegates = new Preferences[delegates.length];
//        for(int i = 0; i < delegates.length; i++) {
//            nueDelegates[i] = delegates[i].node(name);
//        }
//        return new ProxyPreferences(name, this, nueDelegates);
        throw new UnsupportedOperationException("Not supported yet."); //NOI18N
    }
项目:incubator-netbeans    文件:ProxyPreferences.java   
private void firePrefChange(String key, String newValue) {
    try {
        Method m = AbstractPreferences.class.getDeclaredMethod("enqueuePreferenceChangeEvent", String.class, String.class); //NOI18N
        m.setAccessible(true);
        m.invoke(this, key, newValue);
    } catch (Exception e) {
        LOG.log(Level.WARNING, null, e);
    }
}
项目:routerapp    文件:AIXMLPreferences.java   
/**
 * Retrieves this node's child with the given name from the backing store. If
 * such a child doesn't exist, one will be created.
 * @param name the name of the desired child
 * @return the desired node, which will have the 'newNode' flag set if it didn't
 * exist before this method
 */
protected AbstractPreferences childSpi(String name) {
    Element node = myXMLNode();

    if (node != null) {
        NodeList children = node.getElementsByTagName("node");

        for (int i=0 ; i<children.getLength() ; i++) {
            Element child = (Element)children.item(i);
            String childName = child.getAttribute("name");

            if (childName.equals(name)) 
                return createPreferencesFromElement(child,childName);
        }

        // the child doesn't exist, so one will be created
        AbstractPreferences prefs = new AIXMLPreferences(this,name);
        Element newNode = AIPreferencesController.getInstance().getXMLDocument().createElement("node");
        Element map = AIPreferencesController.getInstance().getXMLDocument().createElement("map");

        newNode.appendChild(map);
        newNode.setAttribute("name",name);
        node.appendChild(newNode);

        return prefs;
    }
    return null;
}
项目:routerapp    文件:AIXMLPreferences.java   
/**
 * Creates a preferences node from an XML element.
 * @param child the XML element whose node will be created
 * @return the newly created preferences node
 */
private AbstractPreferences createPreferencesFromElement(Element child, String name) {
    AbstractPreferences prefs = new AIXMLPreferences(this,name);

    NodeList map = child.getElementsByTagName("map");
    NodeList entries = ((Element)map.item(0)).getElementsByTagName("entry");

    for (int i=0 ; i<entries.getLength() ; i++) {
        Element entry = (Element)entries.item(i);

        prefs.put(entry.getAttribute("key"),entry.getAttribute("value"));
    }

    return prefs;
}
项目:routerapp    文件:XMLPreferences.java   
/**
 * Retrieves this node's child with the given name from the backing store. If
 * such a child doesn't exist, one will be created.
 * @param name the name of the desired child
 * @return the desired node, which will have the 'newNode' flag set if it didn't
 * exist before this method
 */
protected AbstractPreferences childSpi(String name) {
    Element node = myXMLNode();

    if (node != null) {
        NodeList children = node.getElementsByTagName("node");

        for (int i=0 ; i<children.getLength() ; i++) {
            Element child = (Element)children.item(i);
            String childName = child.getAttribute("name");

            if (childName.equals(name)) 
                return createPreferencesFromElement(child,childName);
        }

        // the child doesn't exist, so one will be created
        AbstractPreferences prefs = new XMLPreferences(this,name);
        Element newNode = PreferencesController.getInstance().getXMLDocument().createElement("node");
        Element map = PreferencesController.getInstance().getXMLDocument().createElement("map");

        newNode.appendChild(map);
        newNode.setAttribute("name",name);
        node.appendChild(newNode);

        return prefs;
    }
    return null;
}
项目:routerapp    文件:XMLPreferences.java   
/**
 * Creates a preferences node from an XML element.
 * @param child the XML element whose node will be created
 * @return the newly created preferences node
 */
private AbstractPreferences createPreferencesFromElement(Element child, String name) {
    AbstractPreferences prefs = new XMLPreferences(this,name);

    NodeList map = child.getElementsByTagName("map");
    NodeList entries = ((Element)map.item(0)).getElementsByTagName("entry");

    for (int i=0 ; i<entries.getLength() ; i++) {
        Element entry = (Element)entries.item(i);

        prefs.put(entry.getAttribute("key"),entry.getAttribute("value"));
    }

    return prefs;
}
项目:spring4-understanding    文件:PropertyResourceConfigurerTests.java   
@Override
protected AbstractPreferences childSpi(String name) {
    AbstractPreferences child = children.get(name);
    if (child == null) {
        child = new MockPreferences(this, name);
        children.put(name, child);
    }
    return child;
}
项目:vortex    文件:Config.java   
private static Preferences getDBHostSpecificPreferences() {
    ConnectionManager.DatabaseHost host = ConnectionManager.getDatabaseHost();
    if (host != null) {
        String s = host.toString().replaceAll("\\\\+", Matcher.quoteReplacement("\\")).replaceAll("/+", "/");
        if (s.length() > AbstractPreferences.MAX_NAME_LENGTH) {
            s = String.valueOf(s.hashCode());
        }
        return prefDBHosts.node(s);
    } else {
        throw new IllegalStateException("There's no current database host connection");
    }
}
项目:vortex    文件:Config.java   
private static Preferences getDBHostSpecificPreferences() {
    ConnectionManager.DatabaseHost host = ConnectionManager.getDatabaseHost();
    if (host != null) {
        String s = host.toString().replaceAll("\\\\+", Matcher.quoteReplacement("\\")).replaceAll("/+", "/");
        if (s.length() > AbstractPreferences.MAX_NAME_LENGTH) {
            s = String.valueOf(s.hashCode());
        }
        return prefDBHosts.node(s);
    } else {
        throw new IllegalStateException("There's no current database host connection");
    }
}
项目:javify    文件:GConfBasedPreferences.java   
/**
 * Creates a new preference node given a parent node and a name, which has to
 * be relative to its parent. When <code>isUser</code> is true it will be user
 * node otherwise it will be a system node.
 *
 * @param parent The parent node of this newly created node.
 * @param name A name relative to the parent node.
 * @param isUser Set to <code>true</code> initializes this node to be
 * a user node, <code>false</code> initialize it to be a system node.
 */
public GConfBasedPreferences(AbstractPreferences parent, String name,
                             boolean isUser)
{
  super(parent, name);
  this.isUser = isUser;

  // stores the fully qualified name of this node
  String absolutePath = this.absolutePath();
  if (absolutePath != null && absolutePath.endsWith("/"))
    {
      absolutePath = absolutePath.substring(0, absolutePath.length() - 1);
    }

  // strip invalid characters
  // please, note that all names are unescaped into the native peer
  int index = absolutePath.lastIndexOf('/');
  if (index > -1)
    {
      absolutePath = absolutePath.substring(0, index + 1);
      absolutePath = absolutePath + GConfNativePeer.escapeString(name);
    }

  this.node = this.getRealRoot(isUser) + absolutePath;

  boolean nodeExist = backend.nodeExist(this.node);

  this.newNode = !nodeExist;
}
项目:javify    文件:GConfBasedPreferences.java   
/**
 * Returns a child node with the given name.
 * If the child node does not exists, it will be created.
 *
 * @param name The name of the requested node.
 * @return A new reference to the node, creating the node if it is necessary.
 */
protected AbstractPreferences childSpi(String name)
{
  // we don't check anything here, if the node is a new node this will be
  // detected in the constructor, so we simply return a new reference to
  // the requested node.

  GConfBasedPreferences preferenceNode
    = new GConfBasedPreferences(this, name, this.isUser);

  return preferenceNode;
}
项目:sqlpower-library    文件:MemoryPreferences.java   
/**
 * Constructor, non-public, only for use by my PrefencesFactory; should only be called from
 * the PreferencesFactory and from node() below; node() takes care of finding the full path
 * if the incoming path is relative.
 * @param fullPath
 */
MemoryPreferences(AbstractPreferences parent, String name) {
    super(parent, name);

       // note, logger should never be null because it's statically initialised.  However,
       // it comes out null every time we run the MatchMaker SwingSessionContextTest!  Hmm...
       if (logger != null && logger.isDebugEnabled()) {
           logger.debug(String.format("MemoryPreferences.MemoryPreferences(%s, %s)", parent, name));
       }
}
项目:sqlpower-library    文件:MemoryPreferences.java   
@Override
protected AbstractPreferences childSpi(String name) {
    logger.debug(String.format("MemoryPreferences.node(%s)", name));
    AbstractPreferences n = new MemoryPreferences(this, name);
    children.put(name, n);
    return n;
}
项目:prokaryote    文件:HeadlessPreferencesFactory.java   
@Override
protected AbstractPreferences childSpi(String name) {
    checkAlive();
    if (! children.containsKey(name)) {
        final HeadlessPreferences result = new HeadlessPreferences(this, name); 
        children.put(name, result);
        result.newNode = true;
        return result;
    } else {
        return children.get(name);
    }
}
项目:jvm-stm    文件:GConfBasedPreferences.java   
/**
 * Creates a new preference node given a parent node and a name, which has to
 * be relative to its parent. When <code>isUser</code> is true it will be user
 * node otherwise it will be a system node.
 * 
 * @param parent The parent node of this newly created node.
 * @param name A name relative to the parent node.
 * @param isUser Set to <code>true</code> initializes this node to be
 * a user node, <code>false</code> initialize it to be a system node.
 */
public GConfBasedPreferences(AbstractPreferences parent, String name,
                             boolean isUser)
{
  super(parent, name);
  this.isUser = isUser;

  // stores the fully qualified name of this node
  String absolutePath = this.absolutePath();
  if (absolutePath != null && absolutePath.endsWith("/"))
    {
      absolutePath = absolutePath.substring(0, absolutePath.length() - 1);
    }

  // strip invalid characters
  // please, note that all names are unescaped into the native peer
  int index = absolutePath.lastIndexOf('/');
  if (index > -1)
    {
      absolutePath = absolutePath.substring(0, index + 1);
      absolutePath = absolutePath + GConfNativePeer.escapeString(name);
    }

  this.node = this.getRealRoot(isUser) + absolutePath;

  boolean nodeExist = backend.nodeExist(this.node);

  this.newNode = !nodeExist;
}
项目:jvm-stm    文件:GConfBasedPreferences.java   
/**
 * Returns a child node with the given name.
 * If the child node does not exists, it will be created.
 * 
 * @param name The name of the requested node.
 * @return A new reference to the node, creating the node if it is necessary.
 */
protected AbstractPreferences childSpi(String name)
{
  // we don't check anything here, if the node is a new node this will be
  // detected in the constructor, so we simply return a new reference to
  // the requested node.

  GConfBasedPreferences preferenceNode
    = new GConfBasedPreferences(this, name, this.isUser);

  return preferenceNode;
}
项目:evosuite    文件:PreferencesImpl.java   
@Override
protected AbstractPreferences childSpi(String name) {
    if(children.containsKey(name))
        return children.get(name);
    else {
        PreferencesImpl child = new PreferencesImpl(this, name);
        children.put(name, child);
        return child;
    }
}
项目:cross-preferences    文件:ZkPreferences.java   
@Override
public void close() throws IOException {
    synchronized (lock) {
        for (AbstractPreferences child : cachedChildren()) {
            try {
                ((ZkPreferences) child).close();
            } catch (Exception e) {
                logger.error("Failed to close child node: {}", child);
            }
        }
        logger.info("Closing the Zookeeper listener for {}", this);
        pcc.close();
    }
}
项目:Robot-Overlord-App    文件:MarginallyCleverPreferences.java   
/**
 * FIXME - Pure hack to get around erasure.
 *
 * @return true if removed
 * @throws ReflectiveOperationException
 */
private boolean getIsRemoved(AbstractPreferences abstractPreference) throws ReflectiveOperationException {
  Log.message( abstractPreference.toString() );
  final Method declaredMethod = AbstractPreferences.class.getDeclaredMethod("isRemoved");
  declaredMethod.setAccessible(true);
  Object isRemoved = declaredMethod.invoke(abstractPreference, new Object[]{null});
  return (boolean) isRemoved;
}
项目:Robot-Overlord-App    文件:MarginallyCleverPreferences.java   
/**
 * FIXME - Pure hack to get around erasure.
 *
 * @param abstractPreference
 * @return
 * @throws ReflectiveOperationException
 */
private boolean getIsRemoved(AbstractPreferences abstractPreference) throws ReflectiveOperationException {
  Log.message( abstractPreference.toString() );
  final Method declaredMethod = AbstractPreferences.class.getDeclaredMethod("isRemoved");
  declaredMethod.setAccessible(true);
  Object isRemoved = declaredMethod.invoke(abstractPreference, new Object[]{null});
  return (boolean) isRemoved;
}
项目:In-the-Box-Fork    文件:NodeChangeEventTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Test is correct, functionality checked in separate Mock class.",
    method = "getChild",
    args = {}
)
public void testGetChild() throws BackingStoreException {

    AbstractPreferences parent = (AbstractPreferences) Preferences
            .userNodeForPackage(Preferences.class);

    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");

    MockNodeChangeListener nl = new MockNodeChangeListener(
            MockNodeChangeListener.TEST_GET_CHILD);
    try {
        pref.addNodeChangeListener(nl);
        Preferences child1 = pref.node("mock1");
        nl.waitForEvent();
        assertEquals(1, nl.getAdded());
        assertTrue(nl.getAddResult());
        nl.reset();
        child1.removeNode();
        nl.waitForEvent();
        assertEquals(1, nl.getRemoved());
        assertTrue(nl.getRemoveResult());
        nl.reset();
    } finally {
        pref.removeNodeChangeListener(nl);
    }
}