|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.windows; import junit.framework.*; import org.netbeans.junit.*; import org.openide.cookies.*; import org.openide.nodes.*; import org.openide.util.*; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; /** * Checks behaviour of a bridge that listens on a provided lookup * and initializes activated nodes according to the nodes in the * lookup. * * @author Jaroslav Tulach, Jesse Glick */ public final class TopComponentLookupToNodesBridge extends NbTestCase { /** own action map */ protected javax.swing.ActionMap map; /** top component we work on */ protected TopComponent top; /** instance in the lookup */ protected InstanceContent ic; /** its lookup */ protected Lookup lookup; public TopComponentLookupToNodesBridge (String testName) { super(testName); } public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { return new NbTestSuite(TopComponentLookupToNodesBridge.class); } /** Setup component with lookup. */ protected void setUp () { System.setProperty ("org.openide.util.Lookup", "-"); map = new javax.swing.ActionMap (); ic = new InstanceContent (); ic.add (map); lookup = new AbstractLookup (ic); top = new TopComponent (lookup); } public void testTheLookupIsReturned () { assertEquals ("Lookup provided to TC in constructor is returned", lookup, top.getLookup ()); } public void testActionMapIsTakenFromTheLookupIfProvided () { assertEquals ("Action map is set", map, top.getActionMap ()); ic.set (java.util.Collections.singleton (new javax.swing.ActionMap ()), null); assertEquals ("And is not changed (right now) if modified in list", map, top.getActionMap ()); } public void testEmptyLookupGeneratesZeroLengthArray () { assertNotNull ("Array is there", top.getActivatedNodes ()); assertEquals ("No nodes", 0, top.getActivatedNodes ().length); } public void testNodeIsThereIfInLookup () { class Listener implements java.beans.PropertyChangeListener { public int cnt; public String name; public void propertyChange (java.beans.PropertyChangeEvent ev) { cnt++; name = ev.getPropertyName (); } } Listener l = new Listener (); top.addPropertyChangeListener (l); ic.add (Node.EMPTY); assertNotNull ("Array exists", top.getActivatedNodes ()); assertEquals ("One node", 1, top.getActivatedNodes ().length); assertEquals ("The node", Node.EMPTY, top.getActivatedNodes ()[0]); assertEquals ("One PCE", 1, l.cnt); assertEquals ("Name of property", "activatedNodes", l.name); ic.set (java.util.Collections.nCopies (2, Node.EMPTY), null); assertEquals ("Two nodes", 2, top.getActivatedNodes ().length); assertEquals ("The same", Node.EMPTY, top.getActivatedNodes ()[0]); assertEquals ("The same", Node.EMPTY, top.getActivatedNodes ()[1]); assertEquals ("second PCE change", 2, l.cnt); assertEquals ("Name of property", "activatedNodes", l.name); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.