1 19 20 package org.openide.util.lookup; 21 22 import org.openide.util.*; 23 24 import java.lang.ref.WeakReference ; 25 import java.util.*; 26 import junit.framework.*; 27 import org.netbeans.junit.*; 28 import java.io.Serializable ; 29 30 public class InitializationBug44134Test extends NbTestCase { 31 public InitializationBug44134Test (java.lang.String testName) { 32 super(testName); 33 } 34 35 public static void main(java.lang.String [] args) { 36 junit.textui.TestRunner.run(new NbTestSuite(InitializationBug44134Test.class)); 37 } 38 39 public void testThereShouldBe18Integers () throws Exception { 40 FooManifestLookup foo = new FooManifestLookup (); 41 42 Collection items = foo.lookup (new Lookup.Template (Integer .class)).allItems (); 43 44 assertEquals ("18 of them", 18, items.size ()); 45 46 Iterator it = items.iterator (); 47 while (it.hasNext()) { 48 Lookup.Item t = (Lookup.Item)it.next (); 49 assertEquals ("Is Integer", Integer .class, t.getInstance ().getClass ()); 50 } 51 } 52 53 54 public class FooManifestLookup extends AbstractLookup { 55 public FooManifestLookup() { 56 super(); 57 } 58 59 protected void initialize() { 60 for (int i=0; i<18; i++) { 61 try { 62 String id= "__" + i; 63 64 addPair(new FooLookupItem(new Integer (i),id)); 65 } 66 catch (Exception e) { 67 } 68 } 69 } 70 71 public class FooLookupItem extends AbstractLookup.Pair { 72 public FooLookupItem(Integer data, String id) { 73 super(); 74 this.data=data; 75 this.id=id; 76 } 77 78 protected boolean creatorOf(Object obj) { 79 return obj == data; 80 } 81 82 public String getDisplayName() { 83 return data.toString(); 84 } 85 86 public Class getType () { 87 return Integer .class; 88 } 89 90 protected boolean instanceOf (Class c) { 91 return c.isInstance(data); 92 } 93 94 public Object getInstance() { 95 return data; 96 } 97 98 public String getId() { 99 return id; 100 } 101 102 private Integer data; 103 private String id; 104 } 105 } 106 107 } 108 | Popular Tags |