|
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.netbeans.api.registry; import junit.textui.TestRunner; import org.netbeans.junit.NbTestCase; import org.netbeans.junit.NbTestSuite; import org.openide.modules.ModuleInfo; import org.openide.util.Lookup; import javax.swing.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class OrderingTest extends NbTestCase { public OrderingTest(String name) { super (name); } public static void main(String[] args) { TestRunner.run(new NbTestSuite(OrderingTest.class)); } protected void setUp () throws Exception { Lookup.getDefault().lookup(ModuleInfo.class); } public void testOrdering() throws Exception { Context subctx = getContext().createSubcontext ("sorta"); Context sub1 = subctx.createSubcontext("subo1"); Context sub2 = subctx.createSubcontext("subo2"); Context sub3 = subctx.createSubcontext("subo3"); Context sub4 = subctx.createSubcontext("subo4"); Context sub5 = subctx.createSubcontext("subo5"); Object o1 = new JLabel("bino1"); subctx.putObject("bin1", o1); Object o2 = new JLabel("bino2"); subctx.putObject("bin2", o2); Object o3 = new JLabel("bino3"); subctx.putObject("bin3", o3); Object o4 = new JLabel("bino4"); subctx.putObject("bin4", o4); Object o5 = new JLabel("bino5"); subctx.putObject("bin5", o5); Collection c = subctx.getOrderedObjects(); // nothing known about order, but all objects must be there ArrayList ar = new ArrayList(c); assertTrue("Element not found in the ordered list.", ar.remove(sub1)); assertTrue("Element not found in the ordered list.", ar.remove(sub2)); assertTrue("Element not found in the ordered list.", ar.remove(sub3)); assertTrue("Element not found in the ordered list.", ar.remove(sub4)); assertTrue("Element not found in the ordered list.", ar.remove(sub5)); assertTrue("Element not found in the ordered list.", ar.remove(o1)); assertTrue("Element not found in the ordered list.", ar.remove(o2)); assertTrue("Element not found in the ordered list.", ar.remove(o3)); assertTrue("Element not found in the ordered list.", ar.remove(o4)); assertTrue("Element not found in the ordered list.", ar.remove(o5)); assertTrue("The collection must be empty now: "+ar, ar.size() == 0); ArrayList newOrder = new ArrayList(); ArrayList newOrderValue = new ArrayList(); newOrder.add("bin5"); newOrderValue.add(o5); newOrder.add("subo5/"); newOrderValue.add(sub5); newOrder.add("subo2/"); newOrderValue.add(sub2); newOrder.add("bin2"); newOrderValue.add(o2); newOrder.add("subo1/"); newOrderValue.add(sub1); newOrder.add("subo3/"); newOrderValue.add(sub3); newOrder.add("bin3"); newOrderValue.add(o3); newOrder.add("bin1"); newOrderValue.add(o1); newOrder.add("bin4"); newOrderValue.add(o4); newOrder.add("subo4/"); newOrderValue.add(sub4); subctx.orderContext(newOrder); List l = subctx.getOrderedObjects(); assertTrue("The number of returned items must be the same.", l.size() == newOrderValue.size()); for (int i=0; i |
... 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.